-
Notifications
You must be signed in to change notification settings - Fork 111
fix: first action in empty document cannot be undone #8063
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
Conversation
96bab2c to
f79ac10
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
max-nextcloud
left a comment
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.
Thanks for tracking this down! ❤️
Signed-off-by: Benjamin Frueh <[email protected]>
f79ac10 to
12dca2b
Compare
|
/backport to stable32 |
|
/backport to stable31 |
|
/backport to stable30 please |
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
Description
Fixes an issue where the first user action (e.g. typing or pasting) in an empty collaborative document cannot be undone. All actions after that work fine.
Root Cause
The Yjs UndoManager tracks changes using a
lastChangetimestamp. WhenlastChangeis0, the undo manager sets the timestamp but skips tracking that transaction. The first action in an empty document haslastChange = 0, so it gets skipped.Why
lastChangeis0on first action:The
TextDirectionextension detects and sets text direction (LTR/RTL) on the first user action. The extension setstr.setMeta('addToHistory', false)to prevent the direction change from being tracked as a separate undo step.This causes the following:
addToHistory: falseand callsundoManager.stopCapturing()(sync-plugin.js:223)stopCapturing()resetslastChange = 0(UndoManager.js:333)lastChange = 0and is not added to undo stackAfter the first action, the TextDirection extension skips processing, so no
addToHistory: falseis set and undo works normally.Solution
Remove
tr.setMeta('addToHistory', false)from the TextDirection extension. The direction change is now tracked together with the user's text input.Tested with both LTR and RTL languages - the
addToHistory: falseflag is not needed for correct text direction and consistent undo behavior.Regression Test
Added
playwright/e2e/history.spec.tsto prevent this bug from reoccurring. The test verifies that the first action in an empty document can be undone.