How to correctly set the rowCount
parameter before creating a sheet
?
#5674
Replies: 1 comment 1 reply
-
Situation You are monitoring the BeforeCommandExecute event. The ID being caught: sheet.mutation.insert-sheet. Then you are forcing the rowCount parameter to be processed. As a result, Undo/Redo is breaking. Analysis The BeforeCommandExecute event is meant for intercepting/inspecting a command before it runs. If you override internal parameters (like rowCount) at this stage: Initial and final states become inconsistent → because the command manager logs history based on the original parameters, not your overridden values. Undo/Redo relies on the command history stack. If parameters change on the fly without being properly logged, the history becomes corrupted. Possible Solutions Don’t force parameters in BeforeCommandExecute Instead, create a custom command with the correct parameters. Use registerCommand and override the default behavior properly. Use AfterCommandExecute if you only need sync/UI logic This way, Undo/Redo still works based on the original command. If you really must override parameters Make sure you also update the Undo/Redo handlers with the modified parameters. That means extending the CommandManager and defining consistent undo + redo logic for your custom command. Example (Safe Approach) If you want to change the default rowCount: commandManager.registerCommand('custom.insertSheet', {
execute: (ctx, options) => {
const rowCount = options.rowCount || 10; // default 10 rows
return ctx.invokeCommand('sheet.mutation.insert-sheet', { ...options, rowCount });
},
undo: (ctx, options) => ctx.undoCommand('sheet.mutation.insert-sheet', options),
redo: (ctx, options) => ctx.redoCommand('sheet.mutation.insert-sheet', options),
});
// then use this, instead of intercepting BeforeCommandExecute
commandManager.executeCommand('custom.insertSheet', { rowCount: 20 });
👉 In short: Undo/Redo breaks because you’re changing parameters “on the fly” inside BeforeCommandExecute without keeping the history consistent.
Fix: either create a custom command, or move your logic to AfterCommandExecute if you just need to trigger something extra. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, the
BeforeCommandExecute
event is being monitored, ID:sheet.mutation.insert-sheet
, and then the rowCount parameter is being forced to be processed, but this seems to be causing problems with theUndo
andRedo
operations.Beta Was this translation helpful? Give feedback.
All reactions