aboutsummaryrefslogtreecommitdiffstats
path: root/incdec
diff options
context:
space:
mode:
authorTeddy Wing2021-08-22 21:16:42 +0200
committerTeddy Wing2021-08-22 21:16:42 +0200
commit392554df943a23099d788d0f04e1cf13b66e910f (patch)
treedc17f373001ab433b3c31e019b6ef315926cf509 /incdec
parent250252e775486f9d60652a4b4490caac6756e767 (diff)
downloadreadline-incdec-392554df943a23099d788d0f04e1cf13b66e910f.tar.bz2
incdec: Move point if negative hyphen is added or removed
Previously, point would stay in the same position, causing it to look like it moved when incrementing or decrementing between a negative number and a positive number. This moves point by one to the right when decrementing to a negative integer, or by one to the left when incrementing to a positive integer. That makes the point seem like it hasn't moved and making it look more natural. For example, now point behaves like this: $ test 12 0 ^ _decrement_ $ test 12 -1 ^ $ test 12 -1 ^ _increment_ $ test 12 0 ^ Before, it would do: $ test 12 0 ^ _decrement_ $ test 12 -1 ^ $ test 12 -1 ^ _increment_ $ test 12 0 ^
Diffstat (limited to 'incdec')
-rw-r--r--incdec24
1 files changed, 23 insertions, 1 deletions
diff --git a/incdec b/incdec
index fe4670b..c253028 100644
--- a/incdec
+++ b/incdec
@@ -128,10 +128,32 @@ sub incdec {
}
function __readline_incdec_increment {
+ local old_line_length="${#READLINE_LINE}"
+
__readline_incdec 1 1
+
+ local new_line_length="${#READLINE_LINE}"
+
+ if [ "$old_line_length" -gt "$new_line_length" ]; then
+ READLINE_POINT="$(($READLINE_POINT - 1))"
+ fi
+}
+
+function __readline_incdec_decrement {
+ local old_line_length="${#READLINE_LINE}"
+
+ __readline_incdec -1 1
+
+ local new_line_length="${#READLINE_LINE}"
+
+ if [ "$old_line_length" -lt "$new_line_length" ]; then
+ READLINE_POINT="$(($READLINE_POINT + 1))"
+ # elif [ "$old_line_length" -gt "$new_line_length" ]; then
+ # READLINE_POINT="$(($READLINE_POINT - 1))"
+ fi
}
-bind -x '"\C-x-": __readline_incdec -1 1'
+bind -x '"\C-x-": __readline_incdec_decrement'
bind -x '"\C-x+": __readline_incdec_increment'