aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
diff options
context:
space:
mode:
authorTeddy Wing2021-08-08 20:36:10 +0200
committerTeddy Wing2021-08-08 20:37:59 +0200
commit5950add03889fc9a8cb6faface53903cebf3a206 (patch)
tree935c5f758ce72ba8658fabab67c13e78eb7cb5be /incdec.pm
parent3a813c6204e4f6879540fb2f44abb71f0406296f (diff)
downloadreadline-incdec-5950add03889fc9a8cb6faface53903cebf3a206.tar.bz2
incdec: Change a number when the cursor is in the middle of it
Correctly increment a number when the cursor is, for example, at: test 12 0 ^ This causes the #5 test incrementing the second number to fail.
Diffstat (limited to 'incdec.pm')
-rw-r--r--incdec.pm7
1 files changed, 7 insertions, 0 deletions
diff --git a/incdec.pm b/incdec.pm
index 2dfeb74..e8efe0b 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -9,6 +9,13 @@ sub incdec {
$point_position ||= 0;
$is_backward ||= 0;
+ $line =~ /(\d+)/;
+ # print $-[0] . ':' . $+[0] . ';' . $point_position;
+
+ if ($-[0] <= $point_position || $point_position <= $+[0]) {
+ $point_position = $-[0];
+ }
+
my $line_part = substr $line, $point_position;
$line_part =~ s/(\d+)/$1+1/e;