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:
Horam Zarri 2024-09-04 22:56:32 +03:30 committed by GitHub
parent 65bc1ea7c8
commit 694c912201
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 25 deletions

View file

@ -656,13 +656,11 @@ pub fn command_interceptor(mut input: &str, cx: &AppContext) -> Option<CommandIn
query.next();
}
if let Some(replacement) = Replacement::parse(query) {
Some(
ReplaceCommand {
replacement,
range: range.clone(),
}
.boxed_clone(),
)
let range = range.clone().unwrap_or(CommandRange {
start: Position::CurrentLine { offset: 0 },
end: None,
});
Some(ReplaceCommand { replacement, range }.boxed_clone())
} else {
None
}
@ -789,11 +787,13 @@ mod test {
cx.set_shared_state(indoc! {"
ˇa
b
b
c"})
.await;
cx.simulate_shared_keystrokes(": % s / b / d enter").await;
cx.shared_state().await.assert_eq(indoc! {"
a
d
ˇd
c"});
cx.simulate_shared_keystrokes(": % s : . : \\ 0 \\ 0 enter")
@ -801,7 +801,14 @@ mod test {
cx.shared_state().await.assert_eq(indoc! {"
aa
dd
dd
ˇcc"});
cx.simulate_shared_keystrokes("k : s / dd / ee enter").await;
cx.shared_state().await.assert_eq(indoc! {"
aa
dd
ˇee
cc"});
}
#[gpui::test]