Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Revert "Return the previous suggestion when replacing it"
Antonio Scandurra65fd605b828a
diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rsindex f54e2e980c5..c5e6b371edf 100644--- a/crates/editor/src/display_map.rs+++ b/crates/editor/src/display_map.rs@@ -7,7 +7,7 @@ mod wrap_map;use crate::{Anchor, AnchorRangeExt, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint};pub use block_map::{BlockMap, BlockPoint};use collections::{HashMap, HashSet};-use fold_map::{FoldMap, FoldOffset};+use fold_map::FoldMap;use gpui::{color::Color,fonts::{FontId, HighlightStyle},@@ -238,22 +238,19 @@ impl DisplayMap {&self,new_suggestion: Option<Suggestion<T>>,cx: &mut ModelContext<Self>,- ) -> Option<Suggestion<FoldOffset>>- where+ ) whereT: ToPoint,{let snapshot = self.buffer.read(cx).snapshot(cx);let edits = self.buffer_subscription.consume().into_inner();let tab_size = Self::tab_size(&self.buffer, cx);let (snapshot, edits) = self.fold_map.read(snapshot, edits);- let (snapshot, edits, old_suggestion) =- self.suggestion_map.replace(new_suggestion, snapshot, edits);+ let (snapshot, edits) = self.suggestion_map.replace(new_suggestion, snapshot, edits);let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);let (snapshot, edits) = self.wrap_map.update(cx, |map, cx| map.sync(snapshot, edits, cx));self.block_map.read(snapshot, edits);- old_suggestion}pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext<Self>) -> bool {diff --git a/crates/editor/src/display_map/suggestion_map.rs b/crates/editor/src/display_map/suggestion_map.rsindex 17dbae60316..ccc07bf591b 100644--- a/crates/editor/src/display_map/suggestion_map.rs+++ b/crates/editor/src/display_map/suggestion_map.rs@@ -79,11 +79,7 @@ impl SuggestionMap {new_suggestion: Option<Suggestion<T>>,fold_snapshot: FoldSnapshot,fold_edits: Vec<FoldEdit>,- ) -> (- SuggestionSnapshot,- Vec<SuggestionEdit>,- Option<Suggestion<FoldOffset>>,- )+ ) -> (SuggestionSnapshot, Vec<SuggestionEdit>)whereT: ToPoint,{@@ -103,8 +99,7 @@ impl SuggestionMap {let mut snapshot = self.0.lock();let mut patch = Patch::new(edits);- let old_suggestion = snapshot.suggestion.take();- if let Some(suggestion) = &old_suggestion {+ if let Some(suggestion) = snapshot.suggestion.take() {patch = patch.compose([SuggestionEdit {old: SuggestionOffset(suggestion.position.0)..SuggestionOffset(suggestion.position.0 + suggestion.text.len()),@@ -124,7 +119,7 @@ impl SuggestionMap {snapshot.suggestion = new_suggestion;snapshot.version += 1;- (snapshot.clone(), patch.into_inner(), old_suggestion)+ (snapshot.clone(), patch.into_inner())}pub fn sync(@@ -594,7 +589,7 @@ mod tests {let (suggestion_map, suggestion_snapshot) = SuggestionMap::new(fold_snapshot.clone());assert_eq!(suggestion_snapshot.text(), "abcdefghi");- let (suggestion_snapshot, _, _) = suggestion_map.replace(+ let (suggestion_snapshot, _) = suggestion_map.replace(Some(Suggestion {position: 3,text: "123\n456".into(),@@ -859,9 +854,7 @@ mod tests {};log::info!("replacing suggestion with {:?}", new_suggestion);- let (snapshot, edits, _) =- self.replace(new_suggestion, fold_snapshot, Default::default());- (snapshot, edits)+ self.replace(new_suggestion, fold_snapshot, Default::default())}}}diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 7431c868150..84d18bafe86 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -2881,11 +2881,9 @@ impl Editor {}fn hide_copilot_suggestion(&mut self, cx: &mut ViewContext<Self>) -> bool {- let old_suggestion = self- .display_map- .update(cx, |map, cx| map.replace_suggestion::<usize>(None, cx));-- if old_suggestion.is_some() {+ if self.has_active_copilot_suggestion(cx) {+ self.display_map+ .update(cx, |map, cx| map.replace_suggestion::<usize>(None, cx));cx.notify();true} else {