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

Agus Zubiaga and Danilo created

If a suggested edit is a single character insert or a single line
deletion, we'll show the diff popover to make it stand out more.

Release Notes:

- N/A

Co-authored-by: Danilo <danilo@zed.dev>

Change summary

crates/editor/src/element.rs | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)

Detailed changes

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,