Repository: helix-editor/helix
File: helix-term/src/commands.rs (Rust)

Code before:
        true,
        true,
        char::is_ascii_digit,
        1,
    );

    let mut amount = match increment_direction {
        IncrementDirection::Increase =>  cx.count() as i64,
        IncrementDirection::Decrease =>  -(cx.count() as i64),
    };

    let (view, doc) = current!(cx.editor);
    let selection = doc.selection(view.id);
    let text = doc.text().slice(..);


    let increase_by = match cx.register {
        Some(value) => match value.eq(&'#') {
            true => match increment_direction {
                IncrementDirection::Increase => 1,
                IncrementDirection::Decrease => -1,
            },
            false => 0,
        },
        None => 0,
    };

    let changes: Vec<_> = selection
        .ranges()
        .iter()
        .filter_map(|range| {
            let incrementor: Box<dyn Increment> =
                if let Some(incrementor) = DateTimeIncrementor::from_range(text, *range) {
                    Box::new(incrementor)
                } else if let Some(incrementor) = NumberIncrementor::from_range(text, *range) {
                    Box::new(incrementor)
                } else {
                    return None;
                };

            let (range, new_text) = incrementor.increment(amount);

            amount += increase_by;

            Some((range.from(), range.to(), Some(new_text)))
        })
        .collect();

    // Overlapping changes in a transaction will panic, so we need to find and remove them.
    // For example, if there are cursors on each of the year, month, and day of `2021-11-29`,
    // incrementing will give overlapping changes, with each change incrementing a different part of

Review comment (suggestion):
This can be simplified a bit:

```rs
let sign = match increment_direction {
    IncrementDirection::Increase => 1,
    IncrementDirection::Decrease => -1,
};
let mut amount = sign * cx.count() as i64;
let increase_by = if cx.register == Some('#') {
    sign
} else {
    0
};

Code after:
        true,
        char::is_ascii_digit,
        1,
    );

    // Increase by 1 if `IncrementDirection` is `Increase`
    // Decrease by 1 if `IncrementDirection` is `Decrease`
    let sign = match increment_direction {
        IncrementDirection::Increase => 1,
        IncrementDirection::Decrease => -1,
    };
    let mut amount = sign * cx.count() as i64;

    // If the register is `#` then increase or decrease the `amount` by 1 per element
    let increase_by = if cx.register == Some('#') { sign } else { 0 };

    let (view, doc) = current!(cx.editor);
    let selection = doc.selection(view.id);
    let text = doc.text().slice(..);

    let changes: Vec<_> = selection
        .ranges()
        .iter()
        .filter_map(|range| {
            let incrementor: Box<dyn Increment> =
                if let Some(incrementor) = DateTimeIncrementor::from_range(text, *range) {
                    Box::new(incrementor)
                } else if let Some(incrementor) = NumberIncrementor::from_range(text, *range) {
                    Box::new(incrementor)
                } else {
                    return None;
                };

            let (range, new_text) = incrementor.increment(amount);

            amount += increase_by;

            Some((range.from(), range.to(), Some(new_text)))
        })
        .collect();

    // Overlapping changes in a transaction will panic, so we need to find and remove them.
    // For example, if there are cursors on each of the year, month, and day of `2021-11-29`,
    // incrementing will give overlapping changes, with each change incrementing a different part of
    // the date. Since these conflict with each other we remove these changes from the transaction
    // so nothing happens.
    let mut overlapping_indexes = HashSet::new();
    for (i, changes) in changes.windows(2).enumerate() {
        if changes[0].1 > changes[1].0 {
            overlapping_indexes.insert(i);
            overlapping_indexes.insert(i + 1);