End pending selection when starting a transaction

Antonio Scandurra , Max Brunsfeld , and Nathan Sobo created

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

Change summary

crates/editor/src/lib.rs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

Detailed changes

crates/editor/src/lib.rs 🔗

@@ -670,8 +670,10 @@ impl Editor {
     }
 
     fn end_selection(&mut self, cx: &mut ViewContext<Self>) {
-        let selections = self.selections::<Point>(cx).collect::<Vec<_>>();
-        self.update_selections(selections, false, cx);
+        if self.pending_selection.is_some() {
+            let selections = self.selections::<usize>(cx).collect::<Vec<_>>();
+            self.update_selections(selections, false, cx);
+        }
     }
 
     pub fn is_selecting(&self) -> bool {
@@ -2404,7 +2406,8 @@ impl Editor {
         cx.notify();
     }
 
-    fn start_transaction(&self, cx: &mut ViewContext<Self>) {
+    fn start_transaction(&mut self, cx: &mut ViewContext<Self>) {
+        self.end_selection(cx);
         self.buffer.update(cx, |buffer, _| {
             buffer
                 .start_transaction(Some(self.selection_set_id))