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:
parent
2a9d4599cd
commit
65f64aa513
4 changed files with 114 additions and 65 deletions
|
@ -1,9 +1,9 @@
|
|||
use crate::{
|
||||
BufferSearchBar, FocusSearch, NextHistoryQuery, PreviousHistoryQuery, ReplaceAll, ReplaceNext,
|
||||
SearchOption, SearchOptions, SelectNextMatch, SelectPreviousMatch, ToggleCaseSensitive,
|
||||
ToggleIncludeIgnored, ToggleRegex, ToggleReplace, ToggleWholeWord,
|
||||
SearchOption, SearchOptions, SearchSource, SelectNextMatch, SelectPreviousMatch,
|
||||
ToggleCaseSensitive, ToggleIncludeIgnored, ToggleRegex, ToggleReplace, ToggleWholeWord,
|
||||
buffer_search::Deploy,
|
||||
search_bar::{input_base_styles, render_action_button, render_text_input},
|
||||
search_bar::{ActionButtonState, input_base_styles, render_action_button, render_text_input},
|
||||
};
|
||||
use anyhow::Context as _;
|
||||
use collections::HashMap;
|
||||
|
@ -1665,7 +1665,7 @@ impl ProjectSearchBar {
|
|||
});
|
||||
}
|
||||
|
||||
fn toggle_search_option(
|
||||
pub(crate) fn toggle_search_option(
|
||||
&mut self,
|
||||
option: SearchOptions,
|
||||
window: &mut Window,
|
||||
|
@ -1962,17 +1962,21 @@ impl Render for ProjectSearchBar {
|
|||
.child(
|
||||
h_flex()
|
||||
.gap_1()
|
||||
.child(
|
||||
SearchOption::CaseSensitive
|
||||
.as_button(search.search_options, focus_handle.clone()),
|
||||
)
|
||||
.child(
|
||||
SearchOption::WholeWord
|
||||
.as_button(search.search_options, focus_handle.clone()),
|
||||
)
|
||||
.child(
|
||||
SearchOption::Regex.as_button(search.search_options, focus_handle.clone()),
|
||||
),
|
||||
.child(SearchOption::CaseSensitive.as_button(
|
||||
search.search_options,
|
||||
SearchSource::Project(cx),
|
||||
focus_handle.clone(),
|
||||
))
|
||||
.child(SearchOption::WholeWord.as_button(
|
||||
search.search_options,
|
||||
SearchSource::Project(cx),
|
||||
focus_handle.clone(),
|
||||
))
|
||||
.child(SearchOption::Regex.as_button(
|
||||
search.search_options,
|
||||
SearchSource::Project(cx),
|
||||
focus_handle.clone(),
|
||||
)),
|
||||
);
|
||||
|
||||
let query_focus = search.query_editor.focus_handle(cx);
|
||||
|
@ -1985,7 +1989,10 @@ impl Render for ProjectSearchBar {
|
|||
.child(render_action_button(
|
||||
"project-search-nav-button",
|
||||
IconName::ChevronLeft,
|
||||
search.active_match_index.is_some(),
|
||||
search
|
||||
.active_match_index
|
||||
.is_none()
|
||||
.then_some(ActionButtonState::Disabled),
|
||||
"Select Previous Match",
|
||||
&SelectPreviousMatch,
|
||||
query_focus.clone(),
|
||||
|
@ -1993,7 +2000,10 @@ impl Render for ProjectSearchBar {
|
|||
.child(render_action_button(
|
||||
"project-search-nav-button",
|
||||
IconName::ChevronRight,
|
||||
search.active_match_index.is_some(),
|
||||
search
|
||||
.active_match_index
|
||||
.is_none()
|
||||
.then_some(ActionButtonState::Disabled),
|
||||
"Select Next Match",
|
||||
&SelectNextMatch,
|
||||
query_focus,
|
||||
|
@ -2054,7 +2064,7 @@ impl Render for ProjectSearchBar {
|
|||
self.active_project_search
|
||||
.as_ref()
|
||||
.map(|search| search.read(cx).replace_enabled)
|
||||
.unwrap_or_default(),
|
||||
.and_then(|enabled| enabled.then_some(ActionButtonState::Toggled)),
|
||||
"Toggle Replace",
|
||||
&ToggleReplace,
|
||||
focus_handle.clone(),
|
||||
|
@ -2079,7 +2089,7 @@ impl Render for ProjectSearchBar {
|
|||
.child(render_action_button(
|
||||
"project-search-replace-button",
|
||||
IconName::ReplaceNext,
|
||||
true,
|
||||
Default::default(),
|
||||
"Replace Next Match",
|
||||
&ReplaceNext,
|
||||
focus_handle.clone(),
|
||||
|
@ -2087,7 +2097,7 @@ impl Render for ProjectSearchBar {
|
|||
.child(render_action_button(
|
||||
"project-search-replace-button",
|
||||
IconName::ReplaceAll,
|
||||
true,
|
||||
Default::default(),
|
||||
"Replace All Matches",
|
||||
&ReplaceAll,
|
||||
focus_handle,
|
||||
|
@ -2129,10 +2139,11 @@ impl Render for ProjectSearchBar {
|
|||
this.toggle_opened_only(window, cx);
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
SearchOption::IncludeIgnored
|
||||
.as_button(search.search_options, focus_handle.clone()),
|
||||
);
|
||||
.child(SearchOption::IncludeIgnored.as_button(
|
||||
search.search_options,
|
||||
SearchSource::Project(cx),
|
||||
focus_handle.clone(),
|
||||
));
|
||||
h_flex()
|
||||
.w_full()
|
||||
.gap_2()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue