From f978acdd34085bb0238c6e3307edd1651f3808b8 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Wed, 9 Aug 2023 01:29:22 +0200 Subject: [PATCH] buffer: use shared func for nav button rendering --- crates/search/src/buffer_search.rs | 19 ++++++++++++++++--- crates/search/src/project_search.rs | 25 ++++++++++++------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index d7add915998f4d4995eefb6f26ddb6c93d33d3a3..25149012c7d5a9f9966bc30aaf0490353775e6b1 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -1,5 +1,7 @@ use crate::{ - history::SearchHistory, mode::SearchMode, search_bar::render_search_mode_button, + history::SearchHistory, + mode::SearchMode, + search_bar::{render_nav_button, render_search_mode_button}, NextHistoryQuery, PreviousHistoryQuery, SearchOptions, SelectAllMatches, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleWholeWord, }; @@ -201,6 +203,17 @@ impl View for BufferSearchBar { .aligned(), ) }); + let nav_button_for_direction = |label, direction, cx: &mut ViewContext| { + render_nav_button( + label, + direction, + move |_, this, cx| match direction { + Direction::Prev => this.select_prev_match(&Default::default(), cx), + Direction::Next => this.select_next_match(&Default::default(), cx), + }, + cx, + ) + }; Flex::row() .with_child( Flex::column() @@ -209,8 +222,8 @@ impl View for BufferSearchBar { .align_children_center() .with_child( Flex::row() - .with_child(self.render_nav_button("<", Direction::Prev, cx)) - .with_child(self.render_nav_button(">", Direction::Next, cx)) + .with_child(nav_button_for_direction("<", Direction::Prev, cx)) + .with_child(nav_button_for_direction(">", Direction::Next, cx)) .aligned(), ) .with_children(match_count) diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index 611fd028466ff671a1651792ebd04f08594409d6..b607848e214a8154489fdd86223c1b03be9e56f9 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -1550,19 +1550,18 @@ impl View for ProjectSearchBar { }; let semantic_index = SemanticIndex::enabled(cx) .then(|| search_button_for_mode(SearchMode::Semantic, cx)); - let nav_button_for_direction = - |label, direction, cx: &mut ViewContext| { - render_nav_button( - label, - direction, - move |_, this, cx| { - if let Some(search) = this.active_project_search.as_ref() { - search.update(cx, |search, cx| search.select_match(direction, cx)); - } - }, - cx, - ) - }; + let nav_button_for_direction = |label, direction, cx: &mut ViewContext| { + render_nav_button( + label, + direction, + move |_, this, cx| { + if let Some(search) = this.active_project_search.as_ref() { + search.update(cx, |search, cx| search.select_match(direction, cx)); + } + }, + cx, + ) + }; Flex::row() .with_child(