Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/icons/chevron_down_up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/keymaps/default-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
"bindings": {
"escape": "project_search::ToggleFocus",
"shift-find": "search::FocusSearch",
"shift-enter": "project_search::ToggleAllSearchResults",
"ctrl-shift-f": "search::FocusSearch",
"ctrl-shift-h": "search::ToggleReplace",
"alt-ctrl-g": "search::ToggleRegex",
Expand Down Expand Up @@ -479,6 +480,7 @@
"alt-w": "search::ToggleWholeWord",
"alt-find": "project_search::ToggleFilters",
"alt-ctrl-f": "project_search::ToggleFilters",
"shift-enter": "project_search::ToggleAllSearchResults",
"ctrl-alt-shift-r": "search::ToggleRegex",
"ctrl-alt-shift-x": "search::ToggleRegex",
"alt-r": "search::ToggleRegex",
Expand Down
2 changes: 2 additions & 0 deletions assets/keymaps/default-macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@
"bindings": {
"escape": "project_search::ToggleFocus",
"cmd-shift-j": "project_search::ToggleFilters",
"shift-enter": "project_search::ToggleAllSearchResults",
"cmd-shift-f": "search::FocusSearch",
"cmd-shift-h": "search::ToggleReplace",
"alt-cmd-g": "search::ToggleRegex",
Expand Down Expand Up @@ -496,6 +497,7 @@
"bindings": {
"escape": "project_search::ToggleFocus",
"cmd-shift-j": "project_search::ToggleFilters",
"shift-enter": "project_search::ToggleAllSearchResults",
"cmd-shift-h": "search::ToggleReplace",
"alt-cmd-g": "search::ToggleRegex",
"alt-cmd-x": "search::ToggleRegex"
Expand Down
1 change: 1 addition & 0 deletions assets/keymaps/default-windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@
"alt-c": "search::ToggleCaseSensitive",
"alt-w": "search::ToggleWholeWord",
"alt-f": "project_search::ToggleFilters",
"shift-enter": "project_search::ToggleAllSearchResults",
"alt-r": "search::ToggleRegex",
// "ctrl-shift-alt-x": "search::ToggleRegex",
"ctrl-k shift-enter": "pane::TogglePinTab"
Expand Down
12 changes: 10 additions & 2 deletions crates/breadcrumbs/src/breadcrumbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,21 @@ impl Render for Breadcrumbs {

let breadcrumbs_stack = h_flex().gap_1().children(breadcrumbs);

let prefix_element = active_item.breadcrumb_prefix(window, cx);

let breadcrumbs = if let Some(prefix) = prefix_element {
h_flex().gap_1p5().child(prefix).child(breadcrumbs_stack)
} else {
breadcrumbs_stack
};

match active_item
.downcast::<Editor>()
.map(|editor| editor.downgrade())
{
Some(editor) => element.child(
ButtonLike::new("toggle outline view")
.child(breadcrumbs_stack)
.child(breadcrumbs)
.style(ButtonStyle::Transparent)
.on_click({
let editor = editor.clone();
Expand Down Expand Up @@ -141,7 +149,7 @@ impl Render for Breadcrumbs {
// Match the height and padding of the `ButtonLike` in the other arm.
.h(rems_from_px(22.))
.pl_1()
.child(breadcrumbs_stack),
.child(breadcrumbs),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/icons/src/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub enum IconName {
Check,
CheckDouble,
ChevronDown,
ChevronDownUp,
ChevronLeft,
ChevronRight,
ChevronUp,
Expand Down
96 changes: 91 additions & 5 deletions crates/search/src/project_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ actions!(
/// Moves to the next input field.
NextField,
/// Toggles the search filters panel.
ToggleFilters
ToggleFilters,
/// Toggles collapse/expand state of all search result excerpts.
ToggleAllSearchResults
]
);

Expand Down Expand Up @@ -118,6 +120,20 @@ pub fn init(cx: &mut App) {
ProjectSearchView::search_in_new(workspace, action, window, cx)
});

register_workspace_action_for_present_search(
workspace,
|workspace, action: &ToggleAllSearchResults, window, cx| {
if let Some(search_view) = workspace
.active_item(cx)
.and_then(|item| item.downcast::<ProjectSearchView>())
{
search_view.update(cx, |search_view, cx| {
search_view.toggle_all_search_results(action, window, cx);
});
}
},
);

register_workspace_action_for_present_search(
workspace,
|workspace, _: &menu::Cancel, window, cx| {
Expand Down Expand Up @@ -217,6 +233,7 @@ pub struct ProjectSearchView {
replace_enabled: bool,
included_opened_only: bool,
regex_language: Option<Arc<Language>>,
results_collapsed: bool,
_subscriptions: Vec<Subscription>,
}

Expand Down Expand Up @@ -649,6 +666,44 @@ impl Item for ProjectSearchView {
fn breadcrumbs(&self, theme: &theme::Theme, cx: &App) -> Option<Vec<BreadcrumbText>> {
self.results_editor.breadcrumbs(theme, cx)
}

fn breadcrumb_prefix(
&self,
_window: &mut Window,
cx: &mut Context<Self>,
) -> Option<gpui::AnyElement> {
if !self.has_matches() {
return None;
}

let is_collapsed = self.results_collapsed;

let (icon, tooltip_label) = if is_collapsed {
(IconName::ChevronUpDown, "Expand All Search Results")
} else {
(IconName::ChevronDownUp, "Collapse All Search Results")
};

let focus_handle = self.query_editor.focus_handle(cx);

Some(
IconButton::new("project-search-collapse-expand", icon)
.shape(IconButtonShape::Square)
.icon_size(IconSize::Small)
.tooltip(move |_, cx| {
Tooltip::for_action_in(
tooltip_label,
&ToggleAllSearchResults,
&focus_handle,
cx,
)
})
.on_click(cx.listener(|this, _, window, cx| {
this.toggle_all_search_results(&ToggleAllSearchResults, window, cx);
}))
.into_any_element(),
)
}
}

impl ProjectSearchView {
Expand Down Expand Up @@ -751,6 +806,34 @@ impl ProjectSearchView {
});
}

fn toggle_all_search_results(
&mut self,
_: &ToggleAllSearchResults,
_window: &mut Window,
cx: &mut Context<Self>,
) {
self.results_collapsed = !self.results_collapsed;
self.update_results_visibility(cx);
}

fn update_results_visibility(&mut self, cx: &mut Context<Self>) {
self.results_editor.update(cx, |editor, cx| {
let multibuffer = editor.buffer().read(cx);
let buffer_ids = multibuffer.excerpt_buffer_ids();

if self.results_collapsed {
for buffer_id in buffer_ids {
editor.fold_buffer(buffer_id, cx);
}
} else {
for buffer_id in buffer_ids {
editor.unfold_buffer(buffer_id, cx);
}
}
});
cx.notify();
}

pub fn new(
workspace: WeakEntity<Workspace>,
entity: Entity<ProjectSearch>,
Expand Down Expand Up @@ -909,8 +992,10 @@ impl ProjectSearchView {
replace_enabled: false,
included_opened_only: false,
regex_language: None,
results_collapsed: false,
_subscriptions: subscriptions,
};

this.entity_changed(window, cx);
this
}
Expand Down Expand Up @@ -1404,6 +1489,7 @@ impl ProjectSearchView {

fn entity_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let match_ranges = self.entity.read(cx).match_ranges.clone();

if match_ranges.is_empty() {
self.active_match_index = None;
self.results_editor.update(cx, |editor, cx| {
Expand Down Expand Up @@ -1961,6 +2047,8 @@ impl Render for ProjectSearchBar {
})
.unwrap_or_else(|| "0/0".to_string());

let query_focus = search.query_editor.focus_handle(cx);

let query_column = input_base_styles(InputPanel::Query)
.on_action(cx.listener(|this, action, window, cx| this.confirm(action, window, cx)))
.on_action(cx.listener(|this, action, window, cx| {
Expand Down Expand Up @@ -1990,11 +2078,9 @@ impl Render for ProjectSearchBar {
)),
);

let query_focus = search.query_editor.focus_handle(cx);

let matches_column = h_flex()
.pl_2()
.ml_2()
.ml_1()
.pl_1p5()
.border_l_1()
.border_color(theme_colors.border_variant)
.child(render_action_button(
Expand Down
1 change: 0 additions & 1 deletion crates/search/src/search_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub(crate) fn input_base_styles(border_color: Hsla, map: impl FnOnce(Div) -> Div
.h_8()
.pl_2()
.pr_1()
.py_1()
.border_1()
.border_color(border_color)
.rounded_md()
Expand Down
14 changes: 14 additions & 0 deletions crates/workspace/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ pub trait Item: Focusable + EventEmitter<Self::Event> + Render + Sized {
None
}

/// Returns optional elements to render to the left of the breadcrumb.
fn breadcrumb_prefix(
&self,
_window: &mut Window,
_cx: &mut Context<Self>,
) -> Option<gpui::AnyElement> {
None
}

fn added_to_workspace(
&mut self,
_workspace: &mut Workspace,
Expand Down Expand Up @@ -479,6 +488,7 @@ pub trait ItemHandle: 'static + Send {
fn to_searchable_item_handle(&self, cx: &App) -> Option<Box<dyn SearchableItemHandle>>;
fn breadcrumb_location(&self, cx: &App) -> ToolbarItemLocation;
fn breadcrumbs(&self, theme: &Theme, cx: &App) -> Option<Vec<BreadcrumbText>>;
fn breadcrumb_prefix(&self, window: &mut Window, cx: &mut App) -> Option<gpui::AnyElement>;
fn show_toolbar(&self, cx: &App) -> bool;
fn pixel_position_of_cursor(&self, cx: &App) -> Option<Point<Pixels>>;
fn downgrade_item(&self) -> Box<dyn WeakItemHandle>;
Expand Down Expand Up @@ -979,6 +989,10 @@ impl<T: Item> ItemHandle for Entity<T> {
self.read(cx).breadcrumbs(theme, cx)
}

fn breadcrumb_prefix(&self, window: &mut Window, cx: &mut App) -> Option<gpui::AnyElement> {
self.update(cx, |item, cx| item.breadcrumb_prefix(window, cx))
}

fn show_toolbar(&self, cx: &App) -> bool {
self.read(cx).show_toolbar()
}
Expand Down
Loading