aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
diff options
context:
space:
mode:
authorTeddy Wing2021-08-08 19:19:58 +0200
committerTeddy Wing2021-08-08 19:19:58 +0200
commit8c5f0c4a32321df2789b2f2b1992c5d190cd4b45 (patch)
treeefd3e6fbe495ae853d9d3c54e6b917378daec36e /incdec.pm
parent5faf72596a1f5d9e209e10ea35dae5570735ddb4 (diff)
downloadreadline-incdec-8c5f0c4a32321df2789b2f2b1992c5d190cd4b45.tar.bz2
incdec: Handle increments relative to the cursor position
This will increment the next number to the right of the given cursor position.
Diffstat (limited to 'incdec.pm')
-rw-r--r--incdec.pm8
1 files changed, 7 insertions, 1 deletions
diff --git a/incdec.pm b/incdec.pm
index 3c229a4..2dfeb74 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -9,7 +9,13 @@ sub incdec {
$point_position ||= 0;
$is_backward ||= 0;
- $line =~ s/(\d+)/$1+1/e;
+ my $line_part = substr $line, $point_position;
+
+ $line_part =~ s/(\d+)/$1+1/e;
+
+ my $line_excluded = substr $line, 0, $point_position;
+
+ $line = $line_excluded . $line_part;
return $line;
}