mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-27 12:54:42 +00:00
Touchups to registrar API
This commit is contained in:
parent
f70eddc988
commit
5ad125a9e9
4 changed files with 32 additions and 57 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2486,7 +2486,6 @@ dependencies = [
|
|||
"postage",
|
||||
"project",
|
||||
"regex",
|
||||
"search",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"settings",
|
||||
|
|
|
@ -18,7 +18,6 @@ gpui = { path = "../gpui" }
|
|||
language = { path = "../language" }
|
||||
menu = { path = "../menu" }
|
||||
project = { path = "../project" }
|
||||
search = { path = "../search" }
|
||||
settings = { path = "../settings" }
|
||||
theme = { path = "../theme" }
|
||||
ui = { path = "../ui" }
|
||||
|
|
|
@ -431,57 +431,42 @@ pub trait SearchActionsRegistrar {
|
|||
}
|
||||
|
||||
impl BufferSearchBar {
|
||||
pub fn register_inner(
|
||||
registrar: &mut impl SearchActionsRegistrar,
|
||||
supported_options: &workspace::searchable::SearchOptions,
|
||||
) {
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
pub fn register_inner(registrar: &mut impl SearchActionsRegistrar) {
|
||||
registrar.register_handler(|this, action: &ToggleCaseSensitive, cx| {
|
||||
if this.supported_options().case {
|
||||
this.toggle_case_sensitive(action, cx);
|
||||
}
|
||||
});
|
||||
|
||||
if supported_options.replacement {
|
||||
registrar.register_handler(|this, action: &ToggleReplace, cx| {
|
||||
if this.supported_options().replacement {
|
||||
this.toggle_replace(action, cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
registrar.register_handler(|this, action: &ToggleWholeWord, cx| {
|
||||
if this.supported_options().word {
|
||||
this.toggle_whole_word(action, cx);
|
||||
}
|
||||
});
|
||||
|
||||
if supported_options.regex {
|
||||
registrar.register_handler(|this, _: &ActivateRegexMode, cx| {
|
||||
if this.supported_options().regex {
|
||||
this.activate_search_mode(SearchMode::Regex, cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
registrar.register_handler(|this, action: &ToggleReplace, cx| {
|
||||
if this.supported_options().replacement {
|
||||
this.toggle_replace(action, 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| {
|
||||
this.activate_search_mode(SearchMode::Text, cx);
|
||||
});
|
||||
|
||||
if supported_options.regex {
|
||||
registrar.register_handler(|this, action: &CycleMode, cx| {
|
||||
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
|
||||
// cycling.
|
||||
this.cycle_mode(action, cx)
|
||||
}
|
||||
});
|
||||
}
|
||||
registrar.register_handler(|this, action: &CycleMode, cx| {
|
||||
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
|
||||
// cycling.
|
||||
this.cycle_mode(action, cx)
|
||||
}
|
||||
});
|
||||
|
||||
registrar.register_handler(|this, action: &SelectNextMatch, cx| {
|
||||
this.select_next_match(action, cx);
|
||||
|
@ -500,6 +485,7 @@ impl BufferSearchBar {
|
|||
cx.propagate();
|
||||
});
|
||||
registrar.register_handler(|this, deploy, cx| {
|
||||
dbg!("Deploying?");
|
||||
this.deploy(deploy, cx);
|
||||
})
|
||||
}
|
||||
|
@ -522,15 +508,7 @@ impl BufferSearchBar {
|
|||
});
|
||||
}
|
||||
}
|
||||
Self::register_inner(
|
||||
workspace,
|
||||
&workspace::searchable::SearchOptions {
|
||||
case: true,
|
||||
word: true,
|
||||
regex: true,
|
||||
replacement: true,
|
||||
},
|
||||
);
|
||||
Self::register_inner(workspace);
|
||||
}
|
||||
pub fn new(cx: &mut ViewContext<Self>) -> Self {
|
||||
let query_editor = cx.new_view(|cx| Editor::single_line(cx));
|
||||
|
|
|
@ -19,7 +19,6 @@ use workspace::{
|
|||
dock::{DockPosition, Panel, PanelEvent},
|
||||
item::Item,
|
||||
pane,
|
||||
searchable::SearchableItem,
|
||||
ui::Icon,
|
||||
Pane, Workspace,
|
||||
};
|
||||
|
@ -359,7 +358,7 @@ impl Render for TerminalPanel {
|
|||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
let div = div();
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue