NHDaly / tmux-better-mouse-mode

A tmux plugin to better manage and configure the mouse.
MIT License
910 stars 27 forks source link

Emulate alternate buffer ignores scroll-in-moused-over-pane #30

Closed ghost closed 6 years ago

ghost commented 7 years ago

When all panes are open on a 'normal' shell, everything works as expected. Scrolling over the active pane always works as expected.

The problem I'm having is that if the mouse is over an alternate buffer pane (that isn't active), the up/down key presses go to the active pane not the moused over one.

Example

One pane has less open, the other (active one) has the shell. Scrolling over the less pane will scroll through commands on the shell.

With two panes showing less and scrolling over the non active one, the active one is scrolled.

.tmux.conf

set-option -g mouse on
set -g @scroll-without-changing-pane "on"
set -g @emulate-scroll-for-no-mouse-alternate-buffer "on"
set -g @scroll-in-moused-over-pane "on"
set -g @scroll-down-exit-copy-mode "on"

This is with tmux 2.3 (and zsh 4.3.11 if that makes a difference). Let me know if you need any other information.

Thanks for this plugin. It saves a huge amount of time.

jep-dev commented 7 years ago

I'm using Tmux Master (post-2.5) and Zsh 5.1.1, and I have the same issue. I've tried variations on all of these settings, as well as disabling the plugin, switching the default-terminal from tmux to xterm-256color and screen-256color, turning xterm-keys on and off, prefixing less with several shot-in-the-dark stty options, and the old inline copy mode scrolling hacks. None of these appeared to change the behavior, except to remove one or more of the existing features.

I've also noticed that while Vim is in the focused pane, scrolling down in a terminal pane leaves the cursor in Vim, but scrolling up starts copy mode at the same time as stealing focus. If I scroll up just enough to enter copy mode but not scroll a line, re-focus Vim, and scroll the other back down, it still steals focus.

In Vim, I can use + to issue when I release them, because alt doesn't send an escape code until the combination is pressed, at which points it fires both at once. (so Vim doesn't have to wait out the disambiguation countdown.) I thought I would try <alt>+scrolling and see how the terminal and copy-mode buffer respond, but sadly <alt>+scroll is bound to screen magnification, and I can't find where that's set (mouse, keyboard, display, accessibility, window manager, etc.)

I wouldn't mind pressing or holding a key to convert all scrolling into key navigation as long as it could target the pane under the mouse cursor and (optionally) leave the focus on the original - but it makes so much more sense to me to replace editors, pagers, and whatever 'copy-mode' actually is with analogues that know what to do with the signals you intend to give them.

I also tried my key bindings for entering and exiting copy-mode, as well as entering them after <prefix>:... and it looks like in both cases only entering copy-mode works. Pressing escape or q still exits it, but not <prefix>:copy-mode -e.

Another shot in the dark: could this be related to the bindings in this plugin being in the wrong tables after some Tmux update?

https://github.com/tmux/tmux/issues/669 -

bind-key -n C-left prev                                                                                                                                                            
bind-key -Tcopy-mode-vi C-right next                                                                                                                                               
bind-key -Tcopy-mode-vi C-left prev

I have the typical terminal-overrides ',xterm*:smcup@:rmcup@' in my rc but that was one of the first things I poked at. The manual says these options are passed through strunvis which led me to vis and the description of the escape codes - maybe there's a mapping we could add to override these behaviors. That's about as far as I got, I don't know how to troubleshoot events beyond inspecting them by consuming them and escaping them on an individual basis for a couple of applications and contexts.

What terminal emulator are you using, and have you tried any others? I thought that might be relevant but the behavior is the same in at least Guake, Tilda, and 'xfce4-terminal', so I'm guessing it's not, but maybe your mileage will vary. Generally speaking the job of a terminal emulator is to give a TTY a framebuffer and an event stream and get out of the way, but I've had plenty of issues when they tried to do more.

I would love it if I could use emulated copy-mode in the pager or script of my choice, because RO vim / View handles events so much better, but there doesn't seem to be a way. Of course there is always 'vi-mode' command line, but I'd have to learn the basics before I could test it properly, and I doubt the copy-mode mechanic would be different anyway.

NHDaly commented 6 years ago

:) Thanks so much for catching this! :) This is a good improvement. Should be fixed now.

Sorry it took me so long to get to this!

ghost commented 6 years ago

Thanks for the fix. Seems to work as expected now.