-
Notifications
You must be signed in to change notification settings - Fork 700
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
Commands to move caret through undo history #808
Comments
I like this idea; it's sort of like a more focused ctrl+o/ctrl+i (in vim). Currently we don't stash selection state in the undo stack, which feels related, and would also be nice to have, e.g. undo should restore your selection/cursor state to whatever it was immediately before the current undo group was created. |
Using stashed selection state is a possibility, but even without it, just placing the caret at the end of the modified range of text is good enough. |
With this patch, we now keep track of selection state as we create and modify undo groups, which lets us restore selections to their state immediately before or after a given edit (edit group) during undo/redo. closes xi-editor#458, closes xi-editor#765 related xi-editor#326, xi-editor#808
With this patch, we now keep track of selection state as we create and modify undo groups, which lets us restore selections to their state immediately before or after a given edit (edit group) during undo/redo. I had trouble figuring out exactly what state we wanted to store and how we wanted to represent that. The first version of this just had a single state per undo group; we would always save the last selection state for a given undo group, updating it on movement events. This didn't work. The problem, I think, is that we have different expectations for undo versus redo. As an example, let's say we've just opened a file with the contents, 'hello'. In our view, this looks like, `hello|` where `|` is the cursor. We enter a space and 'world!'; our view looks like `hello world!|`. We use the arrows to select 'world!' (our view looks like `hello [|world!]`) and type 'dear friend'. We now have two undo groups, corresponding to `hello world!` and `hello dear friend`. (We don't include the state of the document when it was opened, which can't be undone.) If we undo, at this stage, we want everything to go back to the state it was in before the last edit; i.e., `hello [|world!]`. If we undo _again_, we should have `hello|`, our starting state. However, what should now happen on _redo_? If we store a single state per edit, we would end up being back at `hello [|world!]`, which I don't think is right; we want `hello world!|`, the state immediately after the 'world!' edit. This means that (at least in some cases) we need to store two separate states; the state to restore on undo (which is the state immediately before the new edit group was crated) and also the state to restore on redo, which is the state immediately after the last edit in the edit group. closes xi-editor#458, closes xi-editor#765 related xi-editor#326, xi-editor#808
It would be helpful to have commands to place the caret at various changes in the undo history, without actually having to undo/redo the changes. I very often the caret around to look around the file, and then I want to move the caret back to where I was last editing. Sometimes I even want to walk through the undo history and see all the different places where I have recently edited something. I don't know of any other editor that has this feature.
Specification:
The commands “Move to previous change” (bound to
Alt-Z
) and “Move to next change” (bound toAlt-Y
) select entries in the history of changes that can be undone and redone and place the caret at them.When the last command used was not one of these commands, the command “Move to previous change” selects the latest change in the undo history before the start of the redo history, and the command “Move to next change” selects the earliest change in the redo history.
When the last command used was one of these commands, the command “Move to previous change” selects the latest change prior to the change selected by the last command, and the command “Move to next change” selects the earliest change after the change selected by the last command, aborting if there is no such entry.
The caret is placed at the end position of the selected change. The caret is transformed by applying the selected change and all intermediate changes until the current state of the document is reached. When the caret is within the range of a change to apply, the caret is placed at the end of that change.
The text was updated successfully, but these errors were encountered: