fzf-tab icon indicating copy to clipboard operation
fzf-tab copied to clipboard

[BUG] Cursor moves up on failed completion

Open Mellbourn opened this issue 3 years ago • 24 comments

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:

  • OS: Raspbian GNU/Linux 9 (stretch)
  • zsh version: 5.3.1 (arm-unknown-linux-gnueabihf)
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).

Mellbourn avatar Apr 05 '21 23:04 Mellbourn

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

Aloxaf avatar Apr 06 '21 07:04 Aloxaf

 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

Mellbourn avatar Apr 06 '21 09:04 Mellbourn

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

Aloxaf avatar Apr 06 '21 14:04 Aloxaf

echo $widgets[.fzf-tab-orig-$_ftb_orig_widget]
user:_zsh_autosuggest_bound_1_expand-or-complete

Mellbourn avatar Apr 06 '21 19:04 Mellbourn

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.

Aloxaf avatar Apr 07 '21 00:04 Aloxaf

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

Mellbourn avatar Apr 07 '21 16:04 Mellbourn

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

Aloxaf avatar Apr 08 '21 07:04 Aloxaf

echo $widgets[.fzf-tab-orig-$_ftb_orig_widget]
completion:.expand-or-complete:_main_complete

Mellbourn avatar Apr 08 '21 10:04 Mellbourn

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.

Mellbourn avatar Apr 08 '21 10:04 Mellbourn

You can upload the file here.

Aloxaf avatar Apr 09 '21 09:04 Aloxaf

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

Mellbourn avatar Apr 09 '21 17:04 Mellbourn

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

Does it happen on the newer version of zsh?

Aloxaf avatar Apr 19 '21 14:04 Aloxaf

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.

Mellbourn avatar Apr 19 '21 15:04 Mellbourn

Facing the same issue on M1 Macbook Pro

jaychitalia95 avatar Jul 02 '21 03:07 jaychitalia95

I'm getting this issue too on m1

lminer avatar Nov 27 '21 19:11 lminer

@lminer what's the zsh version on m1?

Aloxaf avatar Nov 28 '21 01:11 Aloxaf

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

lminer avatar Nov 28 '21 04:11 lminer

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)

leodream avatar Dec 26 '21 14:12 leodream

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

jameshounshell avatar Jun 17 '22 15:06 jameshounshell

@jameshounshell What's your p10k configuration?

Aloxaf avatar Oct 13 '22 03:10 Aloxaf

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:

SuperTux88 avatar Nov 20 '22 01:11 SuperTux88

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!

RayJameson avatar Dec 17 '22 05:12 RayJameson

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.

Zweihander-Main avatar Apr 23 '23 01:04 Zweihander-Main

@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 ❤️ )

klieret avatar Nov 14 '23 18:11 klieret