Skip to content

Commit

Permalink
fix: always restore original CURSOR position
Browse files Browse the repository at this point in the history
  • Loading branch information
LangLangBart committed Nov 13, 2024
1 parent d06d135 commit c608fc7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions shell/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,16 @@ fzf-completion() {
if [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then
d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir})

# Move the cursor before the trigger to preserve word array elements when
# characters like ';' or '`' would otherwise reset the 'words' array.
cursor_pos=$CURSOR
CURSOR=$((cursor_pos - ${#trigger} - 1))
# Make the 'cmd_word' global
zle __fzf_extract_command || :
CURSOR=$cursor_pos
{
# Move the cursor before the trigger to preserve word array elements when
# trigger chars like ';' or '`' would otherwise reset the 'words' array.
CURSOR=$((cursor_pos - ${#trigger} - 1))
# Make the 'cmd_word' global
zle __fzf_extract_command
} always {
CURSOR=$cursor_pos
}

[ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}
if [[ $prefix = *'$('* ]] || [[ $prefix = *'<('* ]] || [[ $prefix = *'>('* ]] || [[ $prefix = *':='* ]] || [[ $prefix = *'`'* ]]; then
Expand Down

0 comments on commit c608fc7

Please sign in to comment.