From c3813e18b7b5ba594e0dc2680902a4e9416ff999 Mon Sep 17 00:00:00 2001 From: Justin Weiss Date: Tue, 24 Oct 2017 22:30:40 -0700 Subject: [PATCH] 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 --- packages/slate-react/src/components/content.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/slate-react/src/components/content.js b/packages/slate-react/src/components/content.js index b4b89b5d2..a844fc764 100644 --- a/packages/slate-react/src/components/content.js +++ b/packages/slate-react/src/components/content.js @@ -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 }) + } }) }