Rename "find" to "search"

Search is both a verb and a noun, which makes it more natural to use in situations where we need to name a thing rather than a process.
This commit is contained in:
Nathan Sobo 2022-02-27 08:15:38 -07:00
parent dd6f8d20a3
commit ec317159d7
9 changed files with 197 additions and 197 deletions

36
Cargo.lock generated
View file

@ -1772,23 +1772,6 @@ dependencies = [
"workspace",
]
[[package]]
name = "find"
version = "0.1.0"
dependencies = [
"anyhow",
"collections",
"editor",
"gpui",
"language",
"postage",
"project",
"theme",
"unindent",
"util",
"workspace",
]
[[package]]
name = "fixedbitset"
version = "0.2.0"
@ -4180,6 +4163,23 @@ version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
[[package]]
name = "search"
version = "0.1.0"
dependencies = [
"anyhow",
"collections",
"editor",
"gpui",
"language",
"postage",
"project",
"theme",
"unindent",
"util",
"workspace",
]
[[package]]
name = "semver"
version = "0.9.0"
@ -5860,7 +5860,6 @@ dependencies = [
"editor",
"env_logger",
"file_finder",
"find",
"fsevent",
"futures",
"fuzzy",
@ -5889,6 +5888,7 @@ dependencies = [
"rpc",
"rsa",
"rust-embed",
"search",
"serde",
"serde_json",
"serde_path_to_error",

View file

@ -1,10 +1,10 @@
[package]
name = "find"
name = "search"
version = "0.1.0"
edition = "2021"
[lib]
path = "src/find.rs"
path = "src/search.rs"
[dependencies]
collections = { path = "../collections" }

View file

@ -30,22 +30,22 @@ pub fn init(cx: &mut MutableAppContext) {
cx.add_bindings([
Binding::new("cmd-f", Deploy(true), Some("Editor && mode == full")),
Binding::new("cmd-e", Deploy(false), Some("Editor && mode == full")),
Binding::new("escape", Dismiss, Some("FindBar")),
Binding::new("cmd-f", FocusEditor, Some("FindBar")),
Binding::new("enter", GoToMatch(Direction::Next), Some("FindBar")),
Binding::new("shift-enter", GoToMatch(Direction::Prev), Some("FindBar")),
Binding::new("escape", Dismiss, Some("SearchBar")),
Binding::new("cmd-f", FocusEditor, Some("SearchBar")),
Binding::new("enter", GoToMatch(Direction::Next), Some("SearchBar")),
Binding::new("shift-enter", GoToMatch(Direction::Prev), Some("SearchBar")),
Binding::new("cmd-g", GoToMatch(Direction::Next), Some("Pane")),
Binding::new("cmd-shift-G", GoToMatch(Direction::Prev), Some("Pane")),
]);
cx.add_action(FindBar::deploy);
cx.add_action(FindBar::dismiss);
cx.add_action(FindBar::focus_editor);
cx.add_action(FindBar::toggle_search_option);
cx.add_action(FindBar::go_to_match);
cx.add_action(FindBar::go_to_match_on_pane);
cx.add_action(SearchBar::deploy);
cx.add_action(SearchBar::dismiss);
cx.add_action(SearchBar::focus_editor);
cx.add_action(SearchBar::toggle_search_option);
cx.add_action(SearchBar::go_to_match);
cx.add_action(SearchBar::go_to_match_on_pane);
}
struct FindBar {
struct SearchBar {
settings: watch::Receiver<Settings>,
query_editor: ViewHandle<Editor>,
active_editor: Option<ViewHandle<Editor>>,
@ -60,13 +60,13 @@ struct FindBar {
dismissed: bool,
}
impl Entity for FindBar {
impl Entity for SearchBar {
type Event = ();
}
impl View for FindBar {
impl View for SearchBar {
fn ui_name() -> &'static str {
"FindBar"
"SearchBar"
}
fn on_focus(&mut self, cx: &mut ViewContext<Self>) {
@ -76,9 +76,9 @@ impl View for FindBar {
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
let theme = &self.settings.borrow().theme;
let editor_container = if self.query_contains_error {
theme.find.invalid_editor
theme.search.invalid_editor
} else {
theme.find.editor.input.container
theme.search.editor.input.container
};
Flex::row()
.with_child(
@ -87,7 +87,7 @@ impl View for FindBar {
.with_style(editor_container)
.aligned()
.constrained()
.with_max_width(theme.find.editor.max_width)
.with_max_width(theme.search.editor.max_width)
.boxed(),
)
.with_child(
@ -96,7 +96,7 @@ impl View for FindBar {
.with_child(self.render_search_option("Word", SearchOption::WholeWord, cx))
.with_child(self.render_search_option("Regex", SearchOption::Regex, cx))
.contained()
.with_style(theme.find.option_button_group)
.with_style(theme.search.option_button_group)
.aligned()
.boxed(),
)
@ -116,22 +116,22 @@ impl View for FindBar {
};
Some(
Label::new(message, theme.find.match_index.text.clone())
Label::new(message, theme.search.match_index.text.clone())
.contained()
.with_style(theme.find.match_index.container)
.with_style(theme.search.match_index.container)
.aligned()
.boxed(),
)
}))
.contained()
.with_style(theme.find.container)
.with_style(theme.search.container)
.constrained()
.with_height(theme.workspace.toolbar.height)
.named("find bar")
.named("search bar")
}
}
impl Toolbar for FindBar {
impl Toolbar for SearchBar {
fn active_item_changed(
&mut self,
item: Option<Box<dyn ItemViewHandle>>,
@ -163,13 +163,13 @@ impl Toolbar for FindBar {
}
}
impl FindBar {
impl SearchBar {
fn new(settings: watch::Receiver<Settings>, cx: &mut ViewContext<Self>) -> Self {
let query_editor = cx.add_view(|cx| {
Editor::auto_height(
2,
settings.clone(),
Some(|theme| theme.find.editor.input.clone()),
Some(|theme| theme.search.editor.input.clone()),
cx,
)
});
@ -207,7 +207,7 @@ impl FindBar {
search_option: SearchOption,
cx: &mut RenderContext<Self>,
) -> ElementBox {
let theme = &self.settings.borrow().theme.find;
let theme = &self.settings.borrow().theme.search;
let is_active = self.is_search_option_enabled(search_option);
MouseEventHandler::new::<Self, _, _>(search_option as usize, cx, |state, _| {
let style = match (is_active, state.hovered) {
@ -232,7 +232,7 @@ impl FindBar {
direction: Direction,
cx: &mut RenderContext<Self>,
) -> ElementBox {
let theme = &self.settings.borrow().theme.find;
let theme = &self.settings.borrow().theme.search;
enum NavButton {}
MouseEventHandler::new::<NavButton, _, _>(direction as usize, cx, |state, _| {
let style = if state.hovered {
@ -253,13 +253,13 @@ impl FindBar {
fn deploy(workspace: &mut Workspace, Deploy(focus): &Deploy, cx: &mut ViewContext<Workspace>) {
let settings = workspace.settings();
workspace.active_pane().update(cx, |pane, cx| {
pane.show_toolbar(cx, |cx| FindBar::new(settings, cx));
pane.show_toolbar(cx, |cx| SearchBar::new(settings, cx));
if let Some(find_bar) = pane
if let Some(search_bar) = pane
.active_toolbar()
.and_then(|toolbar| toolbar.downcast::<Self>())
{
find_bar.update(cx, |find_bar, _| find_bar.dismissed = false);
search_bar.update(cx, |search_bar, _| search_bar.dismissed = false);
let editor = pane.active_item().unwrap().act_as::<Editor>(cx).unwrap();
let display_map = editor
.update(cx, |editor, cx| editor.snapshot(cx))
@ -286,15 +286,15 @@ impl FindBar {
}
if !text.is_empty() {
find_bar.update(cx, |find_bar, cx| find_bar.set_query(&text, cx));
search_bar.update(cx, |search_bar, cx| search_bar.set_query(&text, cx));
}
if *focus {
let query_editor = find_bar.read(cx).query_editor.clone();
let query_editor = search_bar.read(cx).query_editor.clone();
query_editor.update(cx, |query_editor, cx| {
query_editor.select_all(&editor::SelectAll, cx);
});
cx.focus(&find_bar);
cx.focus(&search_bar);
}
} else {
cx.propagate_action();
@ -303,7 +303,7 @@ impl FindBar {
}
fn dismiss(pane: &mut Pane, _: &Dismiss, cx: &mut ViewContext<Pane>) {
if pane.toolbar::<FindBar>().is_some() {
if pane.toolbar::<SearchBar>().is_some() {
pane.dismiss_toolbar(cx);
}
}
@ -381,8 +381,8 @@ impl FindBar {
}
fn go_to_match_on_pane(pane: &mut Pane, action: &GoToMatch, cx: &mut ViewContext<Pane>) {
if let Some(find_bar) = pane.toolbar::<FindBar>() {
find_bar.update(cx, |find_bar, cx| find_bar.go_to_match(action, cx));
if let Some(search_bar) = pane.toolbar::<SearchBar>() {
search_bar.update(cx, |search_bar, cx| search_bar.go_to_match(action, cx));
}
}
@ -494,7 +494,7 @@ impl FindBar {
this.update_match_index(cx);
if !this.dismissed {
editor.update(cx, |editor, cx| {
let theme = &this.settings.borrow().theme.find;
let theme = &this.settings.borrow().theme.search;
if select_closest_match {
if let Some(match_ix) = this.active_match_index {
@ -558,10 +558,10 @@ mod tests {
use unindent::Unindent as _;
#[gpui::test]
async fn test_find_simple(mut cx: TestAppContext) {
async fn test_search_simple(mut cx: TestAppContext) {
let fonts = cx.font_cache();
let mut theme = gpui::fonts::with_font_cache(fonts.clone(), || theme::Theme::default());
theme.find.match_background = Color::red();
theme.search.match_background = Color::red();
let settings = Settings::new("Courier", &fonts, Arc::new(theme)).unwrap();
let settings = watch::channel_with(settings).1;
@ -581,16 +581,16 @@ mod tests {
Editor::for_buffer(buffer.clone(), None, settings.clone(), cx)
});
let find_bar = cx.add_view(Default::default(), |cx| {
let mut find_bar = FindBar::new(settings, cx);
find_bar.active_item_changed(Some(Box::new(editor.clone())), cx);
find_bar
let search_bar = cx.add_view(Default::default(), |cx| {
let mut search_bar = SearchBar::new(settings, cx);
search_bar.active_item_changed(Some(Box::new(editor.clone())), cx);
search_bar
});
// Search for a string that appears with different casing.
// By default, search is case-insensitive.
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.set_query("us", cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.set_query("us", cx);
});
editor.next_notification(&cx).await;
editor.update(&mut cx, |editor, cx| {
@ -610,8 +610,8 @@ mod tests {
});
// Switch to a case sensitive search.
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.toggle_search_option(&ToggleSearchOption(SearchOption::CaseSensitive), cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.toggle_search_option(&ToggleSearchOption(SearchOption::CaseSensitive), cx);
});
editor.next_notification(&cx).await;
editor.update(&mut cx, |editor, cx| {
@ -626,8 +626,8 @@ mod tests {
// Search for a string that appears both as a whole word and
// within other words. By default, all results are found.
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.set_query("or", cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.set_query("or", cx);
});
editor.next_notification(&cx).await;
editor.update(&mut cx, |editor, cx| {
@ -667,8 +667,8 @@ mod tests {
});
// Switch to a whole word search.
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.toggle_search_option(&ToggleSearchOption(SearchOption::WholeWord), cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.toggle_search_option(&ToggleSearchOption(SearchOption::WholeWord), cx);
});
editor.next_notification(&cx).await;
editor.update(&mut cx, |editor, cx| {
@ -694,82 +694,82 @@ mod tests {
editor.update(&mut cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)], cx);
});
find_bar.update(&mut cx, |find_bar, cx| {
assert_eq!(find_bar.active_match_index, Some(0));
find_bar.go_to_match(&GoToMatch(Direction::Next), cx);
search_bar.update(&mut cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(0));
search_bar.go_to_match(&GoToMatch(Direction::Next), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(0));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0));
});
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.go_to_match(&GoToMatch(Direction::Next), cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.go_to_match(&GoToMatch(Direction::Next), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(1));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(1));
});
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.go_to_match(&GoToMatch(Direction::Next), cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.go_to_match(&GoToMatch(Direction::Next), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(2));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(2));
});
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.go_to_match(&GoToMatch(Direction::Next), cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.go_to_match(&GoToMatch(Direction::Next), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(0));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0));
});
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(2));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(2));
});
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(1));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(1));
});
find_bar.update(&mut cx, |find_bar, cx| {
find_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
search_bar.update(&mut cx, |search_bar, cx| {
search_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(0));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0));
});
// Park the cursor in between matches and ensure that going to the previous match selects
@ -777,16 +777,16 @@ mod tests {
editor.update(&mut cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)], cx);
});
find_bar.update(&mut cx, |find_bar, cx| {
assert_eq!(find_bar.active_match_index, Some(1));
find_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
search_bar.update(&mut cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(1));
search_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(0));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0));
});
// Park the cursor in between matches and ensure that going to the next match selects the
@ -794,16 +794,16 @@ mod tests {
editor.update(&mut cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)], cx);
});
find_bar.update(&mut cx, |find_bar, cx| {
assert_eq!(find_bar.active_match_index, Some(1));
find_bar.go_to_match(&GoToMatch(Direction::Next), cx);
search_bar.update(&mut cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(1));
search_bar.go_to_match(&GoToMatch(Direction::Next), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 11)..DisplayPoint::new(3, 13)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(1));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(1));
});
// Park the cursor after the last match and ensure that going to the previous match selects
@ -811,16 +811,16 @@ mod tests {
editor.update(&mut cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(3, 60)..DisplayPoint::new(3, 60)], cx);
});
find_bar.update(&mut cx, |find_bar, cx| {
assert_eq!(find_bar.active_match_index, Some(2));
find_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
search_bar.update(&mut cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(2));
search_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(2));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(2));
});
// Park the cursor after the last match and ensure that going to the next match selects the
@ -828,16 +828,16 @@ mod tests {
editor.update(&mut cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(3, 60)..DisplayPoint::new(3, 60)], cx);
});
find_bar.update(&mut cx, |find_bar, cx| {
assert_eq!(find_bar.active_match_index, Some(2));
find_bar.go_to_match(&GoToMatch(Direction::Next), cx);
search_bar.update(&mut cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(2));
search_bar.go_to_match(&GoToMatch(Direction::Next), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(0));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(0));
});
// Park the cursor before the first match and ensure that going to the previous match
@ -845,16 +845,16 @@ mod tests {
editor.update(&mut cx, |editor, cx| {
editor.select_display_ranges(&[DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0)], cx);
});
find_bar.update(&mut cx, |find_bar, cx| {
assert_eq!(find_bar.active_match_index, Some(0));
find_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
search_bar.update(&mut cx, |search_bar, cx| {
assert_eq!(search_bar.active_match_index, Some(0));
search_bar.go_to_match(&GoToMatch(Direction::Prev), cx);
assert_eq!(
editor.update(cx, |editor, cx| editor.selected_display_ranges(cx)),
[DisplayPoint::new(3, 56)..DisplayPoint::new(3, 58)]
);
});
find_bar.read_with(&cx, |find_bar, _| {
assert_eq!(find_bar.active_match_index, Some(2));
search_bar.read_with(&cx, |search_bar, _| {
assert_eq!(search_bar.active_match_index, Some(2));
});
}
}

View file

@ -23,20 +23,20 @@ action!(ToggleFocus);
pub fn init(cx: &mut MutableAppContext) {
cx.add_bindings([
Binding::new("cmd-shift-F", ToggleFocus, Some("ProjectFindView")),
Binding::new("cmd-f", ToggleFocus, Some("ProjectFindView")),
Binding::new("cmd-shift-F", ToggleFocus, Some("ProjectSearchView")),
Binding::new("cmd-f", ToggleFocus, Some("ProjectSearchView")),
Binding::new("cmd-shift-F", Deploy, Some("Workspace")),
Binding::new("enter", Search, Some("ProjectFindView")),
Binding::new("cmd-enter", SearchInNew, Some("ProjectFindView")),
Binding::new("enter", Search, Some("ProjectSearchView")),
Binding::new("cmd-enter", SearchInNew, Some("ProjectSearchView")),
]);
cx.add_action(ProjectFindView::deploy);
cx.add_action(ProjectFindView::search);
cx.add_action(ProjectFindView::search_in_new);
cx.add_action(ProjectFindView::toggle_search_option);
cx.add_action(ProjectFindView::toggle_focus);
cx.add_action(ProjectSearchView::deploy);
cx.add_action(ProjectSearchView::search);
cx.add_action(ProjectSearchView::search_in_new);
cx.add_action(ProjectSearchView::toggle_search_option);
cx.add_action(ProjectSearchView::toggle_focus);
}
struct ProjectFind {
struct ProjectSearch {
project: ModelHandle<Project>,
excerpts: ModelHandle<MultiBuffer>,
pending_search: Option<Task<Option<()>>>,
@ -44,8 +44,8 @@ struct ProjectFind {
active_query: Option<SearchQuery>,
}
struct ProjectFindView {
model: ModelHandle<ProjectFind>,
struct ProjectSearchView {
model: ModelHandle<ProjectSearch>,
query_editor: ViewHandle<Editor>,
results_editor: ViewHandle<Editor>,
case_sensitive: bool,
@ -55,11 +55,11 @@ struct ProjectFindView {
settings: watch::Receiver<Settings>,
}
impl Entity for ProjectFind {
impl Entity for ProjectSearch {
type Event = ();
}
impl ProjectFind {
impl ProjectSearch {
fn new(project: ModelHandle<Project>, cx: &mut ModelContext<Self>) -> Self {
let replica_id = project.read(cx).replica_id();
Self {
@ -119,8 +119,8 @@ impl ProjectFind {
}
}
impl Item for ProjectFind {
type View = ProjectFindView;
impl Item for ProjectSearch {
type View = ProjectSearchView;
fn build_view(
model: ModelHandle<Self>,
@ -145,7 +145,7 @@ impl Item for ProjectFind {
let query_editor = cx.add_view(|cx| {
let mut editor = Editor::single_line(
settings.clone(),
Some(|theme| theme.find.editor.input.clone()),
Some(|theme| theme.search.editor.input.clone()),
cx,
);
editor.set_text(query_text, cx);
@ -167,7 +167,7 @@ impl Item for ProjectFind {
cx.observe(&model, |this, _, cx| this.model_changed(true, cx))
.detach();
ProjectFindView {
ProjectSearchView {
model,
query_editor,
results_editor,
@ -188,13 +188,13 @@ enum ViewEvent {
UpdateTab,
}
impl Entity for ProjectFindView {
impl Entity for ProjectSearchView {
type Event = ViewEvent;
}
impl View for ProjectFindView {
impl View for ProjectSearchView {
fn ui_name() -> &'static str {
"ProjectFindView"
"ProjectSearchView"
}
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
@ -208,7 +208,7 @@ impl View for ProjectFindView {
} else {
"No results"
};
Label::new(text.to_string(), theme.find.results_status.clone())
Label::new(text.to_string(), theme.search.results_status.clone())
.aligned()
.contained()
.with_background_color(theme.editor.background)
@ -235,7 +235,7 @@ impl View for ProjectFindView {
}
}
impl ItemView for ProjectFindView {
impl ItemView for ProjectSearchView {
fn act_as_type(
&self,
type_id: TypeId,
@ -260,23 +260,23 @@ impl ItemView for ProjectFindView {
Box::new(self.model.clone())
}
fn tab_content(&self, style: &theme::Tab, cx: &gpui::AppContext) -> ElementBox {
fn tab_content(&self, tab_theme: &theme::Tab, cx: &gpui::AppContext) -> ElementBox {
let settings = self.settings.borrow();
let find_theme = &settings.theme.find;
let search_theme = &settings.theme.search;
Flex::row()
.with_child(
Svg::new("icons/magnifier.svg")
.with_color(style.label.text.color)
.with_color(tab_theme.label.text.color)
.constrained()
.with_width(find_theme.tab_icon_width)
.with_width(search_theme.tab_icon_width)
.aligned()
.boxed(),
)
.with_children(self.model.read(cx).active_query.as_ref().map(|query| {
Label::new(query.as_str().to_string(), style.label.clone())
Label::new(query.as_str().to_string(), tab_theme.label.clone())
.aligned()
.contained()
.with_margin_left(find_theme.tab_icon_spacing)
.with_margin_left(search_theme.tab_icon_spacing)
.boxed()
}))
.boxed()
@ -332,7 +332,7 @@ impl ItemView for ProjectFindView {
let query = self.query_editor.read(cx).text(cx);
let editor = Editor::single_line(
self.settings.clone(),
Some(|theme| theme.find.editor.input.clone()),
Some(|theme| theme.search.editor.input.clone()),
cx,
);
editor
@ -384,15 +384,15 @@ impl ItemView for ProjectFindView {
}
}
impl ProjectFindView {
impl ProjectSearchView {
fn deploy(workspace: &mut Workspace, _: &Deploy, cx: &mut ViewContext<Workspace>) {
if let Some(existing) = workspace
.items_of_type::<ProjectFind>(cx)
.items_of_type::<ProjectSearch>(cx)
.max_by_key(|existing| existing.id())
{
workspace.activate_item(&existing, cx);
} else {
let model = cx.add_model(|cx| ProjectFind::new(workspace.project().clone(), cx));
let model = cx.add_model(|cx| ProjectSearch::new(workspace.project().clone(), cx));
workspace.open_item(model, cx);
}
}
@ -404,27 +404,27 @@ impl ProjectFindView {
}
fn search_in_new(workspace: &mut Workspace, _: &SearchInNew, cx: &mut ViewContext<Workspace>) {
if let Some(find_view) = workspace
if let Some(search_view) = workspace
.active_item(cx)
.and_then(|item| item.downcast::<ProjectFindView>())
.and_then(|item| item.downcast::<ProjectSearchView>())
{
let new_query = find_view.update(cx, |find_view, cx| {
let new_query = find_view.build_search_query(cx);
let new_query = search_view.update(cx, |search_view, cx| {
let new_query = search_view.build_search_query(cx);
if new_query.is_some() {
if let Some(old_query) = find_view.model.read(cx).active_query.clone() {
find_view.query_editor.update(cx, |editor, cx| {
if let Some(old_query) = search_view.model.read(cx).active_query.clone() {
search_view.query_editor.update(cx, |editor, cx| {
editor.set_text(old_query.as_str(), cx);
});
find_view.regex = old_query.is_regex();
find_view.whole_word = old_query.whole_word();
find_view.case_sensitive = old_query.case_sensitive();
search_view.regex = old_query.is_regex();
search_view.whole_word = old_query.whole_word();
search_view.case_sensitive = old_query.case_sensitive();
}
}
new_query
});
if let Some(new_query) = new_query {
let model = cx.add_model(|cx| {
let mut model = ProjectFind::new(workspace.project().clone(), cx);
let mut model = ProjectSearch::new(workspace.project().clone(), cx);
model.search(new_query, cx);
model
});
@ -492,7 +492,7 @@ impl ProjectFindView {
fn model_changed(&mut self, reset_selections: bool, cx: &mut ViewContext<Self>) {
let highlighted_ranges = self.model.read(cx).highlighted_ranges.clone();
if !highlighted_ranges.is_empty() {
let theme = &self.settings.borrow().theme.find;
let theme = &self.settings.borrow().theme.search;
self.results_editor.update(cx, |editor, cx| {
editor.highlight_ranges::<Self>(highlighted_ranges, theme.match_background, cx);
if reset_selections {
@ -511,9 +511,9 @@ impl ProjectFindView {
fn render_query_editor(&self, cx: &mut RenderContext<Self>) -> ElementBox {
let theme = &self.settings.borrow().theme;
let editor_container = if self.query_contains_error {
theme.find.invalid_editor
theme.search.invalid_editor
} else {
theme.find.editor.input.container
theme.search.editor.input.container
};
Flex::row()
.with_child(
@ -522,7 +522,7 @@ impl ProjectFindView {
.with_style(editor_container)
.aligned()
.constrained()
.with_max_width(theme.find.editor.max_width)
.with_max_width(theme.search.editor.max_width)
.boxed(),
)
.with_child(
@ -531,15 +531,15 @@ impl ProjectFindView {
.with_child(self.render_option_button("Word", SearchOption::WholeWord, cx))
.with_child(self.render_option_button("Regex", SearchOption::Regex, cx))
.contained()
.with_style(theme.find.option_button_group)
.with_style(theme.search.option_button_group)
.aligned()
.boxed(),
)
.contained()
.with_style(theme.find.container)
.with_style(theme.search.container)
.constrained()
.with_height(theme.workspace.toolbar.height)
.named("find bar")
.named("project search")
}
fn render_option_button(
@ -548,7 +548,7 @@ impl ProjectFindView {
option: SearchOption,
cx: &mut RenderContext<Self>,
) -> ElementBox {
let theme = &self.settings.borrow().theme.find;
let theme = &self.settings.borrow().theme.search;
let is_active = self.is_option_enabled(option);
MouseEventHandler::new::<Self, _, _>(option as usize, cx, |state, _| {
let style = match (is_active, state.hovered) {

View file

@ -1,11 +1,11 @@
use gpui::MutableAppContext;
mod buffer_find;
mod project_find;
mod buffer_search;
mod project_search;
pub fn init(cx: &mut MutableAppContext) {
buffer_find::init(cx);
project_find::init(cx);
buffer_search::init(cx);
project_search::init(cx);
}
#[derive(Clone, Copy)]

View file

@ -24,7 +24,7 @@ pub struct Theme {
pub project_panel: ProjectPanel,
pub selector: Selector,
pub editor: Editor,
pub find: Find,
pub search: Search,
pub project_diagnostics: ProjectDiagnostics,
}
@ -95,7 +95,7 @@ pub struct Toolbar {
}
#[derive(Clone, Deserialize, Default)]
pub struct Find {
pub struct Search {
#[serde(flatten)]
pub container: ContainerStyle,
pub editor: FindEditor,

View file

@ -36,7 +36,7 @@ contacts_panel = { path = "../contacts_panel" }
diagnostics = { path = "../diagnostics" }
editor = { path = "../editor" }
file_finder = { path = "../file_finder" }
find = { path = "../find" }
search = { path = "../search" }
fsevent = { path = "../fsevent" }
fuzzy = { path = "../fuzzy" }
go_to_line = { path = "../go_to_line" }

View file

@ -348,14 +348,14 @@ tab_icon_width = 13
tab_icon_spacing = 4
tab_summary_spacing = 10
[find]
[search]
match_background = "$state.highlighted_line"
background = "$surface.1"
results_status = { extends = "$text.0", size = 18 }
tab_icon_width = 14
tab_icon_spacing = 4
[find.option_button]
[search.option_button]
extends = "$text.1"
padding = { left = 6, right = 6, top = 1, bottom = 1 }
corner_radius = 6
@ -364,26 +364,26 @@ border = { width = 1, color = "$border.0" }
margin.left = 1
margin.right = 1
[find.option_button_group]
[search.option_button_group]
padding = { left = 2, right = 2 }
[find.active_option_button]
extends = "$find.option_button"
[search.active_option_button]
extends = "$search.option_button"
background = "$surface.2"
[find.hovered_option_button]
extends = "$find.option_button"
[search.hovered_option_button]
extends = "$search.option_button"
background = "$surface.2"
[find.active_hovered_option_button]
extends = "$find.option_button"
[search.active_hovered_option_button]
extends = "$search.option_button"
background = "$surface.2"
[find.match_index]
[search.match_index]
extends = "$text.1"
padding = 6
[find.editor]
[search.editor]
max_width = 400
background = "$surface.0"
corner_radius = 6
@ -394,6 +394,6 @@ placeholder_text = "$text.2"
selection = "$selection.host"
border = { width = 1, color = "$border.0" }
[find.invalid_editor]
extends = "$find.editor"
[search.invalid_editor]
extends = "$search.editor"
border = { width = 1, color = "$status.bad" }

View file

@ -60,7 +60,7 @@ fn main() {
project_symbols::init(cx);
project_panel::init(cx);
diagnostics::init(cx);
find::init(cx);
search::init(cx);
cx.spawn({
let client = client.clone();
|cx| async move {