fix: Handle combined mouse event and paste sequences in stdin buffer #461
+197
−27
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.
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