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

@ -42,7 +42,7 @@ pub struct FindCommand {
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct ReplaceCommand {
pub(crate) range: Option<CommandRange>,
pub(crate) range: CommandRange,
pub(crate) replacement: Replacement,
}
@ -338,20 +338,18 @@ impl Vim {
else {
return;
};
if let Some(range) = &action.range {
if let Some(result) = self.update_editor(cx, |vim, editor, cx| {
let range = range.buffer_range(vim, editor, cx)?;
let snapshot = &editor.snapshot(cx).buffer_snapshot;
let end_point = Point::new(range.end.0, snapshot.line_len(range.end));
let range = snapshot.anchor_before(Point::new(range.start.0, 0))
..snapshot.anchor_after(end_point);
editor.set_search_within_ranges(&[range], cx);
anyhow::Ok(())
}) {
workspace.update(cx, |workspace, cx| {
result.notify_err(workspace, cx);
})
}
if let Some(result) = self.update_editor(cx, |vim, editor, cx| {
let range = action.range.buffer_range(vim, editor, cx)?;
let snapshot = &editor.snapshot(cx).buffer_snapshot;
let end_point = Point::new(range.end.0, snapshot.line_len(range.end));
let range = snapshot.anchor_before(Point::new(range.start.0, 0))
..snapshot.anchor_after(end_point);
editor.set_search_within_ranges(&[range], cx);
anyhow::Ok(())
}) {
workspace.update(cx, |workspace, cx| {
result.notify_err(workspace, cx);
})
}
let vim = cx.view().clone();
pane.update(cx, |pane, cx| {