Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Remove unnecessary cloning of selections (#46598)
Finn Evers5ddfcf09f742
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex de2e6b757bd..e2781436d49 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -15358,12 +15358,10 @@ impl Editor {let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));self.select_next_match_internal(&display_map, false, None, window, cx)?;- let Some(select_next_state) = self.select_next_state.as_mut() else {+ let Some(select_next_state) = self.select_next_state.as_mut().filter(|state| !state.done)+ else {return Ok(());};- if select_next_state.done {- return Ok(());- }let mut new_selections = Vec::new();@@ -15399,7 +15397,7 @@ impl Editor {return Ok(());}- self.unfold_ranges(&new_selections.clone(), false, false, cx);+ self.unfold_ranges(&new_selections, false, false, cx);self.change_selections(SelectionEffects::no_scroll(), window, cx, |selections| {selections.select_ranges(new_selections)});@@ -15421,8 +15419,7 @@ impl Editor {Some(Autoscroll::newest()),window,cx,- )?;- Ok(())+ )}pub fn select_previous(diff --git a/crates/editor/src/scroll/autoscroll.rs b/crates/editor/src/scroll/autoscroll.rsindex fc2ecb92051..068acffcad1 100644--- a/crates/editor/src/scroll/autoscroll.rs+++ b/crates/editor/src/scroll/autoscroll.rs@@ -207,21 +207,17 @@ impl Editor {let strategy = match autoscroll {Autoscroll::Strategy(strategy, _) => strategy,- Autoscroll::Next => {- let last_autoscroll = &self.scroll_manager.last_autoscroll;- if let Some(last_autoscroll) = last_autoscroll {- if self.scroll_manager.anchor.offset == last_autoscroll.0- && target_top == last_autoscroll.1- && target_bottom == last_autoscroll.2- {- last_autoscroll.3.next()- } else {- AutoscrollStrategy::default()- }- } else {- AutoscrollStrategy::default()- }- }+ Autoscroll::Next => self+ .scroll_manager+ .last_autoscroll+ .as_ref()+ .filter(|(offset, last_target_top, last_target_bottom, _)| {+ self.scroll_manager.anchor.offset == *offset+ && target_top == *last_target_top+ && target_bottom == *last_target_bottom+ })+ .map(|(_, _, _, strategy)| strategy.next())+ .unwrap_or_default(),};if let Autoscroll::Strategy(_, Some(anchor)) = autoscroll {target_top = anchor.to_display_point(&display_map).row().as_f64();