vim: (BREAKING) clean up keymap contexts (#14233)

Release Notes:

- vim: (BREAKING) Improved vim keymap contexts.

Previously `vim_mode == normal` was true even when operators were
pending, which led to bugs like #13789 and a requirement for custom
keymaps to exclude various conditions like (`!VimObject` and
`!VimWaiting`) to avoid bugs.

Now `vim_mode` will be set to `operator` or `waiting` in these cases as
described in [the docs](https://zed.dev/docs/vim#keybindings). For most
custom keymaps this change will be a no-op or an improvement, but if you
were deliberately relying on the old behaviour (if you were relying on
`VimObject` or `VimWaiting` becoming true) you will need to update your
keymap.

---------

Co-authored-by: Thorsten <thorsten@zed.dev>
This commit is contained in:
Conrad Irwin 2024-07-11 13:16:26 -06:00 committed by GitHub
parent 8e853e2b56
commit b0dbc80575
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 186 additions and 246 deletions

View file

@ -76,6 +76,7 @@ struct SelectRegister(String);
actions!(
vim,
[
ClearOperators,
Tab,
Enter,
Object,
@ -129,6 +130,9 @@ fn register(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
Vim::update(cx, |vim, cx| vim.push_operator(operator.clone(), cx))
},
);
workspace.register_action(|_: &mut Workspace, _: &ClearOperators, cx| {
Vim::update(cx, |vim, cx| vim.clear_operator(cx))
});
workspace.register_action(|_: &mut Workspace, n: &Number, cx: _| {
Vim::update(cx, |vim, cx| vim.push_count_digit(n.0, cx));
});
@ -973,7 +977,7 @@ impl Vim {
editor.set_cursor_shape(state.cursor_shape(), cx);
editor.set_clip_at_line_ends(state.clip_at_line_ends(), cx);
editor.set_collapse_matches(true);
editor.set_input_enabled(!state.vim_controlled());
editor.set_input_enabled(state.editor_input_enabled());
editor.set_autoindent(state.should_autoindent());
editor.selections.line_mode = matches!(state.mode, Mode::VisualLine);
if editor.is_focused(cx) || editor.mouse_menu_is_focused(cx) {