History

Select all matches (#2717)

Closes https://github.com/zed-industries/community/issues/75 Closes https://github.com/zed-industries/community/issues/1749 The PR * changes keybindings for `Editor && mode == auto_height` context: before, `alt-enter` and `alt-shift-enter` added new lines in such editors, including the one from buffer search. New bindings are the same as in `Editor && mode == full` context. * adds `search::SelectAllMatches` action and binds it to `Alt + Enter` by default, to select all matches of a buffer search The behavior mimics VSCode: we do not move the screen even if all selections are out of the visible range (Cmd+G will navigate there) and allow reselecting the results from both pane and search field, as long as the search is not dismissed. Release Notes: - Added `search::SelectAllMatches` (`Alt + Enter` default) action to place carets and select all buffer search results ([#75](https://github.com/zed-industries/community/issues/75), [#1749](https://github.com/zed-industries/community/issues/1749)).

Kirill Bulatov committed 3 years ago

Commit cde5b392 parents 0f54893 b14cd5f12 files · +337 −31Browse files

Unified · Split

12 files
  1. assets/keymaps/default.json +5 −3
  2. crates/editor/src/items.rs +32 −5
  3. crates/editor/src/selections_collection.rs +2 −2
  4. crates/feedback/src/feedback_editor.rs +12 −2
  5. crates/language_tools/src/lsp_log.rs +12 −2
  6. crates/search/src/buffer_search.rs +199 −12
  7. crates/search/src/search.rs +2 −1
  8. crates/terminal/src/terminal.rs +15 −0
  9. crates/terminal_view/src/terminal_view.rs +12 −1
  10. crates/theme/src/theme.rs +1 −0
  11. crates/workspace/src/searchable.rs +16 −3
  12. styles/src/style_tree/search.ts +29 −0
assets/keymaps/default.json+5−3
@@ -194,8 +194,8 @@ · 193 unmodified lines
194194 {
195195 "context": "Editor && mode == auto_height",
196196 "bindings": {
197− "alt-enter": "editor::Newline",
198− "cmd-alt-enter": "editor::NewlineBelow"
197+ "shift-enter": "editor::Newline",
198+ "cmd-shift-enter": "editor::NewlineBelow"
199199 }
200200 },
201201 {
@@ -221,7 +221,8 @@ · 19 unmodified lines
221221 "escape": "buffer_search::Dismiss",
222222 "tab": "buffer_search::FocusEditor",
223223 "enter": "search::SelectNextMatch",
224− "shift-enter": "search::SelectPrevMatch"
224+ "shift-enter": "search::SelectPrevMatch",
225+ "alt-enter": "search::SelectAllMatches"
225226 }
226227 },
227228 {
@@ -242,6 +243,7 @@ · 14 unmodified lines
242243 "cmd-f": "project_search::ToggleFocus",
243244 "cmd-g": "search::SelectNextMatch",
244245 "cmd-shift-g": "search::SelectPrevMatch",
246+ "alt-enter": "search::SelectAllMatches",
245247 "alt-cmd-c": "search::ToggleCaseSensitive",
246248 "alt-cmd-w": "search::ToggleWholeWord",
247249 "alt-cmd-r": "search::ToggleRegex"
crates/editor/src/items.rs+32−5
@@ -887,10 +887,20 @@ pub(crate) enum BufferSearchHighlights {} · 886 unmodified lines
887887 impl SearchableItem for Editor {
888888 type Match = Range<Anchor>;
889889
890− fn to_search_event(event: &Self::Event) -> Option<SearchEvent> {
890+ fn to_search_event(
891+ &mut self,
892+ event: &Self::Event,
893+ _: &mut ViewContext<Self>,
894+ ) -> Option<SearchEvent> {
891895 match event {
892896 Event::BufferEdited => Some(SearchEvent::MatchesInvalidated),
893− Event::SelectionsChanged { .. } => Some(SearchEvent::ActiveMatchChanged),
897+ Event::SelectionsChanged { .. } => {
898+ if self.selections.disjoint_anchors().len() == 1 {
899+ Some(SearchEvent::ActiveMatchChanged)
900+ } else {
901+ None
902+ }
903+ }
894904 _ => None,
895905 }
896906 }
@@ -941,6 +951,11 @@ impl SearchableItem for Editor { · 44 unmodified lines
941951 });
942952 }
943953
954+ fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) {
955+ self.unfold_ranges(matches.clone(), false, false, cx);
956+ self.change_selections(None, cx, |s| s.select_ranges(matches));
957+ }
958+
944959 fn match_index_for_direction(
945960 &mut self,
946961 matches: &Vec<Range<Anchor>>,
@@ -949,8 +964,16 @@ impl SearchableItem for Editor { · 2 unmodified lines
949964 cx: &mut ViewContext<Self>,
950965 ) -> usize {
951966 let buffer = self.buffer().read(cx).snapshot(cx);
952− let cursor = self.selections.newest_anchor().head();
953− if matches[current_index].start.cmp(&cursor, &buffer).is_gt() {
967+ let current_index_position = if self.selections.disjoint_anchors().len() == 1 {
968+ self.selections.newest_anchor().head()
969+ } else {
970+ matches[current_index].start
971+ };
972+ if matches[current_index]
973+ .start
974+ .cmp(&current_index_position, &buffer)
975+ .is_gt()
976+ {
954977 if direction == Direction::Prev {
955978 if current_index == 0 {
956979 current_index = matches.len() - 1;
@@ -958,7 +981,11 @@ impl SearchableItem for Editor { · 1 unmodified line
958981 current_index -= 1;
959982 }
960983 }
961− } else if matches[current_index].end.cmp(&cursor, &buffer).is_lt() {
984+ } else if matches[current_index]
985+ .end
986+ .cmp(&current_index_position, &buffer)
987+ .is_lt()
988+ {
962989 if direction == Direction::Next {
963990 current_index = 0;
964991 }
crates/editor/src/selections_collection.rs+2−2
@@ -16,13 +16,13 @@ use crate::{ · 15 unmodified lines
1616 Anchor, DisplayPoint, ExcerptId, MultiBuffer, MultiBufferSnapshot, SelectMode, ToOffset,
1717 };
1818
19−#[derive(Clone)]
19+#[derive(Debug, Clone)]
2020 pub struct PendingSelection {
2121 pub selection: Selection<Anchor>,
2222 pub mode: SelectMode,
2323 }
2424
25−#[derive(Clone)]
25+#[derive(Debug, Clone)]
2626 pub struct SelectionsCollection {
2727 display_map: ModelHandle<DisplayMap>,
2828 buffer: ModelHandle<MultiBuffer>,
crates/feedback/src/feedback_editor.rs+12−2
@@ -362,8 +362,13 @@ impl Item for FeedbackEditor { · 361 unmodified lines
362362 impl SearchableItem for FeedbackEditor {
363363 type Match = Range<Anchor>;
364364
365− fn to_search_event(event: &Self::Event) -> Option<workspace::searchable::SearchEvent> {
366− Editor::to_search_event(event)
365+ fn to_search_event(
366+ &mut self,
367+ event: &Self::Event,
368+ cx: &mut ViewContext<Self>,
369+ ) -> Option<workspace::searchable::SearchEvent> {
370+ self.editor
371+ .update(cx, |editor, cx| editor.to_search_event(event, cx))
367372 }
368373
369374 fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
@@ -391,6 +396,11 @@ impl SearchableItem for FeedbackEditor { · 21 unmodified lines
391396 .update(cx, |editor, cx| editor.activate_match(index, matches, cx))
392397 }
393398
399+ fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) {
400+ self.editor
401+ .update(cx, |e, cx| e.select_matches(matches, cx))
402+ }
403+
394404 fn find_matches(
395405 &mut self,
396406 query: project::search::SearchQuery,
crates/language_tools/src/lsp_log.rs+12−2
@@ -467,8 +467,13 @@ impl Item for LspLogView { · 466 unmodified lines
467467 impl SearchableItem for LspLogView {
468468 type Match = <Editor as SearchableItem>::Match;
469469
470− fn to_search_event(event: &Self::Event) -> Option<workspace::searchable::SearchEvent> {
471− Editor::to_search_event(event)
470+ fn to_search_event(
471+ &mut self,
472+ event: &Self::Event,
473+ cx: &mut ViewContext<Self>,
474+ ) -> Option<workspace::searchable::SearchEvent> {
475+ self.editor
476+ .update(cx, |editor, cx| editor.to_search_event(event, cx))
472477 }
473478
474479 fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
@@ -494,6 +499,11 @@ impl SearchableItem for LspLogView { · 19 unmodified lines
494499 .update(cx, |e, cx| e.activate_match(index, matches, cx))
495500 }
496501
502+ fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) {
503+ self.editor
504+ .update(cx, |e, cx| e.select_matches(matches, cx))
505+ }
506+
497507 fn find_matches(
498508 &mut self,
499509 query: project::search::SearchQuery,
crates/search/src/buffer_search.rs+199−12
@@ -1,6 +1,6 @@
11 use crate::{
2− SearchOption, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive, ToggleRegex,
3− ToggleWholeWord,
2+ SearchOption, SelectAllMatches, SelectNextMatch, SelectPrevMatch, ToggleCaseSensitive,
3+ ToggleRegex, ToggleWholeWord,
44 };
55 use collections::HashMap;
66 use editor::Editor;
@@ -39,8 +39,10 @@ pub fn init(cx: &mut AppContext) { · 32 unmodified lines
3939 cx.add_action(BufferSearchBar::focus_editor);
4040 cx.add_action(BufferSearchBar::select_next_match);
4141 cx.add_action(BufferSearchBar::select_prev_match);
42+ cx.add_action(BufferSearchBar::select_all_matches);
4243 cx.add_action(BufferSearchBar::select_next_match_on_pane);
4344 cx.add_action(BufferSearchBar::select_prev_match_on_pane);
45+ cx.add_action(BufferSearchBar::select_all_matches_on_pane);
4446 cx.add_action(BufferSearchBar::handle_editor_cancel);
4547 add_toggle_option_action::<ToggleCaseSensitive>(SearchOption::CaseSensitive, cx);
4648 add_toggle_option_action::<ToggleWholeWord>(SearchOption::WholeWord, cx);
@@ -66,7 +68,7 @@ pub struct BufferSearchBar { · 19 unmodified lines
6668 active_searchable_item: Option<Box<dyn SearchableItemHandle>>,
6769 active_match_index: Option<usize>,
6870 active_searchable_item_subscription: Option<Subscription>,
69− seachable_items_with_matches:
71+ searchable_items_with_matches:
7072 HashMap<Box<dyn WeakSearchableItemHandle>, Vec<Box<dyn Any + Send>>>,
7173 pending_search: Option<Task<()>>,
7274 case_sensitive: bool,
@@ -118,7 +120,7 @@ impl View for BufferSearchBar { · 45 unmodified lines
118120 .with_children(self.active_searchable_item.as_ref().and_then(
119121 |searchable_item| {
120122 let matches = self
121− .seachable_items_with_matches
123+ .searchable_items_with_matches
122124 .get(&searchable_item.downgrade())?;
123125 let message = if let Some(match_ix) = self.active_match_index {
124126 format!("{}/{}", match_ix + 1, matches.len())
@@ -146,6 +148,7 @@ impl View for BufferSearchBar { · 21 unmodified lines
146148 Flex::row()
147149 .with_child(self.render_nav_button("<", Direction::Prev, cx))
148150 .with_child(self.render_nav_button(">", Direction::Next, cx))
151+ .with_child(self.render_action_button("Select All", cx))
149152 .aligned(),
150153 )
151154 .with_child(
@@ -249,7 +252,7 @@ impl BufferSearchBar { · 97 unmodified lines
249252 active_searchable_item: None,
250253 active_searchable_item_subscription: None,
251254 active_match_index: None,
252− seachable_items_with_matches: Default::default(),
255+ searchable_items_with_matches: Default::default(),
253256 case_sensitive: false,
254257 whole_word: false,
255258 regex: false,
@@ -265,7 +268,7 @@ impl BufferSearchBar { · 9 unmodified lines
265268
266269 pub fn dismiss(&mut self, _: &Dismiss, cx: &mut ViewContext<Self>) {
267270 self.dismissed = true;
268− for searchable_item in self.seachable_items_with_matches.keys() {
271+ for searchable_item in self.searchable_items_with_matches.keys() {
269272 if let Some(searchable_item) =
270273 WeakSearchableItemHandle::upgrade(searchable_item.as_ref(), cx)
271274 {
@@ -401,6 +404,37 @@ impl BufferSearchBar { · 129 unmodified lines
401404 .into_any()
402405 }
403406
407+ fn render_action_button(
408+ &self,
409+ icon: &'static str,
410+ cx: &mut ViewContext<Self>,
411+ ) -> AnyElement<Self> {
412+ let tooltip = "Select All Matches";
413+ let tooltip_style = theme::current(cx).tooltip.clone();
414+ let action_type_id = 0_usize;
415+
416+ enum ActionButton {}
417+ MouseEventHandler::<ActionButton, _>::new(action_type_id, cx, |state, cx| {
418+ let theme = theme::current(cx);
419+ let style = theme.search.action_button.style_for(state);
420+ Label::new(icon, style.text.clone())
421+ .contained()
422+ .with_style(style.container)
423+ })
424+ .on_click(MouseButton::Left, move |_, this, cx| {
425+ this.select_all_matches(&SelectAllMatches, cx)
426+ })
427+ .with_cursor_style(CursorStyle::PointingHand)
428+ .with_tooltip::<ActionButton>(
429+ action_type_id,
430+ tooltip.to_string(),
431+ Some(Box::new(SelectAllMatches)),
432+ tooltip_style,
433+ cx,
434+ )
435+ .into_any()
436+ }
437+
404438 fn render_close_button(
405439 &self,
406440 theme: &theme::Search,
@@ -488,11 +522,25 @@ impl BufferSearchBar { · 81 unmodified lines
488522 self.select_match(Direction::Prev, cx);
489523 }
490524
525+ fn select_all_matches(&mut self, _: &SelectAllMatches, cx: &mut ViewContext<Self>) {
526+ if !self.dismissed {
527+ if let Some(searchable_item) = self.active_searchable_item.as_ref() {
528+ if let Some(matches) = self
529+ .searchable_items_with_matches
530+ .get(&searchable_item.downgrade())
531+ {
532+ searchable_item.select_matches(matches, cx);
533+ self.focus_editor(&FocusEditor, cx);
534+ }
535+ }
536+ }
537+ }
538+
491539 pub fn select_match(&mut self, direction: Direction, cx: &mut ViewContext<Self>) {
492540 if let Some(index) = self.active_match_index {
493541 if let Some(searchable_item) = self.active_searchable_item.as_ref() {
494542 if let Some(matches) = self
495− .seachable_items_with_matches
543+ .searchable_items_with_matches
496544 .get(&searchable_item.downgrade())
497545 {
498546 let new_match_index =
@@ -524,6 +572,16 @@ impl BufferSearchBar { · 25 unmodified lines
524572 }
525573 }
526574
575+ fn select_all_matches_on_pane(
576+ pane: &mut Pane,
577+ action: &SelectAllMatches,
578+ cx: &mut ViewContext<Pane>,
579+ ) {
580+ if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
581+ search_bar.update(cx, |bar, cx| bar.select_all_matches(action, cx));
582+ }
583+ }
584+
527585 fn on_query_editor_event(
528586 &mut self,
529587 _: ViewHandle<Editor>,
@@ -547,7 +605,7 @@ impl BufferSearchBar { · 17 unmodified lines
547605
548606 fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
549607 let mut active_item_matches = None;
550− for (searchable_item, matches) in self.seachable_items_with_matches.drain() {
608+ for (searchable_item, matches) in self.searchable_items_with_matches.drain() {
551609 if let Some(searchable_item) =
552610 WeakSearchableItemHandle::upgrade(searchable_item.as_ref(), cx)
553611 {
@@ -559,7 +617,7 @@ impl BufferSearchBar { · 5 unmodified lines
559617 }
560618 }
561619
562− self.seachable_items_with_matches
620+ self.searchable_items_with_matches
563621 .extend(active_item_matches);
564622 }
565623
@@ -605,13 +663,13 @@ impl BufferSearchBar { · 39 unmodified lines
605663 if let Some(active_searchable_item) =
606664 WeakSearchableItemHandle::upgrade(active_searchable_item.as_ref(), cx)
607665 {
608− this.seachable_items_with_matches
666+ this.searchable_items_with_matches
609667 .insert(active_searchable_item.downgrade(), matches);
610668
611669 this.update_match_index(cx);
612670 if !this.dismissed {
613671 let matches = this
614− .seachable_items_with_matches
672+ .searchable_items_with_matches
615673 .get(&active_searchable_item.downgrade())
616674 .unwrap();
617675 active_searchable_item.update_matches(matches, cx);
@@ -637,7 +695,7 @@ impl BufferSearchBar { · 19 unmodified lines
637695 .as_ref()
638696 .and_then(|searchable_item| {
639697 let matches = self
640− .seachable_items_with_matches
698+ .searchable_items_with_matches
641699 .get(&searchable_item.downgrade())?;
642700 searchable_item.active_match_index(matches, cx)
643701 });
@@ -966,4 +1024,133 @@ mod tests { · 322 unmodified lines
9661024 assert_eq!(search_bar.active_match_index, Some(2));
9671025 });
9681026 }
1027+
1028+ #[gpui::test]
1029+ async fn test_search_select_all_matches(cx: &mut TestAppContext) {
1030+ crate::project_search::tests::init_test(cx);
1031+
1032+ let buffer_text = r#"
1033+ A regular expression (shortened as regex or regexp;[1] also referred to as
1034+ rational expression[2][3]) is a sequence of characters that specifies a search
1035+ pattern in text. Usually such patterns are used by string-searching algorithms
1036+ for "find" or "find and replace" operations on strings, or for input validation.
1037+ "#
1038+ .unindent();
1039+ let expected_query_matches_count = buffer_text
1040+ .chars()
1041+ .filter(|c| c.to_ascii_lowercase() == 'a')
1042+ .count();
1043+ assert!(
1044+ expected_query_matches_count > 1,
1045+ "Should pick a query with multiple results"
1046+ );
1047+ let buffer = cx.add_model(|cx| Buffer::new(0, buffer_text, cx));
1048+ let (window_id, _root_view) = cx.add_window(|_| EmptyView);
1049+
1050+ let editor = cx.add_view(window_id, |cx| Editor::for_buffer(buffer.clone(), None, cx));
1051+
1052+ let search_bar = cx.add_view(window_id, |cx| {
1053+ let mut search_bar = BufferSearchBar::new(cx);
1054+ search_bar.set_active_pane_item(Some(&editor), cx);
1055+ search_bar.show(false, true, cx);
1056+ search_bar
1057+ });
1058+
1059+ search_bar.update(cx, |search_bar, cx| {
1060+ search_bar.set_query("a", cx);
1061+ });
1062+
1063+ editor.next_notification(cx).await;
1064+ let initial_selections = editor.update(cx, |editor, cx| {
1065+ let initial_selections = editor.selections.display_ranges(cx);
1066+ assert_eq!(
1067+ initial_selections.len(), 1,
1068+ "Expected to have only one selection before adding carets to all matches, but got: {initial_selections:?}",
1069+ );
1070+ initial_selections
1071+ });
1072+ search_bar.update(cx, |search_bar, _| {
1073+ assert_eq!(search_bar.active_match_index, Some(0));
1074+ });
1075+
1076+ search_bar.update(cx, |search_bar, cx| {
1077+ search_bar.select_all_matches(&SelectAllMatches, cx);
1078+ let all_selections =
1079+ editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
1080+ assert_eq!(
1081+ all_selections.len(),
1082+ expected_query_matches_count,
1083+ "Should select all `a` characters in the buffer, but got: {all_selections:?}"
1084+ );
1085+ });
1086+ search_bar.update(cx, |search_bar, _| {
1087+ assert_eq!(
1088+ search_bar.active_match_index,
1089+ Some(0),
1090+ "Match index should not change after selecting all matches"
1091+ );
1092+ });
1093+
1094+ search_bar.update(cx, |search_bar, cx| {
1095+ search_bar.select_next_match(&SelectNextMatch, cx);
1096+ let all_selections =
1097+ editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
1098+ assert_eq!(
1099+ all_selections.len(),
1100+ 1,
1101+ "On next match, should deselect items and select the next match"
1102+ );
1103+ assert_ne!(
1104+ all_selections, initial_selections,
1105+ "Next match should be different from the first selection"
1106+ );
1107+ });
1108+ search_bar.update(cx, |search_bar, _| {
1109+ assert_eq!(
1110+ search_bar.active_match_index,
1111+ Some(1),
1112+ "Match index should be updated to the next one"
1113+ );
1114+ });
1115+
1116+ search_bar.update(cx, |search_bar, cx| {
1117+ search_bar.select_all_matches(&SelectAllMatches, cx);
1118+ let all_selections =
1119+ editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
1120+ assert_eq!(
1121+ all_selections.len(),
1122+ expected_query_matches_count,
1123+ "Should select all `a` characters in the buffer, but got: {all_selections:?}"
1124+ );
1125+ });
1126+ search_bar.update(cx, |search_bar, _| {
1127+ assert_eq!(
1128+ search_bar.active_match_index,
1129+ Some(1),
1130+ "Match index should not change after selecting all matches"
1131+ );
1132+ });
1133+
1134+ search_bar.update(cx, |search_bar, cx| {
1135+ search_bar.select_prev_match(&SelectPrevMatch, cx);
1136+ let all_selections =
1137+ editor.update(cx, |editor, cx| editor.selections.display_ranges(cx));
1138+ assert_eq!(
1139+ all_selections.len(),
1140+ 1,
1141+ "On previous match, should deselect items and select the previous item"
1142+ );
1143+ assert_eq!(
1144+ all_selections, initial_selections,
1145+ "Previous match should be the same as the first selection"
1146+ );
1147+ });
1148+ search_bar.update(cx, |search_bar, _| {
1149+ assert_eq!(
1150+ search_bar.active_match_index,
1151+ Some(0),
1152+ "Match index should be updated to the previous one"
1153+ );
1154+ });
1155+ }
9691156 }
crates/search/src/search.rs+2−1
@@ -17,7 +17,8 @@ actions!( · 16 unmodified lines
1717 ToggleCaseSensitive,
1818 ToggleRegex,
1919 SelectNextMatch,
20− SelectPrevMatch
20+ SelectPrevMatch,
21+ SelectAllMatches,
2122 ]
2223 );
2324
crates/terminal/src/terminal.rs+15−0
@@ -908,6 +908,21 @@ impl Terminal { · 907 unmodified lines
908908 }
909909 }
910910
911+ pub fn select_matches(&mut self, matches: Vec<RangeInclusive<Point>>) {
912+ let matches_to_select = self
913+ .matches
914+ .iter()
915+ .filter(|self_match| matches.contains(self_match))
916+ .cloned()
917+ .collect::<Vec<_>>();
918+ for match_to_select in matches_to_select {
919+ self.set_selection(Some((
920+ make_selection(&match_to_select),
921+ *match_to_select.end(),
922+ )));
923+ }
924+ }
925+
911926 fn set_selection(&mut self, selection: Option<(Selection, Point)>) {
912927 self.events
913928 .push_back(InternalEvent::SetSelection(selection));
crates/terminal_view/src/terminal_view.rs+12−1
@@ -647,7 +647,11 @@ impl SearchableItem for TerminalView { · 646 unmodified lines
647647 }
648648
649649 /// Convert events raised by this item into search-relevant events (if applicable)
650− fn to_search_event(event: &Self::Event) -> Option<SearchEvent> {
650+ fn to_search_event(
651+ &mut self,
652+ event: &Self::Event,
653+ _: &mut ViewContext<Self>,
654+ ) -> Option<SearchEvent> {
651655 match event {
652656 Event::Wakeup => Some(SearchEvent::MatchesInvalidated),
653657 Event::SelectionsChanged => Some(SearchEvent::ActiveMatchChanged),
@@ -682,6 +686,13 @@ impl SearchableItem for TerminalView { · 28 unmodified lines
682686 cx.notify();
683687 }
684688
689+ /// Add selections for all matches given.
690+ fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) {
691+ self.terminal()
692+ .update(cx, |term, _| term.select_matches(matches));
693+ cx.notify();
694+ }
695+
685696 /// Get all of the matches for this query, should be done on the background
686697 fn find_matches(
687698 &mut self,
crates/theme/src/theme.rs+1−0
@@ -379,6 +379,7 @@ pub struct Search { · 378 unmodified lines
379379 pub invalid_include_exclude_editor: ContainerStyle,
380380 pub include_exclude_inputs: ContainedText,
381381 pub option_button: Toggleable<Interactive<ContainedText>>,
382+ pub action_button: Interactive<ContainedText>,
382383 pub match_background: Color,
383384 pub match_index: ContainedText,
384385 pub results_status: TextStyle,
crates/workspace/src/searchable.rs+16−3
@@ -37,7 +37,11 @@ pub trait SearchableItem: Item { · 36 unmodified lines
3737 regex: true,
3838 }
3939 }
40− fn to_search_event(event: &Self::Event) -> Option<SearchEvent>;
40+ fn to_search_event(
41+ &mut self,
42+ event: &Self::Event,
43+ cx: &mut ViewContext<Self>,
44+ ) -> Option<SearchEvent>;
4145 fn clear_matches(&mut self, cx: &mut ViewContext<Self>);
4246 fn update_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>);
4347 fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String;
@@ -47,6 +51,7 @@ pub trait SearchableItem: Item { · 3 unmodified lines
4751 matches: Vec<Self::Match>,
4852 cx: &mut ViewContext<Self>,
4953 );
54+ fn select_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>);
5055 fn match_index_for_direction(
5156 &mut self,
5257 matches: &Vec<Self::Match>,
@@ -102,6 +107,7 @@ pub trait SearchableItemHandle: ItemHandle { · 49 unmodified lines
102107 matches: &Vec<Box<dyn Any + Send>>,
103108 cx: &mut WindowContext,
104109 );
110+ fn select_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut WindowContext);
105111 fn match_index_for_direction(
106112 &self,
107113 matches: &Vec<Box<dyn Any + Send>>,
@@ -139,8 +145,9 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> { · 31 unmodified lines
139145 cx: &mut WindowContext,
140146 handler: Box<dyn Fn(SearchEvent, &mut WindowContext)>,
141147 ) -> Subscription {
142− cx.subscribe(self, move |_, event, cx| {
143− if let Some(search_event) = T::to_search_event(event) {
148+ cx.subscribe(self, move |handle, event, cx| {
149+ let search_event = handle.update(cx, |handle, cx| handle.to_search_event(event, cx));
150+ if let Some(search_event) = search_event {
144151 handler(search_event, cx)
145152 }
146153 })
@@ -165,6 +172,12 @@ impl<T: SearchableItem> SearchableItemHandle for ViewHandle<T> { · 18 unmodified lines
165172 let matches = downcast_matches(matches);
166173 self.update(cx, |this, cx| this.activate_match(index, matches, cx));
167174 }
175+
176+ fn select_matches(&self, matches: &Vec<Box<dyn Any + Send>>, cx: &mut WindowContext) {
177+ let matches = downcast_matches(matches);
178+ self.update(cx, |this, cx| this.select_matches(matches, cx));
179+ }
180+
168181 fn match_index_for_direction(
169182 &self,
170183 matches: &Vec<Box<dyn Any + Send>>,
styles/src/style_tree/search.ts+29−0
@@ -83,6 +83,35 @@ export default function search(): any { · 82 unmodified lines
8383 },
8484 },
8585 }),
86+ action_button: interactive({
87+ base: {
88+ ...text(theme.highest, "mono", "on"),
89+ background: background(theme.highest, "on"),
90+ corner_radius: 6,
91+ border: border(theme.highest, "on"),
92+ margin: {
93+ right: 4,
94+ },
95+ padding: {
96+ bottom: 2,
97+ left: 10,
98+ right: 10,
99+ top: 2,
100+ },
101+ },
102+ state: {
103+ hovered: {
104+ ...text(theme.highest, "mono", "on", "hovered"),
105+ background: background(theme.highest, "on", "hovered"),
106+ border: border(theme.highest, "on", "hovered"),
107+ },
108+ clicked: {
109+ ...text(theme.highest, "mono", "on", "pressed"),
110+ background: background(theme.highest, "on", "pressed"),
111+ border: border(theme.highest, "on", "pressed"),
112+ },
113+ },
114+ }),
86115 editor,
87116 invalid_editor: {
88117 ...editor,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t