diff options
| author | Teddy Wing | 2021-08-22 21:16:42 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-08-22 21:16:42 +0200 | 
| commit | 392554df943a23099d788d0f04e1cf13b66e910f (patch) | |
| tree | dc17f373001ab433b3c31e019b6ef315926cf509 | |
| parent | 250252e775486f9d60652a4b4490caac6756e767 (diff) | |
| download | readline-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
               ^
| -rw-r--r-- | incdec | 24 | 
1 files changed, 23 insertions, 1 deletions
| @@ -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' | 
