1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-24 09:13:24 +01:00

fix DOM selection can not be updated when use composition input on Safari #3196 (#3698)

* fix DOM selection can not be updated when use composition input on Safari #3196

* Update editable.tsx

* Create dry-deers-applaud.md

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
This commit is contained in:
pubuzhixing8 2021-04-01 05:06:31 +08:00 committed by GitHub
parent 6799dfd228
commit bf83f333e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fixed selection updating with IME inputs in browsers that support `beforeinput`.

View File

@ -372,6 +372,15 @@ export const Editable = (props: EditableProps) => {
case 'insertFromYank':
case 'insertReplacementText':
case 'insertText': {
if (type === 'insertFromComposition') {
// COMPAT: in Safari, `compositionend` is dispatched after the
// `beforeinput` for "insertFromComposition". But if we wait for it
// then we will abort because we're still composing and the selection
// won't be updated properly.
// https://www.w3.org/TR/input-events-2/
state.isComposing = false
}
const window = ReactEditor.getWindow(editor)
if (data instanceof window.DataTransfer) {
ReactEditor.insertData(editor, data as DataTransfer)