Remove newest selection when adding a selection with a click count > 1

Nathan Sobo created

This prevents selections added in earlier clicks from being rendered under the pending selection.

Change summary

crates/editor/src/lib.rs | 10 ++++++++++
1 file changed, 10 insertions(+)

Detailed changes

crates/editor/src/lib.rs 🔗

@@ -751,6 +751,16 @@ impl Editor {
 
         if !add {
             self.update_selections::<usize>(Vec::new(), false, cx);
+        } else if click_count > 1 {
+            // Remove the newest selection since it was only added as part of this multi-click.
+            let newest_selection = self.newest_selection::<usize>(cx);
+            self.update_selections::<usize>(
+                self.selections(cx)
+                    .filter(|selection| selection.id != newest_selection.id)
+                    .collect(),
+                false,
+                cx,
+            )
         }
 
         self.pending_selection = Some(PendingSelection { selection, mode });