@@ -41,7 +41,7 @@ use crate::{
42use crate::job::{self, Job, Jobs};
42use crate::job::{self, Job, Jobs};
43use futures_util::{FutureExt, StreamExt};
43use futures_util::{FutureExt, StreamExt};
44−use std::num::NonZeroUsize;
44+use std::{collections::HashSet, num::NonZeroUsize};
45use std::{fmt, future::Future};
45use std::{fmt, future::Future};
@@ -5802,19 +5802,45 @@ fn increment_impl(cx: &mut Context, amount: i64) {
5802 let selection = doc.selection(view.id);
5802 let selection = doc.selection(view.id);
5803 let text = doc.text();
5803 let text = doc.text();
5805− let changes = selection.ranges().iter().filter_map(|range| {
5805+ let changes = selection
5808+ .filter_map(|range| {
5806− let incrementor: Box<dyn Increment> = if let Some(incrementor) =
5809+ let incrementor: Box<dyn Increment> = if let Some(incrementor) =
5807− DateTimeIncrementor::from_range(text.slice(..), *range)
5810+ DateTimeIncrementor::from_range(text.slice(..), *range)
5809− Box::new(incrementor)
5812+ Box::new(incrementor)
5810− } else if let Some(incrementor) = NumberIncrementor::from_range(text.slice(..), *range) {
5813+ } else if let Some(incrementor) = NumberIncrementor::from_range(text.slice(..), *range)
5811− Box::new(incrementor)
5815+ Box::new(incrementor)
5812− } else {
5816+ } else {
5813− return None;
5817+ return None;
5820+ let (range, new_text) = incrementor.increment(amount);
5822+ Some((range.from(), range.to(), Some(new_text)))
5824+ .collect::<Vec<_>>();
5816− let (range, new_text) = incrementor.increment(amount);
5826+ // Overlapping changes in a transaction will panic, so we need to find and remove them.
5817− Some((range.from(), range.to(), Some(new_text)))
5827+ // For example, if there are cursors on each of the year, month, and day of `2021-11-29`,
5828+ // incrementing will give overlapping changes, with each change incrementing a different part of
5829+ // the date. Since these conflict with each other we remove these changes from the transaction
5830+ // so nothing happens.
5831+ let mut overlapping_indexes = HashSet::new();
5832+ for (i, changes) in changes.windows(2).enumerate() {
5833+ if changes[0].1 > changes[1].0 {
5834+ overlapping_indexes.insert(i);
5835+ overlapping_indexes.insert(i + 1);
5838+ let changes = changes.into_iter().enumerate().filter_map(|(i, change)| {
5839+ if overlapping_indexes.contains(&i) {
5820 if changes.clone().count() > 0 {
5846 if changes.clone().count() > 0 {