Touchups to registrar API

This commit is contained in:
Piotr Osiewicz 2024-01-04 15:51:56 +01:00
parent f70eddc988
commit 5ad125a9e9
4 changed files with 32 additions and 57 deletions

1
Cargo.lock generated
View file

@ -2486,7 +2486,6 @@ dependencies = [
"postage", "postage",
"project", "project",
"regex", "regex",
"search",
"serde", "serde",
"serde_derive", "serde_derive",
"settings", "settings",

View file

@ -18,7 +18,6 @@ gpui = { path = "../gpui" }
language = { path = "../language" } language = { path = "../language" }
menu = { path = "../menu" } menu = { path = "../menu" }
project = { path = "../project" } project = { path = "../project" }
search = { path = "../search" }
settings = { path = "../settings" } settings = { path = "../settings" }
theme = { path = "../theme" } theme = { path = "../theme" }
ui = { path = "../ui" } ui = { path = "../ui" }

View file

@ -431,57 +431,42 @@ pub trait SearchActionsRegistrar {
} }
impl BufferSearchBar { impl BufferSearchBar {
pub fn register_inner( pub fn register_inner(registrar: &mut impl SearchActionsRegistrar) {
registrar: &mut impl SearchActionsRegistrar, registrar.register_handler(|this, action: &ToggleCaseSensitive, cx| {
supported_options: &workspace::searchable::SearchOptions, if this.supported_options().case {
) { this.toggle_case_sensitive(action, cx);
// supported_options controls whether the action is registered in the first place, }
// but we still perform dynamic checks as e.g. if a view (like Workspace) uses SearchableItemHandle, they cannot know in advance });
// whether a given option is supported.
if supported_options.case {
registrar.register_handler(|this, action: &ToggleCaseSensitive, cx| {
if this.supported_options().case {
this.toggle_case_sensitive(action, cx);
}
});
}
if supported_options.word {
registrar.register_handler(|this, action: &ToggleWholeWord, cx| {
if this.supported_options().word {
this.toggle_whole_word(action, cx);
}
});
}
if supported_options.replacement { registrar.register_handler(|this, action: &ToggleWholeWord, cx| {
registrar.register_handler(|this, action: &ToggleReplace, cx| { if this.supported_options().word {
if this.supported_options().replacement { this.toggle_whole_word(action, cx);
this.toggle_replace(action, cx); }
} });
});
}
if supported_options.regex { registrar.register_handler(|this, action: &ToggleReplace, cx| {
registrar.register_handler(|this, _: &ActivateRegexMode, cx| { if this.supported_options().replacement {
if this.supported_options().regex { this.toggle_replace(action, cx);
this.activate_search_mode(SearchMode::Regex, cx); }
} });
});
} registrar.register_handler(|this, _: &ActivateRegexMode, cx| {
if this.supported_options().regex {
this.activate_search_mode(SearchMode::Regex, cx);
}
});
registrar.register_handler(|this, _: &ActivateTextMode, cx| { registrar.register_handler(|this, _: &ActivateTextMode, cx| {
this.activate_search_mode(SearchMode::Text, cx); this.activate_search_mode(SearchMode::Text, cx);
}); });
if supported_options.regex { registrar.register_handler(|this, action: &CycleMode, cx| {
registrar.register_handler(|this, action: &CycleMode, cx| { if this.supported_options().regex {
if this.supported_options().regex { // If regex is not supported then search has just one mode (text) - in that case there's no point in supporting
// If regex is not supported then search has just one mode (text) - in that case there's no point in supporting // cycling.
// cycling. this.cycle_mode(action, cx)
this.cycle_mode(action, cx) }
} });
});
}
registrar.register_handler(|this, action: &SelectNextMatch, cx| { registrar.register_handler(|this, action: &SelectNextMatch, cx| {
this.select_next_match(action, cx); this.select_next_match(action, cx);
@ -500,6 +485,7 @@ impl BufferSearchBar {
cx.propagate(); cx.propagate();
}); });
registrar.register_handler(|this, deploy, cx| { registrar.register_handler(|this, deploy, cx| {
dbg!("Deploying?");
this.deploy(deploy, cx); this.deploy(deploy, cx);
}) })
} }
@ -522,15 +508,7 @@ impl BufferSearchBar {
}); });
} }
} }
Self::register_inner( Self::register_inner(workspace);
workspace,
&workspace::searchable::SearchOptions {
case: true,
word: true,
regex: true,
replacement: true,
},
);
} }
pub fn new(cx: &mut ViewContext<Self>) -> Self { pub fn new(cx: &mut ViewContext<Self>) -> Self {
let query_editor = cx.new_view(|cx| Editor::single_line(cx)); let query_editor = cx.new_view(|cx| Editor::single_line(cx));

View file

@ -19,7 +19,6 @@ use workspace::{
dock::{DockPosition, Panel, PanelEvent}, dock::{DockPosition, Panel, PanelEvent},
item::Item, item::Item,
pane, pane,
searchable::SearchableItem,
ui::Icon, ui::Icon,
Pane, Workspace, Pane, Workspace,
}; };
@ -359,7 +358,7 @@ impl Render for TerminalPanel {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let div = div(); let div = div();
let mut registrar = ActionsRegistrar { div: Some(div), cx }; let mut registrar = ActionsRegistrar { div: Some(div), cx };
BufferSearchBar::register_inner(&mut registrar, &TerminalView::supported_options()); BufferSearchBar::register_inner(&mut registrar);
registrar.div.unwrap().size_full().child(self.pane.clone()) registrar.div.unwrap().size_full().child(self.pane.clone())
} }
} }