Aloxaf / fzf-tab

Replace zsh's default completion selection menu with fzf!
MIT License
3.28k stars 94 forks source link

[BUG] Cursor moves up on failed completion #205

Open Mellbourn opened 3 years ago

Mellbourn commented 3 years ago

In some environments, when I press tab and there is no valid completion, the cursor moves upwards.

This is a recording demonstrating the problems: https://asciinema.org/a/PlF3DoOIeIQQRwpG40K2o5cpw In this recording, I first ssh into a Raspberry pi. Some parts of the prompt looks broken because I use Nerd Fonts glyphs, which work fine for me, but it seems asciinema doesn't understand them. I first try some working competions, then I try to complete fjdkls, which is invalid, and when I press tab, the problem occurs: "no matches for files" is correctly displayed but the cursor moves upward, and when I press tab again the cursor moves up again, also other text also moves upwards, erasing the text that was there.

Environment:

uname -a
Linux alternative-pi-hole 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux

The problem only occurs when I combine three things:

  1. Raspbian 9 (I can't reproduce it on Raspbian 10)
  2. When I use fzf-tab (if I remove that, completion works fine)
  3. When I use the prompt Powerlevel10k with two lines (it does not happen with one line powerlevel10k prompt).
Aloxaf commented 3 years ago

Can you give me the output of C-x . when there is no valid completion? eg. ls asdsad<C-x .>

Mellbourn commented 3 years ago
 cat /tmp/zsh-23324-fzf-tab-1.log
     +fzf-tab-debug:9> : zsh 5.3.1
     +fzf-tab-debug:10> zle .fzf-tab-orig-expand-or-complete
     +fzf-tab-debug:11> unsetopt xtrace
Aloxaf commented 3 years ago

Ummm, strange. What's the value of $widgets[.fzf-tab-orig-$_ftb_orig_widget].

Mellbourn commented 3 years ago
echo $widgets[.fzf-tab-orig-$_ftb_orig_widget]
user:_zsh_autosuggest_bound_1_expand-or-complete
Aloxaf commented 3 years ago

It seems that fzf-tab is loaded after zsh-autosuggestions.

NOTE: fzf-tab needs to be loaded after compinit, but before plugins which will wrap widgets, such as zsh-autosuggestions or fast-syntax-highlighting

Please ajust the order and try again. If it still happens, please give me the output of C-x . again.

Mellbourn commented 3 years ago

I tested moving around the loading of fzf-tab, including before zsh-autosuggestion and fast-syntax-highlighting, but it did no difference. The output of C-x . changed to this

❯ cat /tmp/zsh-28836-fzf-tab-1.log
   +fzf-tab-debug:9> : zsh 5.3.1
   +fzf-tab-debug:10> zle .fzf-tab-orig-fzf-completion
   +fzf-tab-debug:11> unsetopt xtrace
Aloxaf commented 3 years ago

Then what's the value of echo $widgets[.fzf-tab-orig-$_ftb_orig_widget]?

Mellbourn commented 3 years ago
echo $widgets[.fzf-tab-orig-$_ftb_orig_widget]
completion:.expand-or-complete:_main_complete
Mellbourn commented 3 years ago

But this time, the trace output was 2000 lines long! I can give you access to it, but I'm not sure of the best way to give it to you.

Aloxaf commented 3 years ago

You can upload the file here.

Mellbourn commented 3 years ago

There you go: zsh-32478-fzf-tab-3.log

Aloxaf commented 3 years ago

To be honest, I can't figure out why.

Does it happen on the newer version of zsh?

Mellbourn commented 3 years ago

Nope.

The problem occurs on a Raspberry Pi 3 with zsh 5.3.1.

uname -a
Linux alternative-pi-hole 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux

I have a Raspberry Pi 4 with zsh 5.7.1 that does not have the problem.

uname -a
Linux raspberrypi4docker 5.10.17-v8+ #1403 SMP PREEMPT Mon Feb 22 11:37:54 GMT 2021 aarch64 GNU/Linux

I can't get a newer zsh on the Raspberry pi 3, unfortunately.

jaychitalia95 commented 3 years ago

Facing the same issue on M1 Macbook Pro

lminer commented 2 years ago

I'm getting this issue too on m1

Aloxaf commented 2 years ago

@lminer what's the zsh version on m1?

lminer commented 2 years ago

Actually, I'm a complete idiot. It runs fine. Sorry!

leodream commented 2 years ago

Encountered the same issue with powerline10k theme. Also found that cursor would will move up when there is completion candidates but abort with C-c or C-g or Esc.

PS: zsh 5.8 (x86_64-suse-linux-gnu)

jameshounshell commented 2 years ago

Having the cursor problem now with zsh and powerline 10k Darwin XXXXXX 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64 x86_64

sorry for the necrobump

Aloxaf commented 1 year ago

@jameshounshell What's your p10k configuration?

SuperTux88 commented 1 year ago

I had a similar issue where the prompt was moving upwards and "eating" lines above it when using with a multiline prompt, disabling COMPLETION_WAITING_DOTS for oh-my-zsh in the .zshrc solved it for me. Not sure if related to this, as it was also eating lines when successfully completing something not only when it failed. But just in case that helps anyone as I was searching what causes this for a very long time :grimacing:

RayJameson commented 1 year ago

I had a similar issue where the prompt was moving upwards and "eating" lines above it when using with a multiline prompt, disabling COMPLETION_WAITING_DOTS for oh-my-zsh in the .zshrc solved it for me. Not sure if related to this, as it was also eating lines when successfully completing something not only when it failed. But just in case that helps anyone as I was searching what causes this for a very long time 😬

This helped me, thank you!

Zweihander-Main commented 1 year ago

Was also having this problem but tried to diagnose it and got a little headway: I'm using a modification of the OMZ zeta theme.

The relevant code is something like:

function get_space {
    local str=$1$2
    local zero='%([BSUbfksu]|([FB]|){*})'
    local len=${#${(S%%)str//$~zero/}}
    local size=$(( $COLUMNS - $len - 1 ))
    local space=$(printf "%${size}s")
    echo $space
}

function print_prompt_head {
    local left_prompt="$(funcsForLeftPrompt)"
    local right_prompt="$(funcsForRightPrompt)"
    print -rP "$left_prompt$(get_space $left_prompt $right_prompt)$right_prompt"
}

PROMPT='$(print_prompt_head)
$(get_prompt_indicator)'

By remove the -P prompt expansion flag from the print function, it solves the problem:

print -r "$left_prompt$(get_space $left_prompt $right_prompt)$right_prompt"

In this particular theme, it has the downside that it clobbers the terminal on resize but hopefully this helps in debugging.

klieret commented 10 months ago

@Aloxaf Should we include the tip from @SuperTux88 about COMPLETION_WAITING_DOTS to the readme? I also stumbled on this and spent some time trying to solve it by rearranging plugins (to no avail) until this solved it for me

(excellent plugin btw ❤️ )