Skip to content

Commit 8d42d20

Browse files
committed
fix(editor2): overwrite current checkpoint with soft checkpoint only when it's non-squashable
1 parent 50e129c commit 8d42d20

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/components/editor2/history.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,19 @@ export function useHistoryEdit<T extends {}>(
214214
const current = history.stack[history.index]
215215
const snapshottedCurrent = snapshot.stack[snapshot.index]
216216

217-
// make it a soft checkpoint if the state is unchanged
217+
const shouldSquash =
218+
checkpoint.action === current.action &&
219+
checkpoint.squashBy !== undefined &&
220+
checkpoint.squashBy === current.squashBy &&
221+
// only squash if currently on top of the history stack
222+
history.index === history.stack.length - 1
223+
224+
// make it a soft checkpoint if the checkpoint is non-squashable but the state is unchanged,
225+
// because we don't want the history to advance when the state is unchanged, but still want to
226+
// prevent the next checkpoint from being squashed since a non-squashable checkpoint is being used
227+
// and it's supposed to block the squashing even if it's not actually inserted into the history
218228
if (
229+
!shouldSquash &&
219230
current.state === snapshottedCurrent.state &&
220231
JSON.stringify(current.state) ===
221232
JSON.stringify(snapshottedCurrent.state)
@@ -241,13 +252,6 @@ export function useHistoryEdit<T extends {}>(
241252
}
242253
}
243254

244-
const shouldSquash =
245-
checkpoint.action === current.action &&
246-
checkpoint.squashBy !== undefined &&
247-
checkpoint.squashBy === current.squashBy &&
248-
// only squash if currently on top of the history stack
249-
history.index === history.stack.length - 1
250-
251255
if (shouldSquash || checkpoint === softCheckpoint) {
252256
const newStack = [
253257
...history.stack.slice(0, history.index),

0 commit comments

Comments
 (0)