Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Update visible suggestion if edit occurs outside the current editor
Antonio Scandurradcd8bdfc882d
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex d9b2b1a8dbe..0474371af63 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -6411,6 +6411,9 @@ impl Editor {multi_buffer::Event::Edited => {self.refresh_active_diagnostics(cx);self.refresh_code_actions(cx);+ if self.has_active_copilot_suggestion(cx) {+ self.update_visible_copilot_suggestion(cx);+ }cx.emit(Event::BufferEdited);}multi_buffer::Event::ExcerptsAdded {diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 7f7f7ec7eda..8c882f3ea81 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -6026,12 +6026,41 @@ async fn test_copilot(deterministic: Arc<Deterministic>, cx: &mut gpui::TestAppCassert!(editor.has_active_copilot_suggestion(cx));assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");assert_eq!(editor.text(cx), "one.c\ntwo\nthree\n");+ });++ // If an edit occurs outside of this editor, the suggestion is still correctly interpolated.+ cx.update_buffer(|buffer, cx| buffer.edit([(5..5, "o")], None, cx));+ cx.update_editor(|editor, cx| {+ assert!(editor.has_active_copilot_suggestion(cx));+ assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");+ assert_eq!(editor.text(cx), "one.co\ntwo\nthree\n");// Tabbing when there is an active suggestion inserts it.editor.tab(&Default::default(), cx);assert!(!editor.has_active_copilot_suggestion(cx));assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");assert_eq!(editor.text(cx), "one.copilot2\ntwo\nthree\n");++ // When undoing the previously active suggestion is shown again.+ editor.undo(&Default::default(), cx);+ assert!(editor.has_active_copilot_suggestion(cx));+ assert_eq!(editor.display_text(cx), "one.copilot2\ntwo\nthree\n");+ assert_eq!(editor.text(cx), "one.co\ntwo\nthree\n");++ // Hide suggestion.+ editor.cancel(&Default::default(), cx);+ assert!(!editor.has_active_copilot_suggestion(cx));+ assert_eq!(editor.display_text(cx), "one.co\ntwo\nthree\n");+ assert_eq!(editor.text(cx), "one.co\ntwo\nthree\n");+ });++ // If an edit occurs outside of this editor but no suggestion is being shown,+ // we won't make it visible.+ cx.update_buffer(|buffer, cx| buffer.edit([(6..6, "p")], None, cx));+ cx.update_editor(|editor, cx| {+ assert!(!editor.has_active_copilot_suggestion(cx));+ assert_eq!(editor.display_text(cx), "one.cop\ntwo\nthree\n");+ assert_eq!(editor.text(cx), "one.cop\ntwo\nthree\n");});}