Empty last selection on cancel

Antonio Scandurra and Nathan Sobo created

Co-Authored-By: Nathan Sobo <nathan@zed.dev>

Change summary

zed/src/editor/buffer_view.rs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

Detailed changes

zed/src/editor/buffer_view.rs 🔗

@@ -558,7 +558,11 @@ impl BufferView {
                 self.update_selections(vec![pending_selection], true, ctx);
             }
         } else {
-            let oldest_selection = selections.iter().min_by_key(|s| s.id).unwrap().clone();
+            let mut oldest_selection = selections.iter().min_by_key(|s| s.id).unwrap().clone();
+            if selections.len() == 1 {
+                oldest_selection.start = oldest_selection.head().clone();
+                oldest_selection.end = oldest_selection.head().clone();
+            }
             self.update_selections(vec![oldest_selection], true, ctx);
         }
     }