fix: filter mouse escape fragments leaking into dialogs on Linux#161
Open
jacola wants to merge 1 commit intomarcus:mainfrom
Open
fix: filter mouse escape fragments leaking into dialogs on Linux#161jacola wants to merge 1 commit intomarcus:mainfrom
jacola wants to merge 1 commit intomarcus:mainfrom
Conversation
Add universal mouse fragment filter early in handleKeyMsg() using tty.LooksLikeMouseFragment() and a recentMouseEvent flag for bare bracket time-gating. This catches SGR mouse sequences that Linux terminals split across read boundaries, which Bubble Tea delivers as KeyMsg instead of MouseMsg. Remove the now-redundant per-modal isMouseEscapeSequence() calls and the function itself, centralizing the defense in one place.
bab75c1 to
89f2d13
Compare
Author
|
I accidentally added some of my other local fixes into this pr and cleaned them up with the force push above. Sorry about that. 🙇 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix mouse escape sequence fragments leaking into dialogs as garbage text on Linux (Gnome with Ptyxis emulator). On Linux, terminal emulators split SGR mouse sequences across
read()boundaries, causing Bubble Tea to deliver fragments like[<67;78;9MasKeyMsginstead ofMouseMsg. These fragments appear as typed garbage in modal text inputs and can trigger unintended keybindings (e.g.,[→prev-tab).Root cause: The existing
isMouseEscapeSequence()filter was too strict (required trailingM/m, missing truncated fragments) and was only applied in 5 of 11 modal handlers.Fix: Add a single, early universal filter in
handleKeyMsg()that catches all fragment types before any modal/plugin routing. This uses the existing, well-testedtty.LooksLikeMouseFragment()plus arecentMouseEventflag for bare[suppression. Then remove all redundant per-modal filters.Changes Made
internal/app/model.go: AddrecentMouseEvent boolfield for tracking proximity to mouse eventsinternal/app/update.go:recentMouseEvent = trueon everytea.MouseMsghandleKeyMsg()(after Esc handling, before any modal/plugin routing)LooksLikeMouseFragmentwhen first rune suggests mouse dataisMouseEscapeSequence()function definition and all 5 call sitesttypackage importinternal/app/project_add_modal.go: Remove 2isMouseEscapeSequence()call sitesNet result: -27 lines (24 added, 51 removed)
Type of Change
How to Test
@) and move the mouse / scroll — no garbage should appear in the filter inputn) and move the mouse — no fragments in the name field#), help (?), quit confirm (ctrl+c), diagnostics — mouse interaction should not cause unexpected behavior[key still works forprev-tab/prev-filenavigation when no mouse is activeVerification
go build ./...passesgo test ./internal/app/...passesgo test ./internal/tty/...passesgo vet ./...passesAdditional Notes
read(), so Bubble Tea always successfully parses them.tty.LooksLikeMouseFragment()function (ininternal/tty/output_buffer.go) already had comprehensive tests — no changes needed to that function.