Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fish shell integration automatically completes currently shown completion #7168

Closed
martonperei opened this issue Feb 28, 2024 · 8 comments
Closed
Labels

Comments

@martonperei
Copy link

martonperei commented Feb 28, 2024

Describe the bug
When the prompt-mark shell integration is enabled with fish, occasionally the currently shown completion is auto-completed.
The problem doesn't happen with shell_integration no-prompt-mark.

Sometimes it happens right after opening a new tab and typing a command, ending up in something like git checkout developit clone when I want to type git clone

To Reproduce
Steps to reproduce the behavior:

  1. Launch kitty with the following config: shell /opt/homebrew/bin/fish -N --login --interactive
  2. Copy paste the manual shell integration for fish from here: https://sw.kovidgoyal.net/kitty/shell-integration/
  3. Start writing a command, after some time (mouse clicks sometimes trigger it), the command will auto-complete

Screenshots
Completion is shown:
Screenshot 2024-02-28 at 21 04 09
Completion is auto-completed automagically.
Screenshot 2024-02-28 at 21 04 15

Environment details

kitty 0.32.2 (925043d645) created by Kovid Goyal
Darwin martons-mbp.lan.****.*** 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
ProductName:		macOS ProductVersion:		14.3.1 BuildVersion:		23D60
Frozen: True
Paths:
  kitty: /Applications/kitty.app/Contents/MacOS/kitty
  base dir: /Applications/kitty.app/Contents/Resources/kitty
  extensions dir: /Applications/kitty.app/Contents/Resources/Python/lib/kitty-extensions
  system shell: /opt/homebrew/bin/fish
Loaded config files:
  /Users/mperei/.config/kitty/kitty.conf

Config options different from defaults:
shell /opt/homebrew/bin/fish -N --login --interactive
Removed shortcuts:
	cmd+, →  edit_config_file
	cmd+enter →  new_window
	cmd+h →  hide_macos_app
	cmd+k →  clear_terminal to_cursor active
	cmd+m →  minimize_macos_window
	cmd+n →  new_os_window
	cmd+q →  quit
	cmd+t →  new_tab
	cmd+w →  close_tab
	ctrl+cmd+, →  load_config_file
	ctrl+cmd+f →  toggle_fullscreen
	opt+cmd+h →  hide_macos_other_apps
	opt+cmd+r →  clear_terminal reset active
	opt+cmd+s →  toggle_macos_secure_keyboard_entry
	shift+cmd+/ →  open_url https://sw.kovidgoyal.net/kitty/
	shift+cmd+[ →  previous_tab
	shift+cmd+] →  next_tab
	shift+cmd+d →  close_window
	shift+cmd+w →  close_os_window

Important environment variables seen by the kitty process:
	PATH                                /Applications/kitty.app/Contents/MacOS:/usr/bin:/bin:/usr/sbin:/sbin
	LANG                                en_US.UTF-8
	SHELL                               /opt/homebrew/bin/fish
	USER                                mperei

Additional context
Try to reproduce the problem with kitty --config NONE if you cannot then post a minimal kitty.conf that reproduces the problem. If the problem involves interaction with some other terminal program post a minimal config for that program to reproduce the problem as well.

@kovidgoyal
Copy link
Owner

Doesnt reproduce for me with fish version 3.7.0 and empty fish config, and I dont see how
prompt marking can possibly affect completion. Probably some interaction
with something else in your fish config, bisect it to find out.

@martonperei
Copy link
Author

martonperei commented Feb 29, 2024

I've tested with no fish config, thats’s why I included the shell command with -N
It doesn't happen in iTerm2 with shell integration enabled.

Simplified the reproduction:

  1. kitty --config NONE /opt/homebrew/bin/fish -N --login --interactive
  2. Run printf "\033]133;A\007"; printf "\033]133;B\007"
  3. Type g -> g++ will be shown as a completion
  4. Click the mouse in the window (you don't need to, but it seems to trigger it. I've tested with the trackpad too)
  5. The completion will be triggered, but randomly the cursor goes back to before the first character. (and the completion isn't triggered)

It kinda looks like an issue with selection and/or focus.
It does not seem to reproduce with -o clear_all_mouse_actions=yes. Any ideas what mouse mappings in kitty could cause it? I disabled all apps that could interfere with input.

Thanks for any pointers!

@kovidgoyal
Copy link
Owner

clicking the mouse will send fake arrow key press events to move the
cursor. These will trigger completion depending on how you have
completion setup. IIRC in fish the right arrow completes. There isnt
anything that can be done to avoid this, as far as I know.

@martonperei
Copy link
Author

Hm, that makes sense. The cursor doesn't move on click without prompt marks, interesting, so that explains why it only happens with them.

Also, my best guess, that something in my setup must be sending phantom mouse presses to the kitty window periodically then, that's why it sometimes autocompletes without mouse presses.

Thanks a lot for the fast response!

@kovidgoyal
Copy link
Owner

Ideally, fish would have some input function that moves the cursor right
without accepting an auto-suggestion. Then the kitty fish shell integration
could bind that function to some otherwise unused escape sequence and we
would not have this issue. However, there is no such function:
https://fishshell.com/docs/current/cmds/bind.html that I can see.

Even more ideally, fish would add a function that has semantics of
"move cursor to the cell number X on line number Y, where Y is counted
from the line that starts the prompt".

You can try requesting something along these lines, maybe the fish
developers will be kind enough to provide such a function.

@martonperei
Copy link
Author

martonperei commented Feb 29, 2024

As a band-aid, I've disabled the left click prompt event, while keeping the prompt marks working (which is what I needed)
Kitty could send commandline -f suppress-autosuggestion before moving the cursor, but that would mean the completion would vanish. Though I think that's a little bit better behavior than the current one.
However, after some more debugging, this behavior exists in iTerm2 too, but you have to press alt to move the mouse.

@martonperei
Copy link
Author

Actually, there is commandline -C <cursor_position> which sets the cursor position in the current buffer without accepting the suggestion.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Feb 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants