Add new actions editor::FindNextMatch and editor::FindPreviousMatch (#28559)

Closes #7903

Release Notes:

- Add new actions `editor::FindNextMatch` and
`editor::FindPreviousMatch` that are similar to `editor::SelectNext` and
`editor::SelectPrevious` with `"replace_newest": true`, but jumps to the
first or last selection when there are multiple selections.
This commit is contained in:
João Marcos 2025-04-11 00:43:55 -03:00 committed by GitHub
parent c35238bd72
commit ad39d3226f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 62 additions and 2 deletions

View file

@ -12020,6 +12020,54 @@ impl Editor {
Ok(())
}
pub fn find_next_match(
&mut self,
_: &FindNextMatch,
window: &mut Window,
cx: &mut Context<Self>,
) -> Result<()> {
let selections = self.selections.disjoint_anchors();
match selections.first() {
Some(first) if selections.len() >= 2 => {
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.select_ranges([first.range()]);
});
}
_ => self.select_next(
&SelectNext {
replace_newest: true,
},
window,
cx,
)?,
}
Ok(())
}
pub fn find_previous_match(
&mut self,
_: &FindPreviousMatch,
window: &mut Window,
cx: &mut Context<Self>,
) -> Result<()> {
let selections = self.selections.disjoint_anchors();
match selections.last() {
Some(last) if selections.len() >= 2 => {
self.change_selections(Some(Autoscroll::fit()), window, cx, |s| {
s.select_ranges([last.range()]);
});
}
_ => self.select_previous(
&SelectPrevious {
replace_newest: true,
},
window,
cx,
)?,
}
Ok(())
}
pub fn toggle_comments(
&mut self,
action: &ToggleComments,