diff --git a/.changeset/pink-panthers-appear.md b/.changeset/pink-panthers-appear.md new file mode 100644 index 000000000..75bdea3da --- /dev/null +++ b/.changeset/pink-panthers-appear.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Cleanup and fix insertion placeholder mark compare diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 84f2f559e..4c801687e 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -765,9 +765,12 @@ export const Editable = (props: EditableProps) => { if (editor.selection && Range.isCollapsed(editor.selection) && marks) { const { anchor } = editor.selection - const { text, ...rest } = Node.leaf(editor, anchor.path) + const leaf = Node.leaf(editor, anchor.path) + const { text, ...rest } = leaf - if (!Text.equals(rest as Text, marks as Text, { loose: true })) { + // While marks isn't a 'complete' text, we can still use loose Text.equals + // here which only compares marks anyway. + if (!Text.equals(leaf, marks as Text, { loose: true })) { state.hasMarkPlaceholder = true const unset = Object.fromEntries( @@ -792,8 +795,11 @@ export const Editable = (props: EditableProps) => { const { selection } = editor if (selection) { const { anchor } = selection - const { text, ...rest } = Node.leaf(editor, anchor.path) - if (!Text.equals(rest as Text, marks as Text, { loose: true })) { + const text = Node.leaf(editor, anchor.path) + + // While marks isn't a 'complete' text, we can still use loose Text.equals + // here which only compares marks anyway. + if (marks && !Text.equals(text, marks as Text, { loose: true })) { EDITOR_TO_PENDING_INSERTION_MARKS.set(editor, marks) return }