@@ -8,6 +8,7 @@ import { History } from './history'
8
8
export const HISTORY = new WeakMap < Editor , History > ( )
9
9
export const SAVING = new WeakMap < Editor , boolean | undefined > ( )
10
10
export const MERGING = new WeakMap < Editor , boolean | undefined > ( )
11
+ export const SPLITTING_ONCE = new WeakMap < Editor , boolean | undefined > ( )
11
12
12
13
/**
13
14
* `HistoryEditor` contains helpers for history-enabled editors.
@@ -38,6 +39,18 @@ export const HistoryEditor = {
38
39
return MERGING . get ( editor )
39
40
} ,
40
41
42
+ /**
43
+ * Get the splitting once flag's current value.
44
+ */
45
+
46
+ isSplittingOnce ( editor : HistoryEditor ) : boolean | undefined {
47
+ return SPLITTING_ONCE . get ( editor )
48
+ } ,
49
+
50
+ setSplittingOnce ( editor : HistoryEditor , value : boolean | undefined ) : void {
51
+ SPLITTING_ONCE . set ( editor , value )
52
+ } ,
53
+
41
54
/**
42
55
* Get the saving flag's current value.
43
56
*/
@@ -73,6 +86,20 @@ export const HistoryEditor = {
73
86
MERGING . set ( editor , prev )
74
87
} ,
75
88
89
+ /**
90
+ * Apply a series of changes inside a synchronous `fn`, ensuring that the first
91
+ * operation starts a new batch in the history. Subsequent operations will be
92
+ * merged as usual.
93
+ */
94
+ withNewBatch ( editor : HistoryEditor , fn : ( ) => void ) : void {
95
+ const prev = HistoryEditor . isMerging ( editor )
96
+ MERGING . set ( editor , true )
97
+ SPLITTING_ONCE . set ( editor , true )
98
+ fn ( )
99
+ MERGING . set ( editor , prev )
100
+ SPLITTING_ONCE . delete ( editor )
101
+ } ,
102
+
76
103
/**
77
104
* Apply a series of changes inside a synchronous `fn`, without merging any of
78
105
* the new operations into previous save point in the history.
0 commit comments