Pause (not disable) undo history

Posted by: brian.ploe on 17 January 2023, 10:58 pm EST

  • Posted 17 January 2023, 10:58 pm EST

    Hello,

    1. I’d like to execute a command without it entering the undo history. I don’t want to erase existing history or cause the history to loop back around. I just want a specific command not to be added to it when I need it to be paused.

      After the command is executed, I will turn undo history back on.

    I tried suspendDirty(), allowUndo, etc and everything still adds to undo history.

    1. Is there a way to intercept ALL command events, one at a time as they occur, in a similar format to the undo history commands but with actual event triggering? I’d like to do this without having to bind events to every single command type.

    What I’m trying to do is mimic the collaboration that can be done in Excel via MS Teams by sending commands across the wire to users editing the same workbook to keep them in sync. But, I don’t want the command crossing the network to be added to the other user’s undo.

    Thanks!

  • Posted 20 January 2023, 4:52 am EST

    Hi Brian,

    Query1: When you call the commandManager.execute() method to execute a command, it adds an entry to the Undo Stack by default. This is intentional behaviour.

    However, if you want to execute a command without adding it to the Undo stack, you can get the command and then call the command’s execute method. This way, it won’t be added to the Undo stack.

    Consider the following two possibilities:

    The following code will create an entry in the Undo Stack:

    // Use the commandManager's execute method
    commandManager.execute({
        cmd: "editCell",
        sheetName: sheetName,
        row: 1,
        col: 1,
        newValue: "Cell A2",
        autoFormat: true,
    });

    The following code will not add an entry to the Undo Stack:

    // Get the command and call the execute method
    let editCellCmd = spread.commandManager().getCommand("editCell");
    editCellCmd.execute(spread, {
        sheetName: sheetName,
        row: 0,
        col: 0,
        newValue: "Cell A1",
        autoFormat: true,
    })

    You could use the second approach for your use case and pass the commandOptions as the second parameter.

    Query2: To intercept all commands, use the following code snippet:

    spread.commandManager().addListener("appListener", function (info) {
        console.log('app listener');
        console.log(info);
    })

    Sample: https://jscodemine.grapecity.com/share/uZgWM35roEeaSzji2xZd9g/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fsrc%2Fapp.js"%2C"%2Fpackage.json"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}

    I hope this helps you with your problem. Please let us know if you require any additional assistance with this matter. We would be delighted to assist you.

    Regards,

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels