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

Add cursorRedo command (Ctrl+Shift+J) #82620

Merged
merged 2 commits into from
Oct 18, 2019

Conversation

NotWearingPants
Copy link
Contributor

There is a command called cursorUndo which is used to undo cursor and selection changes.
The undo stack is flushed when the text changes.

This PR adds a cursorRedo command to complement cursorUndo, and binds it to Ctrl+Shift+J by default.

This fixes #82007

How to test

  1. Open an empty buffer
  2. Type some text
  3. Move the cursor around with commands that do not modify the text itself. You can also select things and multi-select.
  4. Press Ctrl+U a couple of times to undo some of those movements
  5. Press Ctrl+Shift+J to redo each movement you just undid.
  6. Modify the text - the undo/redo stack should be flushed and you should not be able to use cursorUndo/cursorRedo to get to the previous cursor locations.

Implementation

To do this I refactored the code to separate the part that interacts with the editor (CursorUndoController) from the cursor undo/redo logic (CursorStateStack).

Previously a list of cursor states was kept, and to undo the state it would pop the latest state from the list.

This PR changes that to a list of cursor states and an index to where we are currently inside that list.
When undoing or redoing the index is moved without deleting any states from the list.
When the state changes, all the states after where we are currently inside the list are dropped, and the new state is added.

@msftclas
Copy link

msftclas commented Oct 15, 2019

CLA assistant check
All CLA requirements met.

@alexdima alexdima force-pushed the feature/cursor-redo branch 2 times, most recently from 3505c10 to e9fee2c Compare October 18, 2019 08:56
@alexdima alexdima merged commit 259b7bf into microsoft:master Oct 18, 2019
@alexdima alexdima added this to the October 2019 milestone Oct 18, 2019
@NotWearingPants
Copy link
Contributor Author

@alexandrudima you completely deleted my entire code without even leaving a comment. What gives?

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature-Request: cursorRedo / Soft Redo
3 participants