Skip to content
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

Undo sets the cursor to the beginning of the document #132

Closed
alexeyinkin opened this issue Jan 5, 2023 · 1 comment · Fixed by #187
Closed

Undo sets the cursor to the beginning of the document #132

alexeyinkin opened this issue Jan 5, 2023 · 1 comment · Fixed by #187
Labels
bug Something isn't working P2

Comments

@alexeyinkin
Copy link
Contributor

vokoscreen-2023-01-05_15-47-59.mp4
@alexeyinkin alexeyinkin added bug Something isn't working P2 labels Jan 5, 2023
@alexeyinkin alexeyinkin self-assigned this Jan 5, 2023
@alexeyinkin
Copy link
Contributor Author

The first undo record is pushed in the CodeHistoryController constructor. It has the selection collapsed at -1. When changed and undone, that first undo record is applied, and the selection of -1 is somehow converted to 0 which is the beginning of the document.

The quick fix

Find and fix that -1 -> 0 conversion. This would also need a test.

The proper fix

Keep the selection at the edit point when the first edit is undone. Some ideas for this:

  • When creating an undo record, check if the only record below is the initial one. If so, replace it with another one with the selection as it was before the edit.
  • When selection changes, always create an undo record. Replace the older top record if it is different from the pre-top only in the selection.

Tests for this:

  • Go to location A, edit, undo. Expect being at A.
  • Go to location A, edit, go to location B, go to location C, edit, undo, expect being at C, undo, expect being at A.

@alexeyinkin alexeyinkin removed their assignment Jan 5, 2023
This was referenced Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2
Projects
None yet
1 participant