@@ -290,11 +290,12 @@ impl Selection {
290290 }
291291 }
292292
293+ /// Adds a new range to the selection and makes it the primary range.
293294 pub fn push(mut self, range: Range) -> Self {
294295 self.ranges.push(range);
296+ self.set_primary_index(self.ranges().len() - 1);
295297 self.normalize()
296298 }
297− // replace_range
298299
299300 /// Map selections over a set of changes. Useful for adjusting the selection position after
300301 /// applying changes to a document.
@@ -320,6 +321,11 @@ impl Selection {
320321 self.primary_index
321322 }
322323
324+ pub fn set_primary_index(&mut self, idx: usize) {
325+ assert!(idx < self.ranges.len());
326+ self.primary_index = idx;
327+ }
328+
323329 #[must_use]
324330 /// Constructs a selection holding a single range.
325331 pub fn single(anchor: usize, head: usize) -> Self {