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

[BUG] Mouse handling delayed in neovim terminal #99

Closed
Kavantix opened this issue Oct 8, 2021 · 18 comments · Fixed by #110
Closed

[BUG] Mouse handling delayed in neovim terminal #99

Kavantix opened this issue Oct 8, 2021 · 18 comments · Fixed by #110
Labels
bug Something isn't working

Comments

@Kavantix
Copy link

Kavantix commented Oct 8, 2021

Describe the bug
Mouse clicks inside neovim terminal are delayed until the next system event.
Mouse handling works fine with jroimartin/gocui

To Reproduce
Steps to reproduce the behavior:

  1. Open nvim
  2. Open the nvim terminal with :term
  3. Run a gocui project that uses the MouseLeft keybinding
  4. Notice that nothing happened
  5. Press a random key on the keyboard
  6. Notice that the mouse press is now detected

Expected behavior
The mouse click should be detected immediately

Environment (please complete the following information):

  • OS: macOS catalina
  • nvim 0.5

Context

  • Calling g.Update does not help
  • MouseRelease is trigged (although not on release)`
@Kavantix Kavantix added the bug Something isn't working label Oct 8, 2021
@mjarkk
Copy link
Member

mjarkk commented Oct 11, 2021

I suspect this has something to do with the move over from termbox to tcell for the terminal rendering library

@dankox
Copy link

dankox commented Oct 15, 2021

I was trying to look into this a bit and only found this issue which kinda correspond in tcell:
gdamore/tcell#480

However, when I tried to upgrade tcell to the latest version, it didn't really help :/.

Was testing it in neovim and in vim (the same problem). But actually when I was trying _examples/mouse.go application it didn't really get the mouse event even if any key press happen.
Not sure if this is because of the specific of mouse.go demo app, or anything else. All the other examples worked well, so the mouse is the only affected.

I will try to debug it later.

@Kavantix
Copy link
Author

Kavantix commented Nov 1, 2021

@dankox anything I can specifically test?

@dankox
Copy link

dankox commented Nov 2, 2021

@Kavantix I'm sorry, I kinda forgot about this issue. However, I was doing some tests and I'm not really sure if this works at all in any case anywhere.

What I was using initialy was vim with :term command. But I couldn't make it work even with original gocui which uses termbox, so I tried it also in nvim and the result is the same.

Mouse doesn't work for me in vim or nvim either using termbox-go or tcell.

  • tried jroimartin/gocui (latest which is May 9th) using _examples/mouse.go
  • tried termbox-go using _demos/keyboard.go and _demos/paint.go
  • tried tcell using _demos/mouse.go

My environment is:

  • macOS Big Sur v11.6
  • vim v8.2
  • nvim v0.5
  • terminal used for testing - kitty (v0.19) and iterm2 (v3.4)

Can you please provide a source code or example of application using original gocui which uses mouse and works as you described? I want to try to know if it is just my environment or something else. Thanks...

@Kavantix
Copy link
Author

Kavantix commented Nov 2, 2021

@dankox you probably don’t have mouse mode enabled in vim then (it’s off by default)
You can enable it using set mouse=a

@mjarkk
Copy link
Member

mjarkk commented Nov 2, 2021

Just tried what you said and my mouse input has no delay:

  1. Open nvim
  2. Ran set mouse=a
  3. Ran :term
  4. Ran _examples/mouse.go
    (I also tested lazygit and there the mouse input is also supper fast)

Envourment:

  • OS: Arch linux with kernel release 5.14.14-arch1-1
  • neovim: v0.5.1
  • terminal emulator: gnome-terminal

May i ask what terminal emulator you are using?

@Kavantix
Copy link
Author

Kavantix commented Nov 2, 2021

Weird, I have tried on several terminal emulators (iTerm, kitty, alacritty, macos terminal) and all behave the same on my system. I am using neovim nightly though.

Lazygit is indeed fast but that is still using the termbox version right?

@mjarkk
Copy link
Member

mjarkk commented Nov 2, 2021

Just tried out the same thing using Neovim nightly (v0.6.0-dev+551-ged2573b7e from aur/neovim-nightly-bin) but it's still as fast.

Lazygit is indeed fast but that is still using the termbox version right?

I think so, this was a tui program i knew has mouse support so i tested it also. tough now looking at it back it was a bit pointless.

@mjarkk

This comment has been minimized.

@dankox
Copy link

dankox commented Nov 2, 2021

Ooooooooooh... now I feel stupid 🤦‍♀️ my bad :)

So I've tried it with set mouse=a, and I see the difference.

But I have to say, this is a bit weird, because for vim it works ok... no delay whatsoever. For nvim however, I can see the delay by one event mentioned in the issue.
If I try the original gocui from jroimartin, there is no delay. So it's definitely tcell.

Looking at it more precisely, I think there is something "wrong" with nvim. I have a guess on what is the main difference (keep it mind this is from top of my head, didn't have time to look into code and debug, will do later).

tcell register two events, mouse press and mouse release (from what I remember). And I can see in vim when I try tcell demo app _demos/mouse.go the Button1 test appears just shortly and disapear right away after the mouse release.
However in nvim, this text appears and does not disapear until next event (if next is again mouse click, it will stay).

From this I can guess that nvim just doesn't propagate mouse release event to terminal (or does it later with next event). Why it works for original gocui is because termbox-go does not have mouse release. gocui does not have mouse release either, this is just implementation of tcell mouse events made to be as similar to original gocui as possible.

What we can do:

  1. register mouse click on mouse click (not on mouse release)
  2. introduce new mouse event which is mouse release (could be beneficial if somebody wants to implement drag and drop in TUI apps)
  3. report to nvim that the event is not send (however, this has to be debugged first to be sure)

Anyway, regardless of next action, I want to do some more debugging on this in nvim because now I have at least an idea what might go wrong.
The first option shouldn't be that hard to implement, as we are in charge of what to do with mouse events, but I'm not sure if it's the best.

@dankox
Copy link

dankox commented Nov 2, 2021

@mjarkk can you try tcell demo application from _demos/mouse.go if it has similar behaviour on linux as I desribed in the post above? This could also narrow down a problem that maybe only macOS version of nvim has this problem, or maybe it's general.

@Kavantix
Copy link
Author

Kavantix commented Nov 2, 2021

@dankox thanks for the extensive explanation!
Let me know if I can help in any way

@Kavantix
Copy link
Author

Kavantix commented Nov 2, 2021

Btw, my preference would be adding the mouse release, a drag feature is something I'm planning on adding to one of my projects so would be very welcome

@mjarkk
Copy link
Member

mjarkk commented Nov 3, 2021

@dankox Just tried out the _demos/mouse.go and now i see the problem the issue describes also on linux with neovim v0.6.0

@dankox
Copy link

dankox commented Nov 3, 2021

@Kavantix if you want, you can try to debug it in tcell_driver.go program (in polling function) to see what events are provided and at what time. That's kinda what I want to do (to see when the mouse release is passed from nvim).

I want to look at it later this day when I will get the time to get better idea of what is going on.

@Kavantix
Copy link
Author

@dankox @mjarkk I finally go around to testing this.
It seems neovim is simply not sending mouse release events

However, the old driver that didnt use tcell seems to handle click events on mouse down not mouse release which is why it's not really a problem with the older version.

@Kavantix
Copy link
Author

I opened neovim/neovim#16371 at their side

@dankox
Copy link

dankox commented Nov 23, 2021

@Kavantix thanks for letting us know. I can see that in neovim they are fixing propagation of that event to terminal so that's cool.

I didn't have much time recently to look more into this, but I think we definitely should add the MouseRelease event and implement it properly. Keeping this issue open until it's done.
It should be done correctly so other apps are not affected by it and want to be sure to be compatible with original gocui implementation. So it might take some time, but will try to get to it as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants