mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.97k stars 715 forks source link

[BUG] Scrolling through a long file with the touchpad on macOS + Kitty will sometime reset the view back to the cursor #5130

Closed jamesaustin closed 7 months ago

jamesaustin commented 7 months ago

Version of Kakoune

Kakoune v2023.08.05-335-g610d4114

Reproducer

  1. Open a long text file with Kakoune (default config) with Kitty (default config) and two-finger scroll down through the file.
  2. Occasionally the view will snap back to the cursor position and scrolling will continue from the cursor position.

Outcome

The view will occasionally snap back to the cursor position and continue scrolling again.

Expectations

I would expect the view to not snap back to the location of the cursor.

Additional information

I reported the issue against Kitty - see here. The owner suggests it is more likely to be an issue with Kakoune itself.

I actually can't reproduce the issue with Kakoune and other terminals, having tested with Terminal.app, iTerm2 and Alacrity. Which seemed to suggest it was an issue with Kitty. But I also can't see any output from the Kitty logging that would cause Kakoune to snap the view back to the cursor.

Issue has been experienced for a few years and isn't new.

The issue only happens when scrolling with the trackpad, and not with the mouse.

I originally wondered if the slightly imprecise trackpad scrolling which will sometimes introduce a scroll in the x-axis might trigger the issue.

Issue experienced on macOS 14.2.1.

jamesaustin commented 7 months ago

This is the change that is ensuring the cursor is visible and causes the scrolling to snap back to the cursor position.

https://github.com/mawww/kakoune/commit/20a2bca52e0d159cdbab4ff6d38024cd1503a4f5

jamesaustin commented 7 months ago

If it's a Client 'client0' got key '<scroll:3>' event then the ensure_cursor_visible is cleared in scroll_window.

However when it is a Client 'client0' got key '<mouse:move:17.92>' event then the view will snap.

jamesaustin commented 7 months ago

Looking at the output from Kitty --debug-input it reports only scroll inputs. So I'm not sure where this random mouse:move is coming from.

mawww commented 7 months ago

mouse move events can happen when the OS cursor moves over the terminal, most terminals only send those if a button is held at the same time. In any case it looks like Kakoune considers that a mouse move by itself is sufficient to make the cursor visible, which I think is indeed a bug.

krobelus commented 7 months ago

I have also been seeing this issue in the foot terminal, it reproduces pretty reliably

mawww commented 7 months ago

Pushed a tentative fix but could not validate it as I have no reproducer.

jamesaustin commented 7 months ago

Thank you!! I can confirm it resolved the issue for me with Kitty on macOS.