Skip to content

fix(text-editor): reveal the change after undo, redo and paste - #11138

Open
MichaelUray wants to merge 2 commits into
hcengineering:developfrom
MichaelUray:fix/editor-scroll-on-undo-paste
Open

MichaelUray wants to merge 2 commits into
hcengineering:developfrom
MichaelUray:fix/editor-scroll-on-undo-paste

Conversation

@MichaelUray

Copy link
Copy Markdown
Contributor

Fixes #7814

Problem and change

In collaborative documents undo/redo is handled by the Yjs undo manager. y-prosemirror restores the selection captured before the Yjs transaction (the selection-restoring 'stack-item-popped' event fires only after the document was updated), so the cursor stays where it was and a change made outside the viewport is never shown. The custom markdown and table paste handlers also dispatched their transactions without scrollIntoView, unlike the default ProseMirror paste.

Wrap the collaboration undo/redo commands so that, after a successful undo/redo, the cursor moves to the changed range and it is scrolled into view (selection-only transaction, not added to history). Add scrollIntoView to the smart paste and table paste transactions. Add unit tests for the changed-range helper and the paste scroll.

Tests

New unit tests plugins/text-editor-resources/src/components/extension/__tests__/collaboration.test.ts and an extra assertion in shortcuts/__tests__/smartPaste.test.ts. Checked manually on a self-hosted instance: after typing at the end of a long document and scrolling to the top, Ctrl/Cmd+Z scrolls to the change, redo scrolls to the restored text, and pasting a long plain-text block keeps the end of the paste in view.

In collaborative documents undo/redo is handled by the Yjs undo manager. y-prosemirror restores the selection captured before the Yjs transaction (the selection-restoring 'stack-item-popped' event fires only after the document was updated), so the cursor stays where it was and a change made outside the viewport is never shown. The custom markdown and table paste handlers also dispatched their transactions without scrollIntoView, unlike the default ProseMirror paste.

Wrap the collaboration undo/redo commands so that, after a successful undo/redo, the cursor moves to the changed range and it is scrolled into view (selection-only transaction, not added to history). Add scrollIntoView to the smart paste and table paste transactions. Add unit tests for the changed-range helper and the paste scroll.

Fixes hcengineering#7814

Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>
…ation extension

Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>
@MichaelUray
MichaelUray force-pushed the fix/editor-scroll-on-undo-paste branch from 85bd0ab to d4d7aa0 Compare October 19, 2026 06:42

This branch has not been deployed

No deployments
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.

Fix undo & paste keyboard shortcuts

1 participant