mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-28 15:44:20 +03:00
vim: Support s on selections and with multiple cursors
This commit is contained in:
parent
dcca98b5cc
commit
e1f975e52e
@ -302,6 +302,7 @@
|
|||||||
"x": "vim::VisualDelete",
|
"x": "vim::VisualDelete",
|
||||||
"y": "vim::VisualYank",
|
"y": "vim::VisualYank",
|
||||||
"p": "vim::VisualPaste",
|
"p": "vim::VisualPaste",
|
||||||
|
"s": "vim::Substitute",
|
||||||
"r": [
|
"r": [
|
||||||
"vim::PushOperator",
|
"vim::PushOperator",
|
||||||
"Replace"
|
"Replace"
|
||||||
|
@ -481,17 +481,17 @@ pub(crate) fn normal_replace(text: Arc<str>, cx: &mut WindowContext) {
|
|||||||
pub fn substitute(vim: &mut Vim, count: usize, cx: &mut WindowContext) {
|
pub fn substitute(vim: &mut Vim, count: usize, cx: &mut WindowContext) {
|
||||||
vim.update_active_editor(cx, |editor, cx| {
|
vim.update_active_editor(cx, |editor, cx| {
|
||||||
editor.transact(cx, |editor, cx| {
|
editor.transact(cx, |editor, cx| {
|
||||||
let selection = editor.selections.newest::<Point>(cx);
|
let selections = editor.selections.all::<Point>(cx);
|
||||||
|
for selection in selections.into_iter().rev() {
|
||||||
let end = if selection.start == selection.end {
|
let end = if selection.start == selection.end {
|
||||||
selection.start + Point::new(0, 1)
|
selection.start + Point::new(0, 1)
|
||||||
} else {
|
} else {
|
||||||
selection.end
|
selection.end
|
||||||
};
|
};
|
||||||
|
editor.buffer().update(cx, |buffer, cx| {
|
||||||
editor.buffer().update(cx, |buffer, cx| {
|
buffer.edit([(selection.start..end, "")], None, cx)
|
||||||
buffer.edit([(selection.start..end, "")], None, cx)
|
})
|
||||||
})
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
vim.switch_mode(Mode::Insert, true, cx)
|
vim.switch_mode(Mode::Insert, true, cx)
|
||||||
|
@ -99,12 +99,22 @@ async fn test_buffer_search(cx: &mut gpui::TestAppContext) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_substitute(cx: &mut gpui::TestAppContext) {
|
async fn test_substitute(cx: &mut gpui::TestAppContext) {
|
||||||
let mut cx = VimTestContext::new(cx, true).await;
|
let mut cx = VimTestContext::new(cx, true).await;
|
||||||
|
|
||||||
|
// supports a single cursor
|
||||||
cx.set_state(indoc! {"ˇabc\n"}, Mode::Normal);
|
cx.set_state(indoc! {"ˇabc\n"}, Mode::Normal);
|
||||||
cx.simulate_keystrokes(["s", "x"]);
|
cx.simulate_keystrokes(["s", "x"]);
|
||||||
cx.assert_editor_state("xˇbc\n");
|
cx.assert_editor_state("xˇbc\n");
|
||||||
|
|
||||||
|
// supports a selection
|
||||||
|
cx.set_state(indoc! {"a«bcˇ»\n"}, Mode::Visual { line: false });
|
||||||
|
cx.simulate_keystrokes(["s", "x"]);
|
||||||
|
cx.assert_editor_state("axˇ\n");
|
||||||
|
|
||||||
|
// supports multiple cursors
|
||||||
|
cx.set_state(indoc! {"a«bcˇ»deˇfg\n"}, Mode::Normal);
|
||||||
|
cx.simulate_keystrokes(["s", "x"]);
|
||||||
|
cx.assert_editor_state("axˇdexˇg\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user