@@ -362,6 +362,11 @@ impl Selection {
363 /// Adds a new range to the selection and makes it the primary range.
363 /// Adds a new range to the selection and makes it the primary range.
364 pub fn remove(mut self, index: usize) -> Self {
364 pub fn remove(mut self, index: usize) -> Self {
366+ self.ranges.len() > 1,
367+ "can't remove the last range from a selection!"
365 self.ranges.remove(index);
370 self.ranges.remove(index);
366 if index < self.primary_index || self.primary_index == self.ranges.len() {
371 if index < self.primary_index || self.primary_index == self.ranges.len() {
367 self.primary_index -= 1;
372 self.primary_index -= 1;
@@ -369,6 +374,12 @@ impl Selection {
377+ /// Replace a range in the selection with a new range.
378+ pub fn replace(mut self, index: usize, range: Range) -> Self {
379+ self.ranges[index] = range;
372 /// Map selections over a set of changes. Useful for adjusting the selection position after
383 /// Map selections over a set of changes. Useful for adjusting the selection position after
373 /// applying changes to a document.
384 /// applying changes to a document.
374 pub fn map(self, changes: &ChangeSet) -> Self {
385 pub fn map(self, changes: &ChangeSet) -> Self {