From e6413d46256f6fc60549974242d3ff6ba61e2968 Mon Sep 17 00:00:00 2001 From: Ulion Date: Thu, 6 May 2021 08:30:17 +0800 Subject: [PATCH] Fix addMark/removeMark caused unexpected onChange. (#4227) * Fix addMark/removeMark caused unexpected onChange. * Create three-parrots-remember.md Co-authored-by: Ian Storm Taylor --- .changeset/three-parrots-remember.md | 5 +++++ packages/slate/src/create-editor.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/three-parrots-remember.md diff --git a/.changeset/three-parrots-remember.md b/.changeset/three-parrots-remember.md new file mode 100644 index 000000000..17c0ee497 --- /dev/null +++ b/.changeset/three-parrots-remember.md @@ -0,0 +1,5 @@ +--- +'slate': patch +--- + +Fixed a bug that would allow multiple changes to be scheduled at the same time. diff --git a/packages/slate/src/create-editor.ts b/packages/slate/src/create-editor.ts index f19d93846..a7b8399fe 100644 --- a/packages/slate/src/create-editor.ts +++ b/packages/slate/src/create-editor.ts @@ -106,7 +106,9 @@ export const createEditor = (): Editor => { } editor.marks = marks - editor.onChange() + if (!FLUSHING.get(editor)) { + editor.onChange() + } } } }, @@ -296,7 +298,9 @@ export const createEditor = (): Editor => { const marks = { ...(Editor.marks(editor) || {}) } delete marks[key] editor.marks = marks - editor.onChange() + if (!FLUSHING.get(editor)) { + editor.onChange() + } } } },