Commit b810f82a authored by Frank Terbeck's avatar Frank Terbeck

jtd: Do not try anything if the delimiter is not in the buffer

parent 33c22d09
......@@ -13,6 +13,10 @@ function jumpToDelim () {
if (( forward )); then
(( CURSOR += 2 ))
if [[ $RBUFFER != *${delim}* ]]; then
(( CURSOR -= 2 ))
return 1
fi
(( CURSOR = ${RBUFFER[(i)${delim}]} + ${#LBUFFER} ))
(( CURSOR += ${#delim} - 1 ))
(( CURSOR > ${#delim} )) && (( CURSOR -= ${#delim} + 1 ))
......@@ -24,6 +28,10 @@ function jumpToDelim () {
# Move back a character: If we're already on an instance of the
# delimiter, we want to be able to move off of it to the next instance.
(( CURSOR-- ))
if [[ $LBUFFER != *${delim}* ]]; then
(( CURSOR++ ))
return 1
fi
# This subscript expansion equates to the position of the delimiter in
# the buffer, which is basically "onto == 1" behaviour.
(( CURSOR = ${LBUFFER[(I)${delim}]} - 1 ))
......@@ -41,7 +49,7 @@ function jumpToDelim () {
function jump-to-delim () {
local -i num=${NUMERIC:-1}
while (( num-- > 0 )); do
jumpToDelim "$@"
jumpToDelim "$@" || return
done
return 0
}
......
......@@ -43,6 +43,12 @@ zpty_run 'autoload -Uz jump-to-delim
zpty_run 'bindkey "^xb" jump-to-prev-/
bindkey "^xf" jump-to-next-/'
zle-test-define 'No delimiter in buffer'
zletest $'foo.bar.baz.zsh.scm\C-e\C-xb' | zle-results CURSOR=19
zle-test-define 'One delimiter directly to the left, going left'
zletest $'foo/\C-e\C-xb' | zle-results CURSOR=4
zle-test-define 'One level back to slash'
zletest $'foo/bar/baz/zsh.scm\C-e\C-xb' | zle-results CURSOR=12
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment