fix: coalesce fragmented paste events over SSH #305
Merged
+91
−59
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
Some terminals (e.g., MobaXterm) fragment large pastes into multiple bracketed paste sequences, causing premature submit when newlines trigger the submit handler before the full paste is received.
This adds paste coalescing with a 100ms debounce to buffer consecutive paste events and process them as a single paste operation.
Changes
pasteBufferto collect paste fragmentsisPastingsignal to block submit during coalescingprocessCoalescedPaste()function for the actual paste processingonCleanupto clear timer on unmountTesting
Tested over SSH with MobaXterm - multi-line pastes now correctly show
[X lines pasted]instead of fragmenting and submitting prematurely.Greptile Summary
Adds paste coalescing to fix fragmented paste events over SSH connections. Some terminals like MobaXterm split large pastes into multiple bracketed paste sequences, causing newlines to trigger premature submit before the full content arrives.
Key Changes:
pasteBufferto accumulate paste fragments with a 100ms debounce timerisPastingsignal that blocks the submit handler during coalescingprocessCoalescedPaste()function for cleaner separationConfidence Score: 4/5
Important Files Changed
Sequence Diagram
sequenceDiagram participant Terminal as Terminal (MobaXterm) participant onPaste as onPaste Handler participant Buffer as pasteBuffer participant Timer as Debounce Timer participant Process as processCoalescedPaste participant Input as Textarea Input Terminal->>onPaste: Paste Event 1 (fragment) onPaste->>Buffer: chunks.push(normalizedText) onPaste->>onPaste: setIsPasting(true) onPaste->>Timer: setTimeout(100ms) Terminal->>onPaste: Paste Event 2 (fragment) onPaste->>Timer: clearTimeout (cancel previous) onPaste->>Buffer: chunks.push(normalizedText) onPaste->>Timer: setTimeout(100ms) (reset) Note over Timer: 100ms passes without new paste Timer->>Process: Timer expires Process->>Buffer: coalesced = chunks.join("").trim() Process->>Buffer: Clear chunks and timer alt Empty content Process->>Process: Trigger prompt.paste command else File path detected Process->>Process: Handle as file/image else Large paste (≥3 lines or >150 chars) Process->>Input: pasteText(content, "[Pasted ~N lines]") else Small paste Process->>Input: insertText(pastedContent) end Process->>onPaste: setIsPasting(false) Note over Input: User can now submit