buffer: use shared func for nav button rendering

This commit is contained in:
Piotr Osiewicz
2023-08-09 01:29:22 +02:00
parent e2b8e6ce63
commit f978acdd34
2 changed files with 28 additions and 16 deletions
+16 -3
View File
@@ -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<Self>| {
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)
+12 -13
View File
@@ -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<ProjectSearchBar>| {
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<Self>| {
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(