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' of github.com:zed-industries/zed into project_search_design

KCaverlyd727ba18f248
diff --cc assets/keymaps/default.json
index 3b894de723a,38ec8ffb405..d0fad11503d
--- a/assets/keymaps/default.json
+++ b/assets/keymaps/default.json
@@@ -265,9 -262,7 +265,8 @@@
"alt-enter": "search::SelectAllMatches",
"alt-cmd-c": "search::ToggleCaseSensitive",
"alt-cmd-w": "search::ToggleWholeWord",
- "alt-cmd-r": "search::ActivateRegexMode",
- "alt-cmd-r": "search::ToggleRegex"
+ "alt-tab": "search::CycleMode",
+ "alt-cmd-f": "project_search::ToggleFilters"
}
},
// Bindings from VS Code
diff --cc crates/search/src/buffer_search.rs
index 32e6c93f4ad,36c9d3becd3..daf92151fc1
--- a/crates/search/src/buffer_search.rs
+++ b/crates/search/src/buffer_search.rs
@@@ -487,22 -495,12 +487,22 @@@ impl BufferSearchBar
let tooltip = "Select All Matches";
let tooltip_style = theme::current(cx).tooltip.clone();
let action_type_id = 0_usize;
-
+ let has_matches = self.active_match_index.is_some();
+ let cursor_style = if has_matches {
+ CursorStyle::PointingHand
+ } else {
+ CursorStyle::default()
+ };
enum ActionButton {}
- MouseEventHandler::<ActionButton, _>::new(action_type_id, cx, |state, cx| {
+ MouseEventHandler::new::<ActionButton, _>(action_type_id, cx, |state, cx| {
let theme = theme::current(cx);
- let style = theme.search.action_button.style_for(state);
+ let style = theme
+ .search
+ .action_button
+ .in_state(has_matches)
+ .style_for(state);
Label::new(icon, style.text.clone())
+ .aligned()
.contained()
.with_style(style.container)
})
@@@ -519,19 -517,42 +519,20 @@@
)
.into_any()
}
+
- fn render_close_button(
- &self,
- theme: &theme::Search,
- cx: &mut ViewContext<Self>,
- ) -> AnyElement<Self> {
- let tooltip = "Dismiss Buffer Search";
- let tooltip_style = theme::current(cx).tooltip.clone();
-
- enum CloseButton {}
- MouseEventHandler::new::<CloseButton, _>(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, move |_, this, cx| {
- this.dismiss(&Default::default(), cx)
- })
- .with_cursor_style(CursorStyle::PointingHand)
- .with_tooltip::<CloseButton>(
- 0,
- tooltip.to_string(),
- Some(Box::new(Dismiss)),
- tooltip_style,
- cx,
- )
- .into_any()
+ pub fn activate_search_mode(&mut self, mode: SearchMode, cx: &mut ViewContext<Self>) {
+ assert_ne!(
+ mode,
+ SearchMode::Semantic,
+ "Semantic search is not supported in buffer search"
+ );
+ if mode == self.current_mode {
+ return;
+ }
+ self.current_mode = mode;
+ let _ = self.update_matches(cx);
+ cx.notify();
}
-
fn deploy(pane: &mut Pane, action: &Deploy, cx: &mut ViewContext<Pane>) {
let mut propagate_action = true;
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
diff --cc crates/search/src/project_search.rs
index fb0e71b1ed6,8bc8d7da882..d0a1aa95c1e
--- a/crates/search/src/project_search.rs
+++ b/crates/search/src/project_search.rs
@@@ -406,28 -328,12 +406,28 @@@ impl View for ProjectSearchView
editor.set_placeholder_text(new_placeholder_text, cx);
});
- MouseEventHandler::<Status, _>::new(0, cx, |_, _| {
+ MouseEventHandler::new::<Status, _>(0, cx, |_, _| {
- Label::new(text, theme.search.results_status.clone())
- .aligned()
+ Flex::column()
+ .with_child(Flex::column().contained().flex(1., true))
+ .with_child(
+ Flex::column()
+ .align_children_center()
+ .with_child(Label::new(
+ major_text,
+ theme.search.major_results_status.clone(),
+ ))
+ .with_children(
+ minor_text.into_iter().map(|x| {
+ Label::new(x, theme.search.minor_results_status.clone())
+ }),
+ )
+ .aligned()
+ .top()
+ .contained()
+ .flex(7., true),
+ )
.contained()
.with_background_color(theme.editor.background)
- .flex(1., true)
})
.on_down(MouseButton::Left, |_, _, cx| {
cx.focus_parent();
diff --cc crates/search/src/search_bar.rs
index 47892c0ca66,00000000000..88d46751022
mode 100644,000000..100644
--- a/crates/search/src/search_bar.rs
+++ b/crates/search/src/search_bar.rs
@@@ -1,198 -1,0 +1,198 @@@
+use std::borrow::Cow;
+
+use gpui::{
+ elements::{Label, MouseEventHandler, Svg},
+ platform::{CursorStyle, MouseButton},
+ scene::{CornerRadii, MouseClick},
+ Action, AnyElement, Element, EventContext, View, ViewContext,
+};
+use workspace::searchable::Direction;
+
+use crate::{
+ mode::{SearchMode, Side},
+ 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, _| {
++ MouseEventHandler::new::<CloseButton, _>(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()
+ .contained()
+ .with_style(style.container)
+ .constrained()
+ .with_height(theme.search_bar_row_height)
+ })
+ .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,
+ active: bool,
+ 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();
+ let cursor_style = if active {
+ CursorStyle::PointingHand
+ } else {
+ CursorStyle::default()
+ };
+ enum NavButton {}
- MouseEventHandler::<NavButton, _>::new(direction as usize, cx, |state, cx| {
++ MouseEventHandler::new::<NavButton, _>(direction as usize, cx, |state, cx| {
+ let theme = theme::current(cx);
+ let style = theme
+ .search
+ .nav_button
+ .in_state(active)
+ .style_for(state)
+ .clone();
+ let mut container_style = style.container.clone();
+ let label = Label::new(icon, style.label.clone()).aligned().contained();
+ container_style.corner_radii = match direction {
+ Direction::Prev => CornerRadii {
+ bottom_right: 0.,
+ top_right: 0.,
+ ..container_style.corner_radii
+ },
+ Direction::Next => CornerRadii {
+ bottom_left: 0.,
+ top_left: 0.,
+ ..container_style.corner_radii
+ },
+ };
+ if direction == Direction::Prev {
+ // Remove right border so that when both Next and Prev buttons are
+ // next to one another, there's no double border between them.
+ container_style.border.right = false;
+ }
+ label.with_style(container_style)
+ })
+ .on_click(MouseButton::Left, on_click)
+ .with_cursor_style(cursor_style)
+ .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| {
++ MouseEventHandler::new::<SearchModeButton, _>(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();
+ style.container.border.left = mode.border_left();
+ style.container.border.right = mode.border_right();
+
+ let label = Label::new(mode.label(), style.text.clone())
+ .aligned()
+ .contained();
+ let mut container_style = style.container.clone();
+ if let Some(button_side) = mode.button_side() {
+ if button_side == Side::Left {
+ container_style.corner_radii = CornerRadii {
+ bottom_right: 0.,
+ top_right: 0.,
+ ..container_style.corner_radii
+ };
+ label.with_style(container_style)
+ } else {
+ container_style.corner_radii = CornerRadii {
+ bottom_left: 0.,
+ top_left: 0.,
+ ..container_style.corner_radii
+ };
+ label.with_style(container_style)
+ }
+ } else {
+ container_style.corner_radii = CornerRadii::default();
+ label.with_style(container_style)
+ }
+ .constrained()
+ .with_height(theme.search.search_bar_row_height)
+ })
+ .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,
+ id: usize,
+ label: impl Into<Cow<'static, str>>,
+ action: Box<dyn Action>,
+ 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(id, cx, |state, cx| {
++ MouseEventHandler::new::<V, _>(id, 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(theme.search.option_button_height)
+ })
+ .on_click(MouseButton::Left, on_click)
+ .with_cursor_style(CursorStyle::PointingHand)
+ .with_tooltip::<V>(id, label, Some(action), tooltip_style, cx)
+ .into_any()
+}
diff --cc crates/workspace/src/pane.rs
index 51e2da3f6a1,4aca96374a9..dee6701564d
--- a/crates/workspace/src/pane.rs
+++ b/crates/workspace/src/pane.rs
@@@ -222,56 -222,6 +222,56 @@@ impl TabBarContextMenu
}
}
+#[allow(clippy::too_many_arguments)]
+fn nav_button<A: Action, F: 'static + Fn(&mut Pane, &mut ViewContext<Pane>)>(
+ svg_path: &'static str,
+ style: theme::Interactive<theme::IconButton>,
+ nav_button_height: f32,
+ tooltip_style: TooltipStyle,
+ enabled: bool,
+ on_click: F,
+ tooltip_action: A,
+ action_name: &str,
+ cx: &mut ViewContext<Pane>,
+) -> AnyElement<Pane> {
- MouseEventHandler::<A, _>::new(0, cx, |state, _| {
++ MouseEventHandler::new::<A, _>(0, cx, |state, _| {
+ let style = if enabled {
+ style.style_for(state)
+ } else {
+ style.disabled_style()
+ };
+ Svg::new(svg_path)
+ .with_color(style.color)
+ .constrained()
+ .with_width(style.icon_width)
+ .aligned()
+ .contained()
+ .with_style(style.container)
+ .constrained()
+ .with_width(style.button_width)
+ .with_height(nav_button_height)
+ .aligned()
+ .top()
+ })
+ .with_cursor_style(if enabled {
+ CursorStyle::PointingHand
+ } else {
+ CursorStyle::default()
+ })
+ .on_click(MouseButton::Left, move |_, toolbar, cx| {
+ on_click(toolbar, cx)
+ })
+ .with_tooltip::<A>(
+ 0,
+ action_name.to_string(),
+ Some(Box::new(tooltip_action)),
+ tooltip_style,
+ cx,
+ )
+ .contained()
+ .into_any_named("nav button")
+}
+
impl Pane {
pub fn new(
workspace: WeakViewHandle<Workspace>,
diff --cc crates/workspace/src/toolbar.rs
index e8c1240d437,0516f3a145d..72c879d6d40
--- a/crates/workspace/src/toolbar.rs
+++ b/crates/workspace/src/toolbar.rs
@@@ -143,10 -210,63 +143,65 @@@ impl View for Toolbar
}
}
-#[allow(clippy::too_many_arguments)]
-fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(
- svg_path: &'static str,
- style: theme::Interactive<theme::IconButton>,
- nav_button_height: f32,
- tooltip_style: TooltipStyle,
- enabled: bool,
- spacing: f32,
- on_click: F,
- tooltip_action: A,
- action_name: &'static str,
- cx: &mut ViewContext<Toolbar>,
-) -> AnyElement<Toolbar> {
- MouseEventHandler::new::<A, _>(0, cx, |state, _| {
- let style = if enabled {
- style.style_for(state)
- } else {
- style.disabled_style()
- };
- Svg::new(svg_path)
- .with_color(style.color)
- .constrained()
- .with_width(style.icon_width)
- .aligned()
- .contained()
- .with_style(style.container)
- .constrained()
- .with_width(style.button_width)
- .with_height(nav_button_height)
- .aligned()
- .top()
- })
- .with_cursor_style(if enabled {
- CursorStyle::PointingHand
- } else {
- CursorStyle::default()
- })
- .on_click(MouseButton::Left, move |_, toolbar, cx| {
- on_click(toolbar, cx)
- })
- .with_tooltip::<A>(
- 0,
- action_name,
- Some(Box::new(tooltip_action)),
- tooltip_style,
- cx,
- )
- .contained()
- .with_margin_right(spacing)
- .into_any_named("nav button")
-}
-
++// <<<<<<< HEAD
++// =======
++// #[allow(clippy::too_many_arguments)]
++// fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>)>(
++// svg_path: &'static str,
++// style: theme::Interactive<theme::IconButton>,
++// nav_button_height: f32,
++// tooltip_style: TooltipStyle,
++// enabled: bool,
++// spacing: f32,
++// on_click: F,
++// tooltip_action: A,
++// action_name: &'static str,
++// cx: &mut ViewContext<Toolbar>,
++// ) -> AnyElement<Toolbar> {
++// MouseEventHandler::new::<A, _>(0, cx, |state, _| {
++// let style = if enabled {
++// style.style_for(state)
++// } else {
++// style.disabled_style()
++// };
++// Svg::new(svg_path)
++// .with_color(style.color)
++// .constrained()
++// .with_width(style.icon_width)
++// .aligned()
++// .contained()
++// .with_style(style.container)
++// .constrained()
++// .with_width(style.button_width)
++// .with_height(nav_button_height)
++// .aligned()
++// .top()
++// })
++// .with_cursor_style(if enabled {
++// CursorStyle::PointingHand
++// } else {
++// CursorStyle::default()
++// })
++// .on_click(MouseButton::Left, move |_, toolbar, cx| {
++// on_click(toolbar, cx)
++// })
++// .with_tooltip::<A>(
++// 0,
++// action_name,
++// Some(Box::new(tooltip_action)),
++// tooltip_style,
++// cx,
++// )
++// .contained()
++// .with_margin_right(spacing)
++// .into_any_named("nav button")
++// }
++
++// >>>>>>> 139cbbfd3aebd0863a7d51b0c12d748764cf0b2e
impl Toolbar {
- pub fn new(pane: Option<WeakViewHandle<Pane>>) -> Self {
+ pub fn new() -> Self {
Self {
active_item: None,
- pane,
items: Default::default(),
hidden: false,
can_navigate: true,