1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 05:01:17 +02:00

Save marks when creating native ranges in onNativeBeforeInput (#1272)

* Save marks when creating native ranges in onNativeBeforeInput

When we used native ranges in onNativeBeforeInput, we weren't carrying
over the marks from Slate's selection. This made it impossible to know
that the next character typed should have a set of marks.

Fixes #1270.

* Ensure marks are cleared after successfully entering text

* Stop setting marks in findRange

Adding the selection's marks inside findRange was too broad of a
change, and would keep marks after doing things like moving a
selection around. We should use selection.marks directly in
insertTextAtRange instead.

* Update find-range.js
This commit is contained in:
Justin Weiss
2017-10-24 22:30:40 -07:00
committed by Ian Storm Taylor
parent 6c347e9d4b
commit c3813e18b7

View File

@@ -304,10 +304,17 @@ class Content extends React.Component {
event.preventDefault()
const { editor, state } = this.props
const { selection } = state
const range = findRange(targetRange, state)
editor.change((change) => {
change.insertTextAtRange(range, text)
change.insertTextAtRange(range, text, selection.marks)
// If the text was successfully inserted, and the selection had marks on it,
// unset the selection's marks.
if (selection.marks && state.document != change.state.document) {
change.select({ marks: null })
}
})
}