mirror of
https://github.com/zed-industries/zed.git
synced 2024-09-18 18:08:07 +03:00
vim: Set current line as default sed command scope (#17234)
Closes #16977 Release Notes: - added current line as default sed range to match vim's behavior - changed tests accordingly This also simplifies `ReplaceCommand` implementation by changing `Option<CommandRange>` to `CommandRange` .
This commit is contained in:
parent
65bc1ea7c8
commit
694c912201
@ -656,13 +656,11 @@ pub fn command_interceptor(mut input: &str, cx: &AppContext) -> Option<CommandIn
|
|||||||
query.next();
|
query.next();
|
||||||
}
|
}
|
||||||
if let Some(replacement) = Replacement::parse(query) {
|
if let Some(replacement) = Replacement::parse(query) {
|
||||||
Some(
|
let range = range.clone().unwrap_or(CommandRange {
|
||||||
ReplaceCommand {
|
start: Position::CurrentLine { offset: 0 },
|
||||||
replacement,
|
end: None,
|
||||||
range: range.clone(),
|
});
|
||||||
}
|
Some(ReplaceCommand { replacement, range }.boxed_clone())
|
||||||
.boxed_clone(),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -789,11 +787,13 @@ mod test {
|
|||||||
cx.set_shared_state(indoc! {"
|
cx.set_shared_state(indoc! {"
|
||||||
ˇa
|
ˇa
|
||||||
b
|
b
|
||||||
|
b
|
||||||
c"})
|
c"})
|
||||||
.await;
|
.await;
|
||||||
cx.simulate_shared_keystrokes(": % s / b / d enter").await;
|
cx.simulate_shared_keystrokes(": % s / b / d enter").await;
|
||||||
cx.shared_state().await.assert_eq(indoc! {"
|
cx.shared_state().await.assert_eq(indoc! {"
|
||||||
a
|
a
|
||||||
|
d
|
||||||
ˇd
|
ˇd
|
||||||
c"});
|
c"});
|
||||||
cx.simulate_shared_keystrokes(": % s : . : \\ 0 \\ 0 enter")
|
cx.simulate_shared_keystrokes(": % s : . : \\ 0 \\ 0 enter")
|
||||||
@ -801,7 +801,14 @@ mod test {
|
|||||||
cx.shared_state().await.assert_eq(indoc! {"
|
cx.shared_state().await.assert_eq(indoc! {"
|
||||||
aa
|
aa
|
||||||
dd
|
dd
|
||||||
|
dd
|
||||||
ˇcc"});
|
ˇcc"});
|
||||||
|
cx.simulate_shared_keystrokes("k : s / dd / ee enter").await;
|
||||||
|
cx.shared_state().await.assert_eq(indoc! {"
|
||||||
|
aa
|
||||||
|
dd
|
||||||
|
ˇee
|
||||||
|
cc"});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
@ -42,7 +42,7 @@ pub struct FindCommand {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||||
pub struct ReplaceCommand {
|
pub struct ReplaceCommand {
|
||||||
pub(crate) range: Option<CommandRange>,
|
pub(crate) range: CommandRange,
|
||||||
pub(crate) replacement: Replacement,
|
pub(crate) replacement: Replacement,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,20 +338,18 @@ impl Vim {
|
|||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if let Some(range) = &action.range {
|
if let Some(result) = self.update_editor(cx, |vim, editor, cx| {
|
||||||
if let Some(result) = self.update_editor(cx, |vim, editor, cx| {
|
let range = action.range.buffer_range(vim, editor, cx)?;
|
||||||
let range = range.buffer_range(vim, editor, cx)?;
|
let snapshot = &editor.snapshot(cx).buffer_snapshot;
|
||||||
let snapshot = &editor.snapshot(cx).buffer_snapshot;
|
let end_point = Point::new(range.end.0, snapshot.line_len(range.end));
|
||||||
let end_point = Point::new(range.end.0, snapshot.line_len(range.end));
|
let range = snapshot.anchor_before(Point::new(range.start.0, 0))
|
||||||
let range = snapshot.anchor_before(Point::new(range.start.0, 0))
|
..snapshot.anchor_after(end_point);
|
||||||
..snapshot.anchor_after(end_point);
|
editor.set_search_within_ranges(&[range], cx);
|
||||||
editor.set_search_within_ranges(&[range], cx);
|
anyhow::Ok(())
|
||||||
anyhow::Ok(())
|
}) {
|
||||||
}) {
|
workspace.update(cx, |workspace, cx| {
|
||||||
workspace.update(cx, |workspace, cx| {
|
result.notify_err(workspace, cx);
|
||||||
result.notify_err(workspace, cx);
|
})
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let vim = cx.view().clone();
|
let vim = cx.view().clone();
|
||||||
pane.update(cx, |pane, cx| {
|
pane.update(cx, |pane, cx| {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{"Put":{"state":"ˇa\nb\nc"}}
|
{"Put":{"state":"ˇa\nb\nb\nc"}}
|
||||||
{"Key":":"}
|
{"Key":":"}
|
||||||
{"Key":"%"}
|
{"Key":"%"}
|
||||||
{"Key":"s"}
|
{"Key":"s"}
|
||||||
@ -7,7 +7,7 @@
|
|||||||
{"Key":"/"}
|
{"Key":"/"}
|
||||||
{"Key":"d"}
|
{"Key":"d"}
|
||||||
{"Key":"enter"}
|
{"Key":"enter"}
|
||||||
{"Get":{"state":"a\nˇd\nc","mode":"Normal"}}
|
{"Get":{"state":"a\nd\nˇd\nc","mode":"Normal"}}
|
||||||
{"Key":":"}
|
{"Key":":"}
|
||||||
{"Key":"%"}
|
{"Key":"%"}
|
||||||
{"Key":"s"}
|
{"Key":"s"}
|
||||||
@ -19,4 +19,13 @@
|
|||||||
{"Key":"\\"}
|
{"Key":"\\"}
|
||||||
{"Key":"0"}
|
{"Key":"0"}
|
||||||
{"Key":"enter"}
|
{"Key":"enter"}
|
||||||
{"Get":{"state":"aa\ndd\nˇcc","mode":"Normal"}}
|
{"Get":{"state":"aa\ndd\ndd\nˇcc","mode":"Normal"}}
|
||||||
|
{"Key":"k"}
|
||||||
|
{"Key":":"}
|
||||||
|
{"Key":"s"}
|
||||||
|
{"Key":"/"}
|
||||||
|
{"Key":"dd"}
|
||||||
|
{"Key":"/"}
|
||||||
|
{"Key":"ee"}
|
||||||
|
{"Key":"enter"}
|
||||||
|
{"Get":{"state":"aa\ndd\nˇee\ncc", "mode":"Normal"}}
|
Loading…
Reference in New Issue
Block a user