-
Notifications
You must be signed in to change notification settings - Fork 470
Improve handling of undo/redo events in web demo (#1254) #1255
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
|
||
| for (let textarea_id in editor_by_textarea_id) { | ||
| let editor = editor_by_textarea_id[textarea_id]; | ||
| let startedJobId = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I understand correctly you're using this to serialise processing each of the change events?
I think that's ok. Though I think there's another way to do it without the setTimeout: You can keep a reference to an 'ongoing change' to await, and then chain them. Something like this:
let ongoingChange = Promise.resolve(true);
editor.on('change', function() {
return ongoingChange.then(async () => {
try {
// previous change is complete and future changes are queued on our promise
// do the event processing
} catch (e) {
// log the error; if it unwinds further then it'll break the Promise chain
}
});
});What do you think? (I haven't tried running this to verify it!)
|
Thanks for the contribution! It's great to have a fix for this! |
Fixes #1254. In the demo on https://jsonnet.org, if you hit redo/undo for multiple characters, the demo breaks. This seems to be because the browser generates multiple text change events (Chrome 139, MacOS 14.6).
Previous Behavior
https://jsonnet.org/
Screen.Recording.2025-09-02.at.8.12.12.PM.mov
New Behavior
Screen.Recording.2025-09-02.at.8.12.43.PM.mov