From e042ebd4a2539aeabf0996e8f1a1dad1be5860c0 Mon Sep 17 00:00:00 2001 From: Jason Tamulonis Date: Mon, 7 Jun 2021 12:39:05 -0700 Subject: [PATCH] Expose interface to setNormalizing (#3859) --- packages/slate/src/interfaces/editor.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/slate/src/interfaces/editor.ts b/packages/slate/src/interfaces/editor.ts index cbc3cd85b..1863e071e 100644 --- a/packages/slate/src/interfaces/editor.ts +++ b/packages/slate/src/interfaces/editor.ts @@ -254,6 +254,7 @@ export interface EditorInterface { ) => RangeRef rangeRefs: (editor: Editor) => Set removeMark: (editor: Editor, key: string) => void + setNormalizing: (editor: Editor, isNormalizing: boolean) => void start: (editor: Editor, at: Location) => Point string: ( editor: Editor, @@ -1549,6 +1550,16 @@ export const Editor: EditorInterface = { editor.removeMark(key) }, + /** + * Manually set if the editor should currently be normalizing. + * + * Note: Using this incorrectly can leave the editor in an invalid state. + * + */ + setNormalizing(editor: Editor, isNormalizing: boolean): void { + NORMALIZING.set(editor, isNormalizing) + }, + /** * Get the start point of a location. */ @@ -1669,11 +1680,11 @@ export const Editor: EditorInterface = { withoutNormalizing(editor: Editor, fn: () => void): void { const value = Editor.isNormalizing(editor) - NORMALIZING.set(editor, false) + Editor.setNormalizing(editor, false) try { fn() } finally { - NORMALIZING.set(editor, value) + Editor.setNormalizing(editor, value) } Editor.normalize(editor) },