aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs38
-rw-r--r--helix-term/src/keymap.rs3
2 files changed, 41 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 74bc52fd..7ef8f56c 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -6,6 +6,7 @@ use helix_core::{
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},
register::Register,
@@ -354,6 +355,8 @@ impl Command {
shell_keep_pipe, "Filter selections with shell predicate",
suspend, "Suspend",
rename_symbol, "Rename symbol",
+ increment, "Increment",
+ decrement, "Decrement",
);
}
@@ -5459,3 +5462,38 @@ fn rename_symbol(cx: &mut Context) {
);
cx.push_layer(Box::new(prompt));
}
+
+/// Increment object under cursor by count.
+fn increment(cx: &mut Context) {
+ increment_impl(cx, cx.count() as i64);
+}
+
+/// Decrement object under cursor by count.
+fn decrement(cx: &mut Context) {
+ increment_impl(cx, -(cx.count() as i64));
+}
+
+/// Decrement object under cursor by `amount`.
+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 changes = selection.ranges().iter().filter_map(|range| {
+ let incrementor = NumberIncrementor::from_range(text.slice(..), *range)?;
+ let new_text = incrementor.incremented_text(amount);
+ Some((
+ incrementor.range.from(),
+ incrementor.range.to(),
+ Some(new_text),
+ ))
+ });
+
+ if changes.clone().count() > 0 {
+ let transaction = Transaction::change(doc.text(), changes);
+ let transaction = transaction.with_selection(selection.clone());
+
+ doc.apply(&transaction, view.id);
+ doc.append_changes_to_history(view.id);
+ }
+}
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index fdf43d87..bf3b594e 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -698,6 +698,9 @@ impl Default for Keymaps {
"A-!" => shell_append_output,
"$" => shell_keep_pipe,
"C-z" => suspend,
+
+ "C-a" => increment,
+ "C-x" => decrement,
});
let mut select = normal.clone();
select.merge_nodes(keymap!({ "Select mode"