Skip to content

✨ Restore Cursor and Scroll Position on Undo/Redo #95

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

Open
austincondiff opened this issue May 7, 2025 · 0 comments
Open

✨ Restore Cursor and Scroll Position on Undo/Redo #95

austincondiff opened this issue May 7, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@austincondiff
Copy link
Contributor

austincondiff commented May 7, 2025

Description

When performing an undo or redo, the cursor and scroll position should return to the state they were in at the time of the change. Currently, only the text content is restored, but the selection and scroll position are not preserved, which can disrupt the editing experience—especially during rapid or successive edits.

Expected Behavior

  • When a change is undone, the insertion point and scroll position should move to where they were when the change originally occurred.
  • When a change is redone, the insertion point and scroll position should likewise be restored to their prior state.
  • This behavior should feel seamless and natural, mirroring the expectations of professional editors on macOS.

Proposed Implementation

  • Extend the existing Mutation or UndoGroup struct to include the selected range and visible scroll rect at the time of the change.
  • Capture these properties during registerMutation(_:).
  • Restore the stored selected range and scroll rect in undo() and redo() methods after applying the text mutations.

Benefits

  • Improves consistency and usability of the editor during undo/redo workflows.
  • Reduces disorientation from insertion point jumps or loss of context.
  • Brings CodeEditTextView in line with native Mac editor expectations.

Additional Notes

  • Consider edge cases such as when the associated text range no longer exists.
@austincondiff austincondiff added the enhancement New feature or request label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant