search: Fix recently introduced issues with the search bars (#36271)
Follow-up to https://github.com/zed-industries/zed/pull/36233 The above PR simplified the handling but introduced some bugs: The replace buttons were no longer clickable, some buttons also lost their toggle states, some buttons shared their element id and, lastly, some buttons were clickable but would not trigger the right action. This PR fixes all that. Release Notes: - N/A
This commit is contained in:
@@ -2,9 +2,9 @@ mod registrar;
|
||||
|
||||
use crate::{
|
||||
FocusSearch, NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext, SearchOption,
|
||||
SearchOptions, SelectAllMatches, SelectNextMatch, SelectPreviousMatch, ToggleCaseSensitive,
|
||||
ToggleRegex, ToggleReplace, ToggleSelection, ToggleWholeWord,
|
||||
search_bar::{input_base_styles, render_action_button, render_text_input},
|
||||
SearchOptions, SearchSource, SelectAllMatches, SelectNextMatch, SelectPreviousMatch,
|
||||
ToggleCaseSensitive, ToggleRegex, ToggleReplace, ToggleSelection, ToggleWholeWord,
|
||||
search_bar::{ActionButtonState, input_base_styles, render_action_button, render_text_input},
|
||||
};
|
||||
use any_vec::AnyVec;
|
||||
use anyhow::Context as _;
|
||||
@@ -213,22 +213,25 @@ impl Render for BufferSearchBar {
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.when(case, |div| {
|
||||
div.child(
|
||||
SearchOption::CaseSensitive
|
||||
.as_button(self.search_options, focus_handle.clone()),
|
||||
)
|
||||
div.child(SearchOption::CaseSensitive.as_button(
|
||||
self.search_options,
|
||||
SearchSource::Buffer,
|
||||
focus_handle.clone(),
|
||||
))
|
||||
})
|
||||
.when(word, |div| {
|
||||
div.child(
|
||||
SearchOption::WholeWord
|
||||
.as_button(self.search_options, focus_handle.clone()),
|
||||
)
|
||||
div.child(SearchOption::WholeWord.as_button(
|
||||
self.search_options,
|
||||
SearchSource::Buffer,
|
||||
focus_handle.clone(),
|
||||
))
|
||||
})
|
||||
.when(regex, |div| {
|
||||
div.child(
|
||||
SearchOption::Regex
|
||||
.as_button(self.search_options, focus_handle.clone()),
|
||||
)
|
||||
div.child(SearchOption::Regex.as_button(
|
||||
self.search_options,
|
||||
SearchSource::Buffer,
|
||||
focus_handle.clone(),
|
||||
))
|
||||
}),
|
||||
)
|
||||
});
|
||||
@@ -240,7 +243,7 @@ impl Render for BufferSearchBar {
|
||||
this.child(render_action_button(
|
||||
"buffer-search-bar-toggle",
|
||||
IconName::Replace,
|
||||
self.replace_enabled,
|
||||
self.replace_enabled.then_some(ActionButtonState::Toggled),
|
||||
"Toggle Replace",
|
||||
&ToggleReplace,
|
||||
focus_handle.clone(),
|
||||
@@ -285,7 +288,9 @@ impl Render for BufferSearchBar {
|
||||
.child(render_action_button(
|
||||
"buffer-search-nav-button",
|
||||
ui::IconName::ChevronLeft,
|
||||
self.active_match_index.is_some(),
|
||||
self.active_match_index
|
||||
.is_none()
|
||||
.then_some(ActionButtonState::Disabled),
|
||||
"Select Previous Match",
|
||||
&SelectPreviousMatch,
|
||||
query_focus.clone(),
|
||||
@@ -293,7 +298,9 @@ impl Render for BufferSearchBar {
|
||||
.child(render_action_button(
|
||||
"buffer-search-nav-button",
|
||||
ui::IconName::ChevronRight,
|
||||
self.active_match_index.is_some(),
|
||||
self.active_match_index
|
||||
.is_none()
|
||||
.then_some(ActionButtonState::Disabled),
|
||||
"Select Next Match",
|
||||
&SelectNextMatch,
|
||||
query_focus.clone(),
|
||||
@@ -313,7 +320,7 @@ impl Render for BufferSearchBar {
|
||||
el.child(render_action_button(
|
||||
"buffer-search-nav-button",
|
||||
IconName::SelectAll,
|
||||
true,
|
||||
Default::default(),
|
||||
"Select All Matches",
|
||||
&SelectAllMatches,
|
||||
query_focus,
|
||||
@@ -324,7 +331,7 @@ impl Render for BufferSearchBar {
|
||||
el.child(render_action_button(
|
||||
"buffer-search",
|
||||
IconName::Close,
|
||||
true,
|
||||
Default::default(),
|
||||
"Close Search Bar",
|
||||
&Dismiss,
|
||||
focus_handle.clone(),
|
||||
@@ -352,7 +359,7 @@ impl Render for BufferSearchBar {
|
||||
.child(render_action_button(
|
||||
"buffer-search-replace-button",
|
||||
IconName::ReplaceNext,
|
||||
true,
|
||||
Default::default(),
|
||||
"Replace Next Match",
|
||||
&ReplaceNext,
|
||||
focus_handle.clone(),
|
||||
@@ -360,7 +367,7 @@ impl Render for BufferSearchBar {
|
||||
.child(render_action_button(
|
||||
"buffer-search-replace-button",
|
||||
IconName::ReplaceAll,
|
||||
true,
|
||||
Default::default(),
|
||||
"Replace All Matches",
|
||||
&ReplaceAll,
|
||||
focus_handle,
|
||||
@@ -394,7 +401,7 @@ impl Render for BufferSearchBar {
|
||||
div.child(h_flex().absolute().right_0().child(render_action_button(
|
||||
"buffer-search",
|
||||
IconName::Close,
|
||||
true,
|
||||
Default::default(),
|
||||
"Close Search Bar",
|
||||
&Dismiss,
|
||||
focus_handle.clone(),
|
||||
|
||||
Reference in New Issue
Block a user