Skip to content

Commit 4085715

Browse files
authored
Only toggle insert style on <Insert> press in Insert mode (#177)
1 parent 99c892a commit 4085715

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

crates/modalkit/src/env/vim/keybindings.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ enum InternalAction {
179179
SetCursorChar(char),
180180
SetCursorDigraph,
181181
SetInsertStyle(InsertStyle),
182+
SetOrToggleInsertStyle(InsertStyle),
182183
SetTargetShape(TargetShapeFilter, TargetShape),
183184
SetOperation(EditAction),
184185
SetPostMode(VimMode),
@@ -238,6 +239,9 @@ impl InternalAction {
238239
}
239240
},
240241
InternalAction::SetInsertStyle(style) => {
242+
ctx.persist.insert = Some(*style);
243+
},
244+
InternalAction::SetOrToggleInsertStyle(style) => {
241245
match ctx.persist.insert {
242246
None => {
243247
ctx.persist.insert = Some(*style);
@@ -934,6 +938,18 @@ macro_rules! insert {
934938
};
935939
}
936940

941+
macro_rules! insert_toggle {
942+
($style: expr) => {
943+
isv!(
944+
vec![InternalAction::SetOrToggleInsertStyle($style)],
945+
vec![ExternalAction::Something(
946+
CursorAction::Split(Count::MinusOne).into()
947+
)],
948+
VimMode::Insert
949+
)
950+
};
951+
}
952+
937953
macro_rules! paste_register {
938954
($dir: expr, $reg: expr) => {
939955
is!(
@@ -1747,7 +1763,7 @@ fn default_keys<I: ApplicationInfo>() -> Vec<(MappedModes, &'static str, InputSt
17471763
( IMAP, "<Esc>", normal!() ),
17481764
( IMAP, "<Tab>", chartype!(Char::Single('\t')) ),
17491765
( IMAP, "<C-Home>", edit!(EditAction::Motion, MoveType::BufferPos(MovePosition::Beginning)) ),
1750-
( IMAP, "<Insert>", insert!(InsertStyle::Replace) ),
1766+
( IMAP, "<Insert>", insert_toggle!(InsertStyle::Replace) ),
17511767
( IMAP, "<PageDown>", scroll2d!(MoveDir2D::Down, ScrollSize::Page) ),
17521768
( IMAP, "<PageUp>", scroll2d!(MoveDir2D::Up, ScrollSize::Page) ),
17531769

@@ -1782,7 +1798,7 @@ fn default_keys<I: ApplicationInfo>() -> Vec<(MappedModes, &'static str, InputSt
17821798
( CMAP, "<S-Down>", prompt!(PromptAction::Recall(RecallFilter::All, MoveDir1D::Next, Count::Contextual)) ),
17831799
( CMAP, "<PageUp>", prompt!(PromptAction::Recall(RecallFilter::All, MoveDir1D::Previous, Count::Contextual)) ),
17841800
( CMAP, "<PageDown>", prompt!(PromptAction::Recall(RecallFilter::All, MoveDir1D::Next, Count::Contextual)) ),
1785-
( CMAP, "<Insert>", iact!(InternalAction::SetInsertStyle(InsertStyle::Replace)) ),
1801+
( CMAP, "<Insert>", iact!(InternalAction::SetOrToggleInsertStyle(InsertStyle::Replace)) ),
17861802

17871803
// Operator-Pending mode
17881804
( OMAP, "gn", unmapped!() ),

0 commit comments

Comments
 (0)