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
7 changed files with 219 additions and 27 deletions
+45
View File
@@ -0,0 +1,45 @@
{"Put":{"state":"hello quˇoel world"}}
{"Key":"v"}
{"Key":"i"}
{"Key":"w"}
{"Key":"s"}
{"Key":"c"}
{"Key":"o"}
{"Key":"escape"}
{"Key":"u"}
{"Get":{"state":"hello ˇquoel world","mode":"Normal"}}
{"Key":"ctrl-r"}
{"Get":{"state":"hello ˇco world","mode":"Normal"}}
{"Key":"a"}
{"Key":"o"}
{"Key":"right"}
{"Key":"l"}
{"Key":"escape"}
{"Get":{"state":"hello cooˇl world","mode":"Normal"}}
{"Key":"u"}
{"Get":{"state":"hello cooˇ world","mode":"Normal"}}
{"Key":"u"}
{"Get":{"state":"hello cˇo world","mode":"Normal"}}
{"Key":"u"}
{"Get":{"state":"hello ˇquoel world","mode":"Normal"}}
{"Put":{"state":"hello quˇoel world"}}
{"Key":"v"}
{"Key":"i"}
{"Key":"w"}
{"Key":"~"}
{"Key":"u"}
{"Get":{"state":"hello ˇquoel world","mode":"Normal"}}
{"Put":{"state":"\nhello quˇoel world\n"}}
{"Key":"shift-v"}
{"Key":"s"}
{"Key":"c"}
{"Key":"escape"}
{"Key":"u"}
{"Get":{"state":"\nˇhello quoel world\n","mode":"Normal"}}
{"Put":{"state":"ˇ1\n2\n3"}}
{"Key":"ctrl-v"}
{"Key":"shift-g"}
{"Key":"ctrl-a"}
{"Get":{"state":"ˇ2\n3\n4","mode":"Normal"}}
{"Key":"u"}
{"Get":{"state":"ˇ1\n2\n3","mode":"Normal"}}