Skip to content

Commit

Permalink
Handle native undo/redo
Browse files Browse the repository at this point in the history
Currently our editor listens on the common hotkeys (cmd+z / cmd+shift+z)
for undo/redo but the user could always undo using native browser UI
like right-click, the edit topbar menu, and on mobile iOS there is a toolbar,
and the native undo usually does not do the right thing.

Most modern browsers support `beforeinput` to interrupt native undo/redo inputs
so we'll use this to handle them natively.
  • Loading branch information
luin committed Jul 24, 2020
1 parent 84d2234 commit 474f081
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions modules/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class History extends Module {
this.redo.bind(this),
);
}

this.quill.root.addEventListener('beforeinput', event => {
if (event.inputType === 'historyUndo') {
this.undo();
event.preventDefault();
} else if (event.inputType === 'historyRedo') {
this.redo();
event.preventDefault();
}
});
}

change(source, dest) {
Expand Down

0 comments on commit 474f081

Please sign in to comment.