Skip to content

Commit

Permalink
Add withMerging (#5696)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfeng33 authored Aug 20, 2024
1 parent c3a4e1e commit e5fed79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-rice-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-history': minor
---

Add `withMerging`
11 changes: 11 additions & 0 deletions packages/slate-history/src/history-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e5fed79

Please sign in to comment.