Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into project_search_design

Piotr Osiewicz6be73e46bfb2
diff --cc crates/search/src/project_search.rs
index f0363ee5d9a,018ab9cb115..db48fa14c3e
--- a/crates/search/src/project_search.rs
+++ b/crates/search/src/project_search.rs
@@@ -1415,248 -1284,103 +1415,248 @@@ impl View for ProjectSearchBar
.aligned()
.right()
.flex(1.0, true);
-
let row_spacing = theme.workspace.toolbar.container.padding.bottom;
+ let search = _search.read(cx);
+ let filter_button = {
+ let tooltip_style = theme::current(cx).tooltip.clone();
+ let is_active = search.filters_enabled;
+ MouseEventHandler::<Self, _>::new(0, cx, |state, cx| {
+ let theme = theme::current(cx);
+ let style = theme
+ .search
+ .option_button
+ .in_state(is_active)
+ .style_for(state);
+ Svg::new("icons/filter_12.svg")
+ .with_color(style.text.color.clone())
+ .contained()
+ .with_style(style.container)
+ })
+ .on_click(MouseButton::Left, move |_, this, cx| {
+ this.toggle_filters(cx);
+ })
+ .with_cursor_style(CursorStyle::PointingHand)
+ .with_tooltip::<Self>(
+ 0,
- "Toggle filters".into(),
++ "Toggle filters",
+ Some(Box::new(ToggleFilters)),
+ tooltip_style,
+ cx,
+ )
+ .into_any()
+ };
+ let search = _search.read(cx);
+ let is_semantic_disabled = search.semantic_state.is_none();
+ let render_option_button_icon = |path, option, cx: &mut ViewContext<Self>| {
+ crate::search_bar::render_option_button_icon(
+ self.is_option_enabled(option, cx),
+ path,
+ option,
+ move |_, this, cx| {
+ this.toggle_search_option(option, cx);
+ },
+ cx,
+ )
+ };
+ let case_sensitive = is_semantic_disabled.then(|| {
+ render_option_button_icon(
+ "icons/case_insensitive_12.svg",
+ SearchOptions::CASE_SENSITIVE,
+ cx,
+ )
+ });
- Flex::column()
+ let whole_word = is_semantic_disabled.then(|| {
+ render_option_button_icon("icons/word_search_12.svg", SearchOptions::WHOLE_WORD, cx)
+ });
+
+ let search = _search.read(cx);
+ let icon_style = theme.search.editor_icon.clone();
+ let query = Flex::row()
+ .with_child(
+ Svg::for_style(icon_style.icon)
+ .contained()
+ .with_style(icon_style.container)
+ .constrained(),
+ )
+ .with_child(
+ ChildView::new(&search.query_editor, cx)
+ .constrained()
+ .flex(1., true)
+ .into_any(),
+ )
.with_child(
Flex::row()
+ .with_child(filter_button)
+ .with_children(whole_word)
+ .with_children(case_sensitive)
+ .flex(1., true)
+ .contained(),
+ )
+ .align_children_center()
+ .aligned()
+ .left()
+ .flex(1., true);
+ let search = _search.read(cx);
+ let matches = search.active_match_index.map(|match_ix| {
+ Label::new(
+ format!(
+ "{}/{}",
+ match_ix + 1,
+ search.model.read(cx).match_ranges.len()
+ ),
+ theme.search.match_index.text.clone(),
+ )
+ .contained()
+ .with_style(theme.search.match_index.container)
+ });
+
+ let filters = search.filters_enabled.then(|| {
+ Flex::row()
+ .with_child(
+ Flex::row()
+ .with_child(included_files_view)
+ .contained()
+ .with_style(include_container_style)
+ .aligned()
+ .constrained()
+ .with_min_width(theme.search.include_exclude_editor.min_width)
+ .with_max_width(theme.search.include_exclude_editor.max_width)
+ .flex(1., false),
+ )
+ .with_child(
+ Flex::row()
+ .with_child(excluded_files_view)
+ .contained()
+ .with_style(exclude_container_style)
+ .aligned()
+ .constrained()
+ .with_min_width(theme.search.include_exclude_editor.min_width)
+ .with_max_width(theme.search.include_exclude_editor.max_width)
+ .flex(1., false),
+ )
+ });
+ let search_button_for_mode = |mode, cx: &mut ViewContext<ProjectSearchBar>| {
+ let is_active = if let Some(search) = self.active_project_search.as_ref() {
+ let search = search.read(cx);
+ search.current_mode == mode
+ } else {
+ false
+ };
+ render_search_mode_button(
+ mode,
+ is_active,
+ move |_, this, cx| {
+ this.activate_search_mode(mode, cx);
+ },
+ cx,
+ )
+ };
+ let semantic_index = SemanticIndex::enabled(cx)
+ .then(|| search_button_for_mode(SearchMode::Semantic, cx));
+ let nav_button_for_direction = |label, direction, cx: &mut ViewContext<Self>| {
+ render_nav_button(
+ label,
+ direction,
+ move |_, this, cx| {
+ if let Some(search) = this.active_project_search.as_ref() {
+ search.update(cx, |search, cx| search.select_match(direction, cx));
+ }
+ },
+ cx,
+ )
+ };
+
+ Flex::row()
+ .with_child(
+ Flex::column()
.with_child(
Flex::row()
+ .align_children_center()
.with_child(
- ChildView::new(&search.query_editor, cx)
- .aligned()
- .left()
- .flex(1., true),
+ Flex::row()
+ .with_child(nav_button_for_direction(
+ "<",
+ Direction::Prev,
+ cx,
+ ))
+ .with_child(nav_button_for_direction(
+ ">",
+ Direction::Next,
+ cx,
+ ))
+ .aligned(),
)
- .with_children(search.active_match_index.map(|match_ix| {
- Label::new(
- format!(
- "{}/{}",
- match_ix + 1,
- search.model.read(cx).match_ranges.len()
- ),
- theme.search.match_index.text.clone(),
- )
- .contained()
- .with_style(theme.search.match_index.container)
- .aligned()
- }))
- .contained()
- .with_style(query_container_style)
+ .with_children(matches)
.aligned()
- .constrained()
- .with_min_width(theme.search.editor.min_width)
- .with_max_width(theme.search.editor.max_width)
- .flex(1., false),
+ .top()
+ .left(),
)
+ .constrained()
+ .with_max_height(theme.search.search_bar_row_height)
+ .flex(1., true),
+ )
+ .with_child(
+ Flex::column()
+ .align_children_center()
.with_child(
Flex::row()
- .with_child(self.render_nav_button("<", Direction::Prev, cx))
- .with_child(self.render_nav_button(">", Direction::Next, cx))
- .aligned(),
- )
- .with_child({
- let row = if SemanticIndex::enabled(cx) {
- Flex::row().with_child(self.render_semantic_search_button(cx))
- } else {
- Flex::row()
- };
-
- let row = row
- .with_child(self.render_option_button(
- "Case",
- SearchOptions::CASE_SENSITIVE,
- cx,
- ))
- .with_child(self.render_option_button(
- "Word",
- SearchOptions::WHOLE_WORD,
- cx,
- ))
- .with_child(self.render_option_button(
- "Regex",
- SearchOptions::REGEX,
- cx,
- ))
+ .with_child(
+ Flex::row()
+ .with_child(query)
+ .contained()
+ .with_style(query_container_style)
+ .aligned()
+ .constrained()
+ .with_min_width(theme.search.editor.min_width)
+ .with_max_width(theme.search.editor.max_width)
+ .with_max_height(theme.search.search_bar_row_height)
+ .flex(1., false),
+ )
.contained()
- .with_style(theme.search.option_button_group)
- .aligned();
-
- row
- })
+ .with_margin_bottom(row_spacing),
+ )
+ .with_children(filters)
.contained()
- .with_margin_bottom(row_spacing),
+ .aligned()
+ .top()
+ .flex(1., false),
)
.with_child(
- Flex::row()
+ Flex::column()
.with_child(
Flex::row()
- .with_child(included_files_view)
- .contained()
- .with_style(include_container_style)
- .aligned()
+ .align_children_center()
+ .with_child(search_button_for_mode(SearchMode::Text, cx))
+ .with_children(semantic_index)
+ .with_child(search_button_for_mode(SearchMode::Regex, cx))
+ .with_child(super::search_bar::render_close_button(
+ "Dismiss Project Search",
+ &theme.search,
+ cx,
+ |_, this, cx| {
+ if let Some(search) = this.active_project_search.as_mut() {
+ search.update(cx, |_, cx| cx.emit(ViewEvent::Dismiss))
+ }
+ },
+ None,
+ ))
.constrained()
- .with_min_width(theme.search.include_exclude_editor.min_width)
- .with_max_width(theme.search.include_exclude_editor.max_width)
- .flex(1., false),
- )
- .with_child(
- Flex::row()
- .with_child(excluded_files_view)
+ .with_height(theme.workspace.toolbar.height)
.contained()
- .with_style(exclude_container_style)
.aligned()
- .constrained()
- .with_min_width(theme.search.include_exclude_editor.min_width)
- .with_max_width(theme.search.include_exclude_editor.max_width)
- .flex(1., false),
- ),
+ .right()
+ .top()
+ .flex(1., true),
+ )
+ .with_children(
+ _search
+ .read(cx)
+ .filters_enabled
+ .then(|| Flex::row().flex(1., true)),
+ )
+ .contained()
+ .flex(1., true),
)
.contained()
.with_style(theme.search.container)
diff --cc crates/search/src/search_bar.rs
index 1569174c92b,00000000000..ecfb51b1c64
mode 100644,000000..100644
--- a/crates/search/src/search_bar.rs
+++ b/crates/search/src/search_bar.rs
@@@ -1,238 -1,0 +1,238 @@@
+use gpui::{
+ elements::{Flex, Label, MouseEventHandler, ParentElement, Svg},
+ platform::{CursorStyle, MouseButton},
+ scene::MouseClick,
+ Action, AnyElement, Element, EventContext, View, ViewContext,
+};
+use workspace::searchable::Direction;
+
+use crate::{
+ elements::ButtonSide,
+ mode::{SearchMode, Side},
+ SearchOptions, SelectNextMatch, SelectPrevMatch,
+};
+
+pub(super) fn render_close_button<V: View>(
+ tooltip: &'static str,
+ theme: &theme::Search,
+ cx: &mut ViewContext<V>,
+ on_click: impl Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
+ dismiss_action: Option<Box<dyn Action>>,
+) -> AnyElement<V> {
+ let tooltip_style = theme::current(cx).tooltip.clone();
+
+ enum CloseButton {}
+ MouseEventHandler::<CloseButton, _>::new(0, cx, |state, _| {
+ let style = theme.dismiss_button.style_for(state);
+ Svg::new("icons/x_mark_8.svg")
+ .with_color(style.color)
+ .constrained()
+ .with_width(style.icon_width)
+ .aligned()
+ .constrained()
+ .with_width(style.button_width)
+ .contained()
+ .with_style(style.container)
+ })
+ .on_click(MouseButton::Left, on_click)
+ .with_cursor_style(CursorStyle::PointingHand)
+ .with_tooltip::<CloseButton>(0, tooltip.to_string(), dismiss_action, tooltip_style, cx)
+ .into_any()
+}
+
+pub(super) fn render_nav_button<V: View>(
+ icon: &'static str,
+ direction: Direction,
+ on_click: impl Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
+ cx: &mut ViewContext<V>,
+) -> AnyElement<V> {
+ let action: Box<dyn Action>;
+ let tooltip;
+
+ match direction {
+ Direction::Prev => {
+ action = Box::new(SelectPrevMatch);
+ tooltip = "Select Previous Match";
+ }
+ Direction::Next => {
+ action = Box::new(SelectNextMatch);
+ tooltip = "Select Next Match";
+ }
+ };
+ let tooltip_style = theme::current(cx).tooltip.clone();
+
+ enum NavButton {}
+ MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| {
+ let theme = theme::current(cx);
+ let mut style = theme.search.nav_button.style_for(state).clone();
- let button_side_width = style.container.corner_radius;
- style.container.corner_radius = 0.;
++ let button_side_width = style.container.corner_radii.top_left;
++ style.container.corner_radii = (0.).into();
+ let label = Label::new(icon, style.label.clone())
+ .contained()
+ .with_style(style.container.clone());
+ match direction {
+ Direction::Prev => Flex::row()
+ .with_child(
+ ButtonSide::left(
+ style
+ .clone()
+ .container
+ .background_color
+ .unwrap_or_else(gpui::color::Color::transparent_black),
+ button_side_width,
+ )
+ .with_border(style.container.border.width, style.container.border.color)
+ .contained()
+ .constrained()
+ .with_max_width(button_side_width),
+ )
+ .with_child(label)
+ .constrained()
+ .with_height(theme.workspace.toolbar.height),
+ Direction::Next => Flex::row()
+ .with_child(label)
+ .with_child(
+ ButtonSide::right(
+ style
+ .clone()
+ .container
+ .background_color
+ .unwrap_or_else(gpui::color::Color::transparent_black),
+ button_side_width,
+ )
+ .with_border(style.container.border.width, style.container.border.color)
+ .contained()
+ .constrained()
+ .with_max_width(button_side_width),
+ )
+ .constrained()
+ .with_height(theme.workspace.toolbar.height),
+ }
+ })
+ .on_click(MouseButton::Left, on_click)
+ .with_cursor_style(CursorStyle::PointingHand)
+ .with_tooltip::<NavButton>(
+ direction as usize,
+ tooltip.to_string(),
+ Some(action),
+ tooltip_style,
+ cx,
+ )
+ .into_any()
+}
+
+pub(crate) fn render_search_mode_button<V: View>(
+ mode: SearchMode,
+ is_active: bool,
+ on_click: impl Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
+ cx: &mut ViewContext<V>,
+) -> AnyElement<V> {
+ let tooltip_style = theme::current(cx).tooltip.clone();
+ enum SearchModeButton {}
+ MouseEventHandler::<SearchModeButton, _>::new(mode.region_id(), cx, |state, cx| {
+ let theme = theme::current(cx);
+ let mut style = theme
+ .search
+ .mode_button
+ .in_state(is_active)
+ .style_for(state)
+ .clone();
- let side_width = style.container.corner_radius;
- style.container.corner_radius = 0.;
++ let side_width = style.container.corner_radii.top_left;
++ style.container.corner_radii = (0.).into();
+ if mode.button_side().is_some() {
+ style.container.border.left = mode.border_left();
+ style.container.border.right = mode.border_right();
+ }
+ let label = Label::new(mode.label(), style.text.clone())
+ .contained()
+ .with_style(style.container);
+
+ if let Some(button_side) = mode.button_side() {
+ if button_side == Side::Left {
+ Flex::row()
+ .align_children_center()
+ .with_child(
+ ButtonSide::left(
+ style
+ .container
+ .background_color
+ .unwrap_or_else(gpui::color::Color::transparent_black),
+ side_width,
+ )
+ .with_border(style.container.border.width, style.container.border.color)
+ .contained()
+ .constrained()
+ .with_max_width(side_width)
+ .with_height(theme.search.search_bar_row_height),
+ )
+ .with_child(label)
+ .into_any()
+ } else {
+ Flex::row()
+ .align_children_center()
+ .with_child(label)
+ .with_child(
+ ButtonSide::right(
+ style
+ .container
+ .background_color
+ .unwrap_or_else(gpui::color::Color::transparent_black),
+ side_width,
+ )
+ .with_border(style.container.border.width, style.container.border.color)
+ .contained()
+ .constrained()
+ .with_max_width(side_width)
+ .with_height(theme.search.search_bar_row_height),
+ )
+ .into_any()
+ }
+ } else {
+ label.into_any()
+ }
+ })
+ .on_click(MouseButton::Left, on_click)
+ .with_cursor_style(CursorStyle::PointingHand)
+ .with_tooltip::<SearchModeButton>(
+ mode.region_id(),
+ mode.tooltip_text().to_owned(),
+ Some(mode.activate_action()),
+ tooltip_style,
+ cx,
+ )
+ .into_any()
+}
+
+pub(crate) fn render_option_button_icon<V: View>(
+ is_active: bool,
+ icon: &'static str,
+ option: SearchOptions,
+ on_click: impl Fn(MouseClick, &mut V, &mut EventContext<V>) + 'static,
+ cx: &mut ViewContext<V>,
+) -> AnyElement<V> {
+ let tooltip_style = theme::current(cx).tooltip.clone();
+ MouseEventHandler::<V, _>::new(option.bits as usize, cx, |state, cx| {
+ let theme = theme::current(cx);
+ let style = theme
+ .search
+ .option_button
+ .in_state(is_active)
+ .style_for(state);
+ Svg::new(icon)
+ .with_color(style.text.color.clone())
+ .contained()
+ .with_style(style.container)
+ .constrained()
+ .with_height(22.)
+ })
+ .on_click(MouseButton::Left, on_click)
+ .with_cursor_style(CursorStyle::PointingHand)
+ .with_tooltip::<V>(
+ option.bits as usize,
+ format!("Toggle {}", option.label()),
+ Some(option.to_toggle_action()),
+ tooltip_style,
+ cx,
+ )
+ .into_any()
+}