Make buffer search aware of search direction (#24974)
This solves a couple of issues with Vim search by making the search buffer and `SearchableItem` aware of the direction of the search. If `SearchOptions::BACKWARDS` is set, all operations will be reversed. By making `SearchableItem` aware of the direction, the correct active match can be selected when searching backward. Fixes #22506. This PR does not fix the last problem in that issue, but that one is also tracked in #8049. Release Notes: - Fixes incorrect behavior of backward search in Vim mode
This commit is contained in:
parent
ed13e05855
commit
229e853874
9 changed files with 80 additions and 25 deletions
|
@ -150,6 +150,7 @@ pub trait SearchableItem: Item + EventEmitter<SearchEvent> {
|
|||
) -> Task<Vec<Self::Match>>;
|
||||
fn active_match_index(
|
||||
&mut self,
|
||||
direction: Direction,
|
||||
matches: &[Self::Match],
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
|
@ -208,6 +209,7 @@ pub trait SearchableItemHandle: ItemHandle {
|
|||
) -> Task<AnyVec<dyn Send>>;
|
||||
fn active_match_index(
|
||||
&self,
|
||||
direction: Direction,
|
||||
matches: &AnyVec<dyn Send>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
|
@ -315,13 +317,14 @@ impl<T: SearchableItem> SearchableItemHandle for Entity<T> {
|
|||
}
|
||||
fn active_match_index(
|
||||
&self,
|
||||
direction: Direction,
|
||||
matches: &AnyVec<dyn Send>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Option<usize> {
|
||||
let matches = matches.downcast_ref()?;
|
||||
self.update(cx, |this, cx| {
|
||||
this.active_match_index(matches.as_slice(), window, cx)
|
||||
this.active_match_index(direction, matches.as_slice(), window, cx)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue