Repository navigation
feat(ui): add toggle_mouse action to suspend mouse tracking at runtime - #435
Conversation
mouse tracking captures plain drag, so terminal-native text selection is unavailable while it is on; --no-mouse is startup-only and gives up wheel and click handling entirely. toggle_mouse (default m) flips tracking at runtime: suspending hands the mouse back to the terminal for drag selection, a second press restores wheel and click. the tracking state moves to a mutable model field so the editor and output-flush suspend paths restore the current mode rather than the startup flag. works in both directions, including enabling from a --no-mouse start.
|
Opened #436 with the problem statement per CONTRIBUTING (this PR went up first — happy to rework per discussion there). |
umputun
left a comment
There was a problem hiding this comment.
I'm ok with the toggle, but as an opt-in action with no default key. The terminal's own selection modifiers (Shift, Option or Ctrl+Shift, depending on the terminal) already cover plain terminals. The case this helps is a multiplexer like herdr, where turning tracking off lets it select inside revdiff's pane only. Users who need it can add map m toggle_mouse to their keybindings.
changes:
- drop the
mdefault fromdefaultBindingsand replace the binding test entry with an assertion thattoggle_mouseis unbound by default - add a status-bar indicator, so a suspended mouse is visible: an entry in
statusIconForActionplus a row instatusModeIcons, lit while tracking is off. Show it only when the action is bound (len(m.keymap.KeysFor(keymap.ActionToggleMouse)) > 0), so users who never map it don't get a new icon. ExtendTestBuildHelpSpec_StatusIconsOnToggleRowswith an explicitly boundtoggle_mouse, since the default keymap won't have it - tests for the toggle from both startup states (tracking on and
--no-mouse), and for the editor, source editor and post-flush callbacks after toggling off or on. Check that each callback restores the current setting, not the startup one. A hand-built completion message doesn't pin the change - remove
cfg.mouseTracking(app/ui/model.go:325and its initializer at :938), nothing reads it now app/ui/editor.go:96still says "originally enabled", and thehandleMouseTogglecomment describes the implementation.// handleMouseToggle toggles mouse tracking.is enough
docs are optional. README, site/docs.html and the plugin's references/usage.md should mention the action with a map example, but I'll accept the PR without them and add the docs myself.
yes, I'll update PR. BTW: not of those options (Shift, Option or Ctrl+Shift ...) are working in native MacOs terminal for text selection. |
…ent-state restore - no default binding: plain terminals select through their own modifiers; users map the action explicitly (test asserts it stays unbound) - status-bar indicator shown only when the action is bound, lit while tracking is suspended - completion handlers (editor, source editor, post-flush) read the current tracking state instead of a restoreMouse flag carried through completion messages, so the new tests drive the real toggle from both startup states instead of hand-built messages; cfg.mouseTracking is gone - README documents the action with a map example
|
Pushed the reworked branch (84e2ce1):
|
umputun
left a comment
There was a problem hiding this comment.
the rest of the last round checks out, two small things left.
app/ui/model.go:1521- the new tests callhandleMouseToggle()directly and discard its command, so nothing pins which command the toggle sends or that a bound key reaches it. Swappingtea.DisableMousefortea.EnableMouseCellMotionat :1526, or droppingkeymap.ActionToggleMousefrom thedispatchActioncase at :1165, keeps the wholeapp/uisuite green. Fix: one test that builds the model withNewModel(ModelConfig{MouseTracking: ...})for both startup states (likeoutput_test.go:169), binds a key totoggle_mouse, sends it throughUpdate, checksmouseTrackingand the exact command, then presses it again and checks the reverse.app/ui/mouse.go:155- thehandleMousegodoc says the handler never runs with--no-mouse, which is no longer true once such a session toggles tracking on. Fix: something like "mouse events arrive only while terminal mouse tracking is enabled".
Just use the proper terminal, and you will be able to select with the mouse. Also, you may not even need a multiplexer at all ;) |
…sg constructors the original completion plumbing and tests stay verbatim: restoreMouse remains on editorFinishedMsg / sourceEditorFinishedMsg / postFlushFinishedMsg and the handlers keep reading it. the exec closures now build their messages through small constructors that snapshot the current tracking state, so the toggle-flow tests pin the wiring without hand-built messages and without touching existing behavior.
|
Reworked per the minimal/incremental preference: the existing The only production change beyond the original feature is that the three exec closures now build their completion messages through tiny constructors (
|
umputun
left a comment
There was a problem hiding this comment.
I didn't ask for the 22c4587 rework. It brings back the restoreMouse plumbing 84e2ce1 removed, behaves the same, and adds three constructors and message fields. Pls revert it and keep the 84e2ce1 handlers reading m.mouseTracking.
both items from my last review are still open:
app/ui/model.go:1521- nothing pins the toggle itself. Swappingtea.DisableMousefortea.EnableMouseCellMotionat :1526, or droppingkeymap.ActionToggleMousefrom thedispatchActioncase at :1165, still keeps theapp/uisuite green on 22c4587. Fix: one test that builds the model withNewModel(ModelConfig{MouseTracking: ...})for both startup states, binds a key totoggle_mouse, sends it throughUpdate, checksmouseTrackingand the exact command, then presses it again and checks the reverse.app/ui/mouse.go:155- thehandleMousegodoc still says the handler never runs with--no-mouse. Fix: something like "mouse events arrive only while terminal mouse tracking is enabled".
…te via msg constructors" This reverts commit 22c4587.
you absolutely right, my bad, i'll fix it. |
…odoc the toggle-flow tests called handleMouseToggle directly and discarded its command, so a swapped emitted command or a dropped dispatchAction case kept the suite green. the new test binds a key to toggle_mouse, sends it through Update from both startup states, and asserts mouseTracking plus the exact command on each press. handleMouse godoc claimed the handler never runs under --no-mouse, which is no longer true once such a session toggles tracking on.
|
Done:
|
mirror the README toggle_mouse text into site/docs.html and both plugin usage.md copies, add the action to both plugin config.md action lists, and drop the comments #435 added to its tests.
Problem
revdiff captures plain drag via mouse tracking, so terminal-native text selection is unavailable while tracking is on. The current options are all-or-nothing at startup:
--no-mouse— selection works, but wheel scrolling and click navigation are gone for the entire session.How this solves it
A new keymap action
toggle_mouse(defaultm, remappable through the keybindings file, shown in the help overlay and documented in the README) flips tracking at runtime:--no-mousestart.Implementation notes: tracking state moves from the immutable startup config to a mutable model field, and the $EDITOR / output-flush suspend paths restore the current mode rather than the startup flag, so a suspended session stays suspended across editor round-trips. Suspending emits bubbletea's
DisableMouse, resuming emitsEnableMouseCellMotion.Testing
go test ./...green except oneapp/diffblame test (TestGit_FileBlame_UsesIndexForStagedDiffs) that fails identically on a cleanmastercheckout locally — environment-dependent, unrelated to this change;golangci-lint runclean;--no-mousestart.