Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork999
How to correctly set therowCount parameter before creating asheet?#5674
-
Currently, the |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 1 reply
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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 rowsreturn 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 BeforeCommandExecutecommandManager.executeCommand('custom.insertSheet', { rowCount: 20 });👉 In short: Undo/Redo breaks because you’re changing parameters “on the fly” inside BeforeCommandExecute without keeping thehistory consistent.Fix: either create a custom command, or move your logic to AfterCommandExecuteif you just need to trigger something extra. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks, I actually tried this approach, I felt it was too much trouble, and finally tried to use |
BetaWas this translation helpful?Give feedback.