Skip to content

Conversation

@benjaminfrueh
Copy link
Contributor

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 lastChange timestamp. When lastChange is 0, the undo manager sets the timestamp but skips tracking that transaction. The first action in an empty document has lastChange = 0, so it gets skipped.

Why lastChange is 0 on first action:

The TextDirection extension detects and sets text direction (LTR/RTL) on the first user action. The extension sets tr.setMeta('addToHistory', false) to prevent the direction change from being tracked as a separate undo step.

This causes the following:

  1. y-tiptap sync plugin sees addToHistory: false and calls undoManager.stopCapturing() (sync-plugin.js:223)
  2. stopCapturing() resets lastChange = 0 (UndoManager.js:333)
  3. User's first action runs with lastChange = 0 and is not added to undo stack

After the first action, the TextDirection extension skips processing, so no addToHistory: false is 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: false flag is not needed for correct text direction and consistent undo behavior.

Regression Test

Added playwright/e2e/history.spec.ts to prevent this bug from reoccurring. The test verifies that the first action in an empty document can be undone.

@benjaminfrueh benjaminfrueh force-pushed the fix/first-action-undo branch 2 times, most recently from 96bab2c to f79ac10 Compare December 15, 2025 09:50
@benjaminfrueh benjaminfrueh requested a review from elzody December 15, 2025 09:50
@benjaminfrueh benjaminfrueh added 3. to review bug Something isn't working labels Dec 15, 2025
@github-project-automation github-project-automation bot moved this to 🧭 Planning evaluation (don't pick) in 📝 Office team Dec 15, 2025
@benjaminfrueh benjaminfrueh moved this from 🧭 Planning evaluation (don't pick) to 👀 In review in 📝 Office team Dec 15, 2025
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@max-nextcloud max-nextcloud left a 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! ❤️

@mejo- mejo- force-pushed the fix/first-action-undo branch from f79ac10 to 12dca2b Compare December 15, 2025 12:43
@mejo- mejo- merged commit ef43ca7 into main Dec 15, 2025
74 of 77 checks passed
@mejo- mejo- deleted the fix/first-action-undo branch December 15, 2025 13:59
@github-project-automation github-project-automation bot moved this from 👀 In review to ☑️ Done in 📝 Office team Dec 15, 2025
@mejo-
Copy link
Member

mejo- commented Dec 15, 2025

/backport to stable32

@mejo-
Copy link
Member

mejo- commented Dec 15, 2025

/backport to stable31

@elzody
Copy link
Contributor

elzody commented Dec 15, 2025

/backport to stable30 please

@github-actions
Copy link
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: ☑️ Done

Development

Successfully merging this pull request may close these issues.

5 participants