Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Show inline completion popover for hard to spot single edits (#23385)

Agus Zubiagae2c7934783c7
diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs
index e4f526a992b..072750c3d3f 100644
--- a/crates/editor/src/element.rs
+++ b/crates/editor/src/element.rs
@@ -3419,7 +3419,9 @@ impl EditorElement {
return None;
}
- if all_edits_insertions_or_deletions(edits, &editor_snapshot.buffer_snapshot) {
+ if !hard_to_spot_single_edit(&edits, &editor_snapshot.buffer_snapshot)
+ && all_edits_insertions_or_deletions(edits, &editor_snapshot.buffer_snapshot)
+ {
return None;
}
@@ -3428,6 +3430,7 @@ impl EditorElement {
else {
return None;
};
+
let line_count = text.lines().count() + 1;
let longest_row =
@@ -5198,6 +5201,26 @@ fn header_jump_data(
}
}
+/// Returns true if there's a single edit, that's either a single character
+/// insertion or a single line deletion.
+fn hard_to_spot_single_edit(
+ edits: &[(Range<Anchor>, String)],
+ snapshot: &MultiBufferSnapshot,
+) -> bool {
+ if let [(range, new_text)] = edits {
+ match new_text.len() {
+ 0 => {
+ let range = range.to_point(&snapshot);
+ range.start.row == range.end.row
+ }
+ 1 => true,
+ _ => false,
+ }
+ } else {
+ false
+ }
+}
+
fn all_edits_insertions_or_deletions(
edits: &Vec<(Range<Anchor>, String)>,
snapshot: &MultiBufferSnapshot,