diff --git a/.changeset/giant-adults-matter.md b/.changeset/giant-adults-matter.md new file mode 100644 index 000000000..4d31449ef --- /dev/null +++ b/.changeset/giant-adults-matter.md @@ -0,0 +1,5 @@ +--- +slate: patch +--- + +Fixed insert and remove text operations to no-op without any text. diff --git a/packages/slate/src/transforms/general.ts b/packages/slate/src/transforms/general.ts index 49fd0757a..6ccbb9646 100644 --- a/packages/slate/src/transforms/general.ts +++ b/packages/slate/src/transforms/general.ts @@ -44,6 +44,7 @@ export const GeneralTransforms: GeneralTransforms = { case 'insert_text': { const { path, offset, text } = op + if (text.length === 0) break const node = Node.leaf(editor, path) const before = node.text.slice(0, offset) const after = node.text.slice(offset) @@ -167,6 +168,7 @@ export const GeneralTransforms: GeneralTransforms = { case 'remove_text': { const { path, offset, text } = op + if (text.length === 0) break const node = Node.leaf(editor, path) const before = node.text.slice(0, offset) const after = node.text.slice(offset + text.length) diff --git a/packages/slate/src/transforms/text.ts b/packages/slate/src/transforms/text.ts index 1d982b7ec..c58589a79 100644 --- a/packages/slate/src/transforms/text.ts +++ b/packages/slate/src/transforms/text.ts @@ -182,7 +182,8 @@ export const TextTransforms: TextTransforms = { const { path } = point const { offset } = start const text = node.text.slice(offset) - editor.apply({ type: 'remove_text', path, offset, text }) + if (text.length > 0) + editor.apply({ type: 'remove_text', path, offset, text }) } for (const pathRef of pathRefs) { @@ -196,7 +197,8 @@ export const TextTransforms: TextTransforms = { const { path } = point const offset = isSingleText ? start.offset : 0 const text = node.text.slice(offset, end.offset) - editor.apply({ type: 'remove_text', path, offset, text }) + if (text.length > 0) + editor.apply({ type: 'remove_text', path, offset, text }) } if ( @@ -483,7 +485,8 @@ export const TextTransforms: TextTransforms = { } const { path, offset } = at - editor.apply({ type: 'insert_text', path, offset, text }) + if (text.length > 0) + editor.apply({ type: 'insert_text', path, offset, text }) }) }, }