Show buffer_search on vim::MoveToNextMatch (#11836)

This changes the vim::MoveToNextMatch event callback to open the
buffer_search toolbar. This fixes an issue where highlights would appear
which were only cancellable by opening then closing the toolbar.

Release Notes:

- the buffer search toolbar now opens on vim::MoveToNextMatch fixing the
issue where highlights were not cancellable

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Gus 2024-05-14 19:57:58 -07:00 committed by GitHub
parent 1a358e203e
commit 3cbac27117
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 0 deletions

View File

@ -840,6 +840,10 @@ impl BufferSearchBar {
}
}
pub fn has_active_match(&self) -> bool {
self.active_match_index.is_some()
}
fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
let mut active_item_matches = None;
for (searchable_item, matches) in self.searchable_items_with_matches.drain() {

View File

@ -218,6 +218,9 @@ pub fn move_to_match_internal(
pane.update(cx, |pane, cx| {
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
search_bar.update(cx, |search_bar, cx| {
if !search_bar.has_active_match() || !search_bar.show(cx) {
return;
}
search_bar.select_match(direction, count, cx);
let new_selections = vim.editor_selections(cx);

View File

@ -516,6 +516,9 @@ pub fn select_match(
pane.update(cx, |pane, cx| {
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
search_bar.update(cx, |search_bar, cx| {
if !search_bar.has_active_match() || !search_bar.show(cx) {
return;
}
// without update_match_index there is a bug when the cursor is before the first match
search_bar.update_match_index(cx);
search_bar.select_match(direction.opposite(), 1, cx);