Improve vim undo (#9317)

The important change here is to ensure that undo never lands you in
visual mode; but we also take care to restore the selection the same way
vim does (visual line goes to beginning of line, visual block to the top
left, etc.).

To help make this behaviour feel right we also group any deletions that
started insert mode with the first text inserted.

Fixes: #7521

Release Notes:

- vim: Improved undo. It will now restore you to normal mode in the same
position as vim, and group deletions caused by `c` or `s` with the
concomitant insert.
([#7521](https://github.com/zed-industries/zed/issues/7521)).
This commit is contained in:
Conrad Irwin 2024-03-13 23:12:12 -06:00 committed by GitHub
parent 6ae5274954
commit bffde43c12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 219 additions and 27 deletions

View file

@ -1,8 +1,9 @@
use std::{fmt::Display, ops::Range, sync::Arc};
use collections::HashMap;
use editor::Anchor;
use gpui::{Action, KeyContext};
use language::CursorShape;
use language::{CursorShape, Selection, TransactionId};
use serde::{Deserialize, Serialize};
use workspace::searchable::Direction;
@ -66,6 +67,10 @@ pub struct EditorState {
pub post_count: Option<usize>,
pub operator_stack: Vec<Operator>,
pub current_tx: Option<TransactionId>,
pub current_anchor: Option<Selection<Anchor>>,
pub undo_modes: HashMap<TransactionId, Mode>,
}
#[derive(Default, Clone, Debug)]