Search code examples
javascriptundoquillredo

Make an onClick event equal to an undo keyCode combination? (JavaScript)


Is it possible to make an onClick event equal to a combination of keyCodes? I'm trying to make an undo button. What I want is a button's onClick event to be equal to keying down "Command-Z" or "Ctrl-Z".

I can't create the undo feature from scratch. I'm using QuillJS. The undo feature is already built into the program using the keydown method. But there isn't an undo button built into the program. I'm trying to create one that activates the undo keydown event.


Solution

  • When the button is pressed, call the function:

    quill.history.undo();
    

    Check out the docs at https://quilljs.com/docs/modules/history/

    Answering your question directly, there is no way to trick the quilljs editor into thinking that you pressed control+z in this way.