@@ -290,11 +290,12 @@ impl Selection {
293+ /// Adds a new range to the selection and makes it the primary range.
293 pub fn push(mut self, range: Range) -> Self {
294 pub fn push(mut self, range: Range) -> Self {
294 self.ranges.push(range);
295 self.ranges.push(range);
296+ self.set_primary_index(self.ranges().len() - 1);
295 self.normalize()
297 self.normalize()
299 /// Map selections over a set of changes. Useful for adjusting the selection position after
300 /// Map selections over a set of changes. Useful for adjusting the selection position after
300 /// applying changes to a document.
301 /// applying changes to a document.
@@ -320,6 +321,11 @@ impl Selection {
320 self.primary_index
321 self.primary_index
324+ pub fn set_primary_index(&mut self, idx: usize) {
325+ assert!(idx < self.ranges.len());
326+ self.primary_index = idx;
323 #[must_use]
329 #[must_use]
324 /// Constructs a selection holding a single range.
330 /// Constructs a selection holding a single range.
325 pub fn single(anchor: usize, head: usize) -> Self {
331 pub fn single(anchor: usize, head: usize) -> Self {