1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 13:41:19 +02:00

Cleanup and fix insertion placeholder mark compare (#5127)

This commit is contained in:
Eric Meier
2022-09-19 14:07:33 +02:00
committed by GitHub
parent b64af40cd5
commit 341041f0b7
2 changed files with 15 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Cleanup and fix insertion placeholder mark compare

View File

@@ -765,9 +765,12 @@ export const Editable = (props: EditableProps) => {
if (editor.selection && Range.isCollapsed(editor.selection) && marks) { if (editor.selection && Range.isCollapsed(editor.selection) && marks) {
const { anchor } = editor.selection 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 state.hasMarkPlaceholder = true
const unset = Object.fromEntries( const unset = Object.fromEntries(
@@ -792,8 +795,11 @@ export const Editable = (props: EditableProps) => {
const { selection } = editor const { selection } = editor
if (selection) { if (selection) {
const { anchor } = selection const { anchor } = selection
const { text, ...rest } = Node.leaf(editor, anchor.path) const text = Node.leaf(editor, anchor.path)
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 (marks && !Text.equals(text, marks as Text, { loose: true })) {
EDITOR_TO_PENDING_INSERTION_MARKS.set(editor, marks) EDITOR_TO_PENDING_INSERTION_MARKS.set(editor, marks)
return return
} }