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

NotWearingPants commented Oct 15, 2019

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

This comment has been minimized.

Copy link

msftclas commented Oct 15, 2019

CLA assistant check
All CLA requirements met.

@alexandrudima alexandrudima force-pushed the NotWearingPants:feature/cursor-redo branch 2 times, most recently from 3505c10 to e9fee2c Oct 18, 2019
NotWearingPants and others added 2 commits Oct 14, 2019
@alexandrudima alexandrudima force-pushed the NotWearingPants:feature/cursor-redo branch from e9fee2c to a1ff866 Oct 18, 2019
@alexandrudima alexandrudima merged commit 259b7bf into microsoft:master Oct 18, 2019
1 of 2 checks passed
1 of 2 checks passed
VS Code in progress
Details
license/cla All CLA requirements met.
Details
@alexandrudima alexandrudima added this to the October 2019 milestone Oct 18, 2019
@NotWearingPants

This comment has been minimized.

Copy link
Contributor Author

NotWearingPants commented Oct 20, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.