From ae1a46a4e4a9279616d37badb9aa2865af13421b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sat, 26 Feb 2022 08:21:38 -0700 Subject: [PATCH] Render a magnifier icon and the query in project search tab Also: Wire up events so the modified status updates correctly. --- crates/find/src/project_find.rs | 63 +++++++++++++++++++++------ crates/theme/src/theme.rs | 2 + crates/zed/assets/icons/magnifier.svg | 3 ++ crates/zed/assets/themes/_base.toml | 2 + 4 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 crates/zed/assets/icons/magnifier.svg diff --git a/crates/find/src/project_find.rs b/crates/find/src/project_find.rs index 5a1214561effcd48f223d2bf55bc463bb62ae647..00406d26a2ee28d54fe670c866bdd59bf477181c 100644 --- a/crates/find/src/project_find.rs +++ b/crates/find/src/project_find.rs @@ -39,6 +39,7 @@ struct ProjectFind { excerpts: ModelHandle, pending_search: Option>>, highlighted_ranges: Vec>, + active_query: Option, } struct ProjectFindView { @@ -64,6 +65,7 @@ impl ProjectFind { excerpts: cx.add_model(|_| MultiBuffer::new(replica_id)), pending_search: Default::default(), highlighted_ranges: Default::default(), + active_query: None, } } @@ -75,6 +77,7 @@ impl ProjectFind { .update(new_cx, |excerpts, cx| cx.add_model(|cx| excerpts.clone(cx))), pending_search: Default::default(), highlighted_ranges: self.highlighted_ranges.clone(), + active_query: self.active_query.clone(), } } @@ -104,6 +107,7 @@ impl ProjectFind { } }); this.pending_search.take(); + this.active_query = Some(query); cx.notify(); }); } @@ -124,8 +128,22 @@ impl Item for ProjectFind { ) -> Self::View { let settings = workspace.settings(); let excerpts = model.read(cx).excerpts.clone(); + let results_editor = cx.add_view(|cx| { + let mut editor = Editor::for_buffer( + excerpts, + Some(workspace.project().clone()), + settings.clone(), + cx, + ); + editor.set_searchable(false); + editor.set_nav_history(Some(nav_history)); + editor + }); + cx.observe(&results_editor, |_, _, cx| cx.emit(ViewEvent::UpdateTab)) + .detach(); cx.observe(&model, |this, _, cx| this.model_changed(true, cx)) .detach(); + ProjectFindView { model, query_editor: cx.add_view(|cx| { @@ -135,17 +153,7 @@ impl Item for ProjectFind { cx, ) }), - results_editor: cx.add_view(|cx| { - let mut editor = Editor::for_buffer( - excerpts, - Some(workspace.project().clone()), - settings.clone(), - cx, - ); - editor.set_searchable(false); - editor.set_nav_history(Some(nav_history)); - editor - }), + results_editor, case_sensitive: false, whole_word: false, regex: false, @@ -159,8 +167,12 @@ impl Item for ProjectFind { } } +enum ViewEvent { + UpdateTab, +} + impl Entity for ProjectFindView { - type Event = (); + type Event = ViewEvent; } impl View for ProjectFindView { @@ -231,8 +243,26 @@ impl ItemView for ProjectFindView { Box::new(self.model.clone()) } - fn tab_content(&self, style: &theme::Tab, _: &gpui::AppContext) -> ElementBox { - Label::new("Project Find".to_string(), style.label.clone()).boxed() + fn tab_content(&self, style: &theme::Tab, cx: &gpui::AppContext) -> ElementBox { + let settings = self.settings.borrow(); + let find_theme = &settings.theme.find; + Flex::row() + .with_child( + Svg::new("icons/magnifier.svg") + .with_color(style.label.text.color) + .constrained() + .with_width(find_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()) + .aligned() + .contained() + .with_margin_left(find_theme.tab_icon_spacing) + .boxed() + })) + .boxed() } fn project_path(&self, _: &gpui::AppContext) -> Option { @@ -331,6 +361,10 @@ impl ItemView for ProjectFindView { self.results_editor .update(cx, |editor, cx| editor.navigate(data, cx)); } + + fn should_update_tab_on_event(event: &ViewEvent) -> bool { + matches!(event, ViewEvent::UpdateTab) + } } impl ProjectFindView { @@ -407,6 +441,7 @@ impl ProjectFindView { } } + cx.emit(ViewEvent::UpdateTab); cx.notify(); } diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index babd9f6e2001690c9342f1f4c268ddc7464cb503..701047961947f7982b6058cab81ea1ce40b4ab79 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -108,6 +108,8 @@ pub struct Find { pub match_background: Color, pub match_index: ContainedText, pub results_status: TextStyle, + pub tab_icon_width: f32, + pub tab_icon_spacing: f32, } #[derive(Clone, Deserialize, Default)] diff --git a/crates/zed/assets/icons/magnifier.svg b/crates/zed/assets/icons/magnifier.svg new file mode 100644 index 0000000000000000000000000000000000000000..dc27a594ee3d6996e6e5a0fd9922774a05129ada --- /dev/null +++ b/crates/zed/assets/icons/magnifier.svg @@ -0,0 +1,3 @@ + + + diff --git a/crates/zed/assets/themes/_base.toml b/crates/zed/assets/themes/_base.toml index f7fd023f23a1d8e8fcc3f45e7e2f70115d972ce7..b46f8efa5071dc738cab9f60bc897c96e93ca723 100644 --- a/crates/zed/assets/themes/_base.toml +++ b/crates/zed/assets/themes/_base.toml @@ -352,6 +352,8 @@ tab_summary_spacing = 10 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] extends = "$text.1"