diff options
author | Jason Rodney Hansen | 2021-11-21 17:38:41 +0000 |
---|---|---|
committer | Ivan Tham | 2021-12-05 08:22:58 +0000 |
commit | c9641fccedc51737a74ed47009279fa688462ea9 (patch) | |
tree | a057ce6a6a476224238dbb0341cbb8371e88497d /helix-term/src | |
parent | 2a0c685a7857a94db2ac61b586c92425da273ea7 (diff) |
Add `Increment` trait
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/commands.rs | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 639bbd83..6329dec7 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1,14 +1,13 @@ use helix_core::{ - comment, coords_at_pos, - date::DateIncrementor, - find_first_non_whitespace_char, find_root, graphemes, + comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes, history::UndoKind, + increment::date::DateIncrementor, + increment::{number::NumberIncrementor, Increment}, indent, indent::IndentStyle, line_ending::{get_line_ending_of_str, line_end_char_index, str_is_line_ending}, match_brackets, movement::{self, Direction}, - numbers::NumberIncrementor, object, pos_at_coords, regex::{self, Regex, RegexBuilder}, search, selection, surround, textobject, @@ -5804,23 +5803,18 @@ fn increment_impl(cx: &mut Context, amount: i64) { let text = doc.text(); let changes = selection.ranges().iter().filter_map(|range| { - if let Some(incrementor) = DateIncrementor::from_range(text.slice(..), *range) { - let new_text = incrementor.incremented_text(amount); - Some(( - incrementor.range.from(), - incrementor.range.to(), - Some(new_text), - )) + let incrementor: Option<Box<dyn Increment>> = if let Some(incrementor) = + DateIncrementor::from_range(text.slice(..), *range) + { + Some(Box::new(incrementor)) } else if let Some(incrementor) = NumberIncrementor::from_range(text.slice(..), *range) { - let new_text = incrementor.incremented_text(amount); - Some(( - incrementor.range.from(), - incrementor.range.to(), - Some(new_text), - )) + Some(Box::new(incrementor)) } else { None - } + }; + + let (range, new_text) = incrementor?.increment(amount); + Some((range.from(), range.to(), Some(new_text))) }); if changes.clone().count() > 0 { |