diff --git a/.changeset/honest-rice-doubt.md b/.changeset/honest-rice-doubt.md new file mode 100644 index 000000000..46c773d12 --- /dev/null +++ b/.changeset/honest-rice-doubt.md @@ -0,0 +1,5 @@ +--- +'slate-history': minor +--- + +Add `withMerging` diff --git a/packages/slate-history/src/history-editor.ts b/packages/slate-history/src/history-editor.ts index 14f455d34..4f20a8b8e 100644 --- a/packages/slate-history/src/history-editor.ts +++ b/packages/slate-history/src/history-editor.ts @@ -62,6 +62,17 @@ export const HistoryEditor = { editor.undo() }, + /** + * Apply a series of changes inside a synchronous `fn`, These operations will + * be merged into the previous history. + */ + withMerging(editor: HistoryEditor, fn: () => void): void { + const prev = HistoryEditor.isMerging(editor) + MERGING.set(editor, true) + fn() + MERGING.set(editor, prev) + }, + /** * Apply a series of changes inside a synchronous `fn`, without merging any of * the new operations into previous save point in the history.