Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to correctly set therowCount parameter before creating asheet?#5674

Unanswered
Pengap asked this question inQ&A | 常见问题
Discussion options

Currently, theBeforeCommandExecute 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.

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

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.
You must be logged in to vote
1 reply
@Pengap
Comment options

Thanks, I actually tried this approach, I felt it was too much trouble, and finally tried to useJS event rewriting to override the event of the addsheet button, and it seems to work fine.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
2 participants
@Pengap@Rosellines

[8]ページ先頭

©2009-2025 Movatter.jp