Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix infinite loop in select all matches
Mikayla03d4191685d3
diff --git a/assets/keymaps/default.json b/assets/keymaps/default.jsonindex 8ac4fcbf8dc..2fa5c0980f3 100644--- a/assets/keymaps/default.json+++ b/assets/keymaps/default.json@@ -294,7 +294,7 @@"replace_newest": false}],- "cmd-shift-d": "editor::SelectNextAll",+ "cmd-shift-d": "editor::SelectAllMatches","ctrl-cmd-d": ["editor::SelectPrevious",{diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex fa0663f2cf9..cc4af44a1a8 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -130,7 +130,7 @@ pub struct SelectPrevious {}#[derive(Clone, Deserialize, PartialEq, Default)]-pub struct SelectNextAll {+pub struct SelectAllMatches {#[serde(default)]pub replace_newest: bool,}@@ -331,7 +331,7 @@ impl_actions!([SelectNext,SelectPrevious,- SelectNextAll,+ SelectAllMatches,SelectToBeginningOfLine,SelectToEndOfLine,ToggleCodeActions,@@ -732,13 +732,22 @@ struct AddSelectionsState {stack: Vec<usize>,}-#[derive(Clone, Debug)]+#[derive(Clone)]struct SelectNextState {query: AhoCorasick,wordwise: bool,done: bool,}+impl std::fmt::Debug for SelectNextState {+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ f.debug_struct(std::any::type_name::<Self>())+ .field("wordwise", &self.wordwise)+ .field("done", &self.done)+ .finish()+ }+}+#[derive(Debug)]struct AutocloseRegion {selection_id: usize,@@ -5985,7 +5994,9 @@ impl Editor {.stream_find_iter(bytes_before_first_selection).map(|result| (0, result)),);+for (start_offset, query_match) in query_matches {+ (start_offset, &query_match);let query_match = query_match.unwrap(); // can only fail due to I/Olet offset_range =start_offset + query_match.start()..start_offset + query_match.end();@@ -5996,8 +6007,14 @@ impl Editor {|| (!movement::is_inside_word(&display_map, display_range.start)&& !movement::is_inside_word(&display_map, display_range.end)){- next_selected_range = Some(offset_range);- break;+ if selections+ .iter()+ .find(|selection| selection.equals(&offset_range))+ .is_none()+ {+ next_selected_range = Some(offset_range);+ break;+ }}}@@ -6046,7 +6063,7 @@ impl Editor {Ok(())}- pub fn select_all_matches(&mut self, action: &SelectNextAll, cx: &mut ViewContext<Self>) {+ pub fn select_all_matches(&mut self, action: &SelectAllMatches, cx: &mut ViewContext<Self>) {self.push_to_selection_history();let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));diff --git a/crates/text/src/selection.rs b/crates/text/src/selection.rsindex d4f55a043b3..205c27239d9 100644--- a/crates/text/src/selection.rs+++ b/crates/text/src/selection.rs@@ -100,6 +100,10 @@ impl Selection<usize> {reversed: false,}}++ pub fn equals(&self, offset_range: &Range<usize>) -> bool {+ self.start == offset_range.start && self.end == offset_range.end+ }}impl Selection<Anchor> {