fix: Handle combined mouse event and paste sequences in stdin buffer#461
fix: Handle combined mouse event and paste sequences in stdin buffer#461d3vr wants to merge 1 commit intoanomalyco:mainfrom
Conversation
|
I tried to wrap my head around this, is this an issue with the stdin buffering? It seems like https://github.com/anomalyco/opentui/blob/main/packages/core/src/lib/stdin-buffer.ts should handle that before it hits any downstream consumers. |
|
Yeah my bad, in hindsight this was a quick and dirty fix, I haven't wrapped my head around the codebase and I should have opened an issue and waited for your input before submitting a PR. So the proper fix would be to make Should I rework the PR with this approach, or would you prefer I close it and open a fresh one? |
|
No problem. Discussion on a PR is also fine. You can just update this branch, that's fine. |
Drag-and-drop file paths from a file manager into terminals using OpenTUI-based applications (like OpenCode) was not working in Alacritty, while it worked correctly in Ghostty/Kitty/others.
Root Cause Analysis
When a file is dragged and dropped into a terminal, the terminal sends the file path as a bracketed paste sequence (
\x1b[200~...\x1b[201~). However, different terminals emit these sequences differently:Alacritty's combined sequence:
The bug occurred because:
stdinListener()calledhandleMouseData(data)with the full bufferMouseParser.parseMouseEvent()found the mouse event using regexmatch()(not anchored)handleMouseData()returnedtrue, signaling the entire buffer was handledSolution
Added a new method
parseMouseEventWithConsumed()toMouseParserthat returns both the parsed event and the number of bytes consumed. This allows the caller to process any remaining data in the buffer.Key changes:
parse.mouse.ts:MouseParseResulttype:{ event: RawMouseEvent, consumed: number }parseMouseEventWithConsumed()method with^-anchored regexparseMouseEvent()to call the new method (maintains backward compatibility, since the method was exported, I erred on the safe side).renderer.ts:handleMouseData()to useparseMouseEventWithConsumed()_stdinBuffer.process()Flow after fix:
Testing
parse.mouse.test.ts(11 tests)parseAllEventshelper in integration tests to use the new methodRelated