Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Reverse range of pending selection if required (#38410)
Lukas Wirthb1aa2723e9b1
diff --git a/crates/editor/src/selections_collection.rs b/crates/editor/src/selections_collection.rsindex e562be10e92..4343443ff8c 100644--- a/crates/editor/src/selections_collection.rs+++ b/crates/editor/src/selections_collection.rs@@ -469,13 +469,24 @@ impl<'a> MutableSelectionsCollection<'a> {}pub(crate) fn set_pending_anchor_range(&mut self, range: Range<Anchor>, mode: SelectMode) {+ let buffer = self.buffer.read(self.cx).snapshot(self.cx);self.collection.pending = Some(PendingSelection {- selection: Selection {- id: post_inc(&mut self.collection.next_selection_id),- start: range.start,- end: range.end,- reversed: false,- goal: SelectionGoal::None,+ selection: {+ let mut start = range.start;+ let mut end = range.end;+ let reversed = if start.cmp(&end, &buffer).is_gt() {+ mem::swap(&mut start, &mut end);+ true+ } else {+ false+ };+ Selection {+ id: post_inc(&mut self.collection.next_selection_id),+ start,+ end,+ reversed,+ goal: SelectionGoal::None,+ }},mode,});