From 0fde029205cc33d0e5a3723123e9590084c70117 Mon Sep 17 00:00:00 2001 From: Rogier Wiertz <72399947+rawstream@users.noreply.github.com> Date: Sat, 28 Sep 2024 18:53:11 +0200 Subject: [PATCH] fix: don't undo initial state (fix #3266) --- apps/editor/src/commands/defaultCommands.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/editor/src/commands/defaultCommands.ts b/apps/editor/src/commands/defaultCommands.ts index b37cc08af4..16399e47b2 100644 --- a/apps/editor/src/commands/defaultCommands.ts +++ b/apps/editor/src/commands/defaultCommands.ts @@ -7,7 +7,14 @@ export function getDefaultCommands(): Record { return { deleteSelection: () => deleteSelection, selectAll: () => selectAll, - undo: () => undo, + undo: () => (state, dispatch) => { + const hist = state.history$; + + // The initial state is not counted as a history event + if (!hist || hist.done.eventCount === 1) return false; + undo(state, dispatch); + return true; + }, redo: () => redo, }; }