Skip to content

Conversation

@b3nw
Copy link

@b3nw b3nw commented Jan 17, 2026

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

  • Added pasteBuffer to collect paste fragments
  • Added isPasting signal to block submit during coalescing
  • Added 100ms debounce timer to coalesce rapid paste events
  • Extracted processCoalescedPaste() function for the actual paste processing
  • Added onCleanup to clear timer on unmount

Testing

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:

  • Introduced pasteBuffer to accumulate paste fragments with a 100ms debounce timer
  • Added isPasting signal that blocks the submit handler during coalescing
  • Refactored paste logic into processCoalescedPaste() function for cleaner separation
  • Added cleanup handler to clear timer on component unmount
  • Preserved inter-fragment whitespace by not trimming individual chunks (only trim final coalesced result)

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The implementation is well-structured and addresses a specific terminal compatibility issue. The debounce approach is standard, cleanup is properly handled, and the logic preserves existing behavior for non-fragmented pastes. Minor edge cases exist but are unlikely to cause production issues.
  • No files require special attention

Important Files Changed

Filename Overview
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx Adds paste coalescing with 100ms debounce to handle fragmented paste events from terminals like MobaXterm, with proper cleanup and state management

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
Loading

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. Submit is
blocked while paste coalescing is active to prevent partial submissions.
@shuv1337 shuv1337 merged commit 1f44658 into Latitudes-Dev:dev Jan 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants