zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.39k stars 1.16k forks source link

Mouse release event is lost if the pane becomes inactive #3251

Closed dmaluka closed 2 months ago

dmaluka commented 2 months ago

Micro delivers mouse events, including mouse release events, to the currently active pane or tab only. As a result, in the following scenario:

  1. press a mouse button on an active pane or tab
  2. switch to another pane or tab (or, for example, switch to the infopane, e.g. begin typing a command), while keeping the mouse button pressed
  3. release the mouse button

the mouse release event is delivered to the new active pane, not to the original one. As a result, when we switch again to the original pane, it thinks that the mouse is still pressed, and thus handles mouse events incorrectly.

Some examples of issues caused by this bug:

  1. If the file opened in the bufpane has been modified by another program and then we click on the bufpane with the mouse, micro shows The file on disk has changed. Reload file? (y,n,esc) prompt. And then, after pressing y in this prompt, scrolling via the mouse wheel stops working. It starts working again only after clicking a mouse button once again. (In this case, the issue occurs because the prompt switches the focus from the bufpane to the infopane immediately after the mouse is pressed, before it is released.)

  2. Press a mouse button, switch to another split pane via Ctrl-w (without releasing the mouse), release the mouse and switch back to the original pane. Then click mouse somewhere in that pane. Result: unexpected text selection.

  3. Begin resizing a split pane by dragging the split pane divider with the mouse, switch to another tab via Alt-. (without releasing the mouse), release the mouse and switch back to the original tab. Then click mouse somewhere. Result: unexpected resize of the split pane.

Commit hash: f386b29e OS: any Terminal: any

JoeKar commented 2 months ago
  1. Could/should react upon the release earliest, but...
  2. Should perform the release automatically, before the next tab/pane change takes place
  3. Should perform the release automatically, before the next tab/pane change takes place

...so even the 1. could to this too and the same mechanism applies for all scenarios.