vim: Make cc
and S
auto-indent (#9731)
Fix #9612 Release notes: * Changed `cc` and `S` in Vim mode to only change the current line after its indentation. #9612
This commit is contained in:
parent
ff685b299d
commit
2f2f236afe
2 changed files with 65 additions and 1 deletions
|
@ -48,7 +48,25 @@ pub fn change_motion(vim: &mut Vim, motion: Motion, times: Option<usize>, cx: &m
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
motion.expand_selection(map, selection, times, false, &text_layout_details)
|
let result = motion.expand_selection(
|
||||||
|
map,
|
||||||
|
selection,
|
||||||
|
times,
|
||||||
|
false,
|
||||||
|
&text_layout_details,
|
||||||
|
);
|
||||||
|
if let Motion::CurrentLine = motion {
|
||||||
|
let scope = map
|
||||||
|
.buffer_snapshot
|
||||||
|
.language_scope_at(selection.start.to_point(&map));
|
||||||
|
for (ch, _) in map.chars_at(selection.start) {
|
||||||
|
if ch == '\n' || char_kind(&scope, ch) != CharKind::Whitespace {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*selection.start.column_mut() += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -398,6 +416,40 @@ mod test {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_change_cc(cx: &mut gpui::TestAppContext) {
|
||||||
|
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||||
|
cx.assert_neovim_compatible(
|
||||||
|
indoc! {"
|
||||||
|
The quick
|
||||||
|
brownˇ fox
|
||||||
|
jumps over
|
||||||
|
the lazy"},
|
||||||
|
["c", "c"],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
cx.assert_neovim_compatible(
|
||||||
|
indoc! {"
|
||||||
|
ˇThe quick
|
||||||
|
brown fox
|
||||||
|
jumps over
|
||||||
|
the lazy"},
|
||||||
|
["c", "c"],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
cx.assert_neovim_compatible(
|
||||||
|
indoc! {"
|
||||||
|
The quick
|
||||||
|
broˇwn fox
|
||||||
|
jumˇps over
|
||||||
|
the lazy"},
|
||||||
|
["c", "c"],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_change_gg(cx: &mut gpui::TestAppContext) {
|
async fn test_change_gg(cx: &mut gpui::TestAppContext) {
|
||||||
let mut cx = NeovimBackedTestContext::new(cx).await;
|
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||||
|
|
12
crates/vim/test_data/test_change_cc.json
Normal file
12
crates/vim/test_data/test_change_cc.json
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{"Put":{"state":"The quick\n brownˇ fox\njumps over\nthe lazy"}}
|
||||||
|
{"Key":"c"}
|
||||||
|
{"Key":"c"}
|
||||||
|
{"Get":{"state":"The quick\n ˇ\njumps over\nthe lazy","mode":"Insert"}}
|
||||||
|
{"Put":{"state":"ˇThe quick\nbrown fox\njumps over\nthe lazy"}}
|
||||||
|
{"Key":"c"}
|
||||||
|
{"Key":"c"}
|
||||||
|
{"Get":{"state":"ˇ\nbrown fox\njumps over\nthe lazy","mode":"Insert"}}
|
||||||
|
{"Put":{"state":"The quick\n broˇwn fox\njumˇps over\nthe lazy"}}
|
||||||
|
{"Key":"c"}
|
||||||
|
{"Key":"c"}
|
||||||
|
{"Get":{"state":"The quick\n ˇ\nˇ\nthe lazy","mode":"Insert"}}
|
Loading…
Add table
Add a link
Reference in a new issue