Skip to content

Commit

Permalink
Small change
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhansen authored and pickfire committed Dec 5, 2021
1 parent 539c27e commit 461cd20
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5800,28 +5800,26 @@ fn decrement(cx: &mut Context) {
fn increment_impl(cx: &mut Context, amount: i64) {
let (view, doc) = current!(cx.editor);
let selection = doc.selection(view.id);
let text = doc.text();
let text = doc.text().slice(..);

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

Some((range.from(), range.to(), Some(new_text)))
})
.collect::<Vec<_>>();
.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`,
Expand Down

0 comments on commit 461cd20

Please sign in to comment.