Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is electrons webContents.undo() doing?

I want to build an Electron-based App that uses undo-redo functionality. Now it is possible to put undo/redo entries in the menu and according roles already exist in electron. role: undo+ role: redo. As seen here

So what I already found out is probably happening is the that webContents.undo() will be called if I click on the 'undo'-MenuItem.

My question now is, what exactly happens when this undo is called? Can I somehow register a listener and handle the undo myself? Or would it be best practice not to use the 'undo'-role but define a custom menu entry and handle everything myself?

Maybe there is some specification about how the electron chrome browser handles those undo events and where a can catch this and define my own action that should happen on undo/redo.

like image 735
patsimm Avatar asked Nov 25 '25 17:11

patsimm


1 Answers

I think you should define a custom menu entry and handle it yourself.

I don't think you can register a listener and handle it there since there is no event in the webContents documentation.

The menu item would be something like this:

{
    label:       'Undo',
    accelerator: 'CmdOrCtrl+Z',
    click:       function (menuItem, focusedWin) {
        // Undo.
        focusedWin.webContents.undo();

        // Run some custom code.
    }
}
like image 96
Joshua Avatar answered Nov 28 '25 06:11

Joshua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!