Serious bug: selection is already deleted before insertText is called #5153
Description
Description
In insertText
, the application can decide what to do in response to a user's request to insert some text. For example, insertText
may decide that if the editor.selection
is expanded, it will delete that text and replace it with the new text. However, insertText
is also able to make other decisions and take other actions. In our application, we do the following check: if deleting the current selection would make the document invalid, then instead of invalidating the document by deleting the selection, we take no action. (We could do more sophisticated things, but the point is that insertText
needs to decide whether to delete the current selection.)
As of slate-react 0.75.0, this is broken. It seems that the current selection is already deleted before insertText
is called! The application therefore has no opportunity to decide what to do with the current selection, because the decision has apparently already been made.
Steps
To reproduce the behavior:
- Go to the sandbox above
- Select some text
- Type 'h'
Expected behavior: the text 'X' is inserted instead, due to the check in insertText
.
Actual behavior: the text 'h' is inserted, because apparently the selected text was already deleted before insertText
was called.
Environment
- Slate Version: Chrome with slate-react 0.75.0+; Firefox with slate-react 0.74.1+
- Operating System: Windows
- Browser: Chrome, Firefox
Context
I assume this change is an accidental bug, rather than deliberate: it breaks backwards compatibility with no record in the changelog, and violates Slate's goal of "completely customizing the editing experience without having to fight against the library's assumptions".
I can't think of any workaround for this bug. Therefore we are prevented from upgrading beyond slate-react 0.74.2.