mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-14 11:14:04 +02:00
Fix erroneous text after native insert (#4529)
This commit is contained in:
5
.changeset/light-gorillas-train.md
Normal file
5
.changeset/light-gorillas-train.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix erroneous text after native insert
|
@@ -310,10 +310,6 @@ export const Editable = (props: EditableProps) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!native) {
|
|
||||||
event.preventDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
// COMPAT: For the deleting forward/backward input types we don't want
|
// COMPAT: For the deleting forward/backward input types we don't want
|
||||||
// to change the selection because it is the range that will be deleted,
|
// to change the selection because it is the range that will be deleted,
|
||||||
// and those commands determine that for themselves.
|
// and those commands determine that for themselves.
|
||||||
@@ -427,7 +423,9 @@ export const Editable = (props: EditableProps) => {
|
|||||||
// Only insertText operations use the native functionality, for now.
|
// Only insertText operations use the native functionality, for now.
|
||||||
// Potentially expand to single character deletes, as well.
|
// Potentially expand to single character deletes, as well.
|
||||||
if (native) {
|
if (native) {
|
||||||
asNative(editor, () => Editor.insertText(editor, data))
|
asNative(editor, () => Editor.insertText(editor, data), {
|
||||||
|
onFlushed: () => (native = false),
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
Editor.insertText(editor, data)
|
Editor.insertText(editor, data)
|
||||||
}
|
}
|
||||||
@@ -436,6 +434,10 @@ export const Editable = (props: EditableProps) => {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!native) {
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[readOnly, propsOnDOMBeforeInput]
|
[readOnly, propsOnDOMBeforeInput]
|
||||||
|
@@ -10,10 +10,25 @@ export const NATIVE_OPERATIONS: WeakMap<Editor, Operation[]> = new WeakMap()
|
|||||||
* @param {Editor} editor - Editor on which the operations are being applied
|
* @param {Editor} editor - Editor on which the operations are being applied
|
||||||
* @param {callback} fn - Function containing .exec calls which will be queued as native
|
* @param {callback} fn - Function containing .exec calls which will be queued as native
|
||||||
*/
|
*/
|
||||||
export const asNative = (editor: Editor, fn: () => void) => {
|
export const asNative = (
|
||||||
|
editor: Editor,
|
||||||
|
fn: () => void,
|
||||||
|
{ onFlushed }: { onFlushed?: () => void } = {}
|
||||||
|
) => {
|
||||||
|
const isNative = AS_NATIVE.get(editor)
|
||||||
|
|
||||||
AS_NATIVE.set(editor, true)
|
AS_NATIVE.set(editor, true)
|
||||||
|
try {
|
||||||
fn()
|
fn()
|
||||||
AS_NATIVE.set(editor, false)
|
} finally {
|
||||||
|
if (isNative !== undefined) {
|
||||||
|
AS_NATIVE.set(editor, isNative)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NATIVE_OPERATIONS.get(editor)) {
|
||||||
|
onFlushed?.()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +40,7 @@ export const flushNativeEvents = (editor: Editor) => {
|
|||||||
|
|
||||||
// Clear list _before_ applying, as we might flush
|
// Clear list _before_ applying, as we might flush
|
||||||
// events in each op, as well.
|
// events in each op, as well.
|
||||||
NATIVE_OPERATIONS.set(editor, [])
|
NATIVE_OPERATIONS.delete(editor)
|
||||||
|
|
||||||
if (nativeOps) {
|
if (nativeOps) {
|
||||||
Editor.withoutNormalizing(editor, () => {
|
Editor.withoutNormalizing(editor, () => {
|
||||||
|
Reference in New Issue
Block a user