Skip to content

Commit

Permalink
vim: add support for insert-btn
Browse files Browse the repository at this point in the history
This commit adds support for using the physical insert-btn. First
click toggles insert mode and subsequent clicks toggle back and
forth between replace and insert mode.
  • Loading branch information
axelcarl committed Oct 15, 2024
1 parent b739cfa commit f986b27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions assets/keymaps/vim.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"@": ["vim::PushOperator", "ReplayRegister"],
"ctrl-pagedown": "pane::ActivateNextItem",
"ctrl-pageup": "pane::ActivatePrevItem",
"insert": "vim::InsertBefore",
// tree-sitter related commands
"[ x": "editor::SelectLargerSyntaxNode",
"] x": "editor::SelectSmallerSyntaxNode",
Expand Down Expand Up @@ -334,7 +335,8 @@
"ctrl-t": "vim::Indent",
"ctrl-d": "vim::Outdent",
"ctrl-k": ["vim::PushOperator", { "Digraph": {} }],
"ctrl-r": ["vim::PushOperator", "Register"]
"ctrl-r": ["vim::PushOperator", "Register"],
"insert": "vim::ToggleReplace"
}
},
{
Expand All @@ -353,7 +355,8 @@
"ctrl-k": ["vim::PushOperator", { "Digraph": {} }],
"backspace": "vim::UndoReplace",
"tab": "vim::Tab",
"enter": "vim::Enter"
"enter": "vim::Enter",
"insert": "vim::InsertBefore"
}
},
{
Expand Down
11 changes: 10 additions & 1 deletion crates/vim/src/vim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ impl Vim {
operator,
Operator::Change
| Operator::Delete
| Operator::Replace
| Operator::Indent
| Operator::Outdent
| Operator::Lowercase
Expand All @@ -409,6 +408,16 @@ impl Vim {
) {
self.start_recording(cx)
};

if matches!(operator, Operator::Replace) {
// Switch to normal mode when replacing from insert mode.
if matches!(self.mode, Mode::Insert) {
self.switch_mode(Mode::Normal, true, cx);
}

self.start_recording(cx);
}

// Since these operations can only be entered with pre-operators,
// we need to clear the previous operators when pushing,
// so that the current stack is the most correct
Expand Down

0 comments on commit f986b27

Please sign in to comment.