Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle native undo/redo #3115

Merged
merged 1 commit into from
Jul 25, 2020
Merged

Handle native undo/redo #3115

merged 1 commit into from
Jul 25, 2020

Conversation

luin
Copy link
Member

@luin luin commented Jul 24, 2020

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 using beforeinput to interrupt native undo/redo inputs so we'll use this to handle them natively. Firefox supports this event since v74 but hasn't enabled it by default.

To test:

  • Insert some text, make some chars bold.
  • Click Undo in the context menu, make sure the chars are unbold. Click undo again should remove the text.
  • For Firefox, it should behave the same as before.

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.
@jhchen jhchen merged commit bb013a7 into slab:develop Jul 25, 2020
@Dedrus
Copy link

Dedrus commented Aug 4, 2020

I tried to handle native undo redo click in our electron app(we are using quill, thanks for your work), and saw you PR.
@luin I'm almost sure that due to prevent default there will be no redo option after you clicked undo, because event will not reach stack of commands
https://discuss.prosemirror.net/t/native-undo-history/1823 this discussion covers this case a bit

@luin
Copy link
Member Author

luin commented Aug 4, 2020

@Dedrus Thanks for bringing this up. Actually I tried something pretty similar to the provided link when working on this PR and generally I think the idea works but would require more work on it, whereas the scope of this PR was to prevent potential issues caused by native events.

Anyway, I think it's worth revisiting this for better undo/redo stack handling.

@luin luin deleted the handle-native-undo branch August 4, 2020 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants