Skip to content

Conversation

@b3nw
Copy link

@b3nw b3nw commented Jan 19, 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 150ms debounce to buffer consecutive paste events and process them as a single paste operation.

Note: Re-submission of #305 and #311 which were lost/had issues.

Changes

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

Technical Details

When a paste event arrives:

  1. Content is buffered in pasteBuffer.chunks
  2. isPasting signal is set to true (blocks submit)
  3. Debounce timer is started/reset (150ms)
  4. When timer fires, all chunks are joined and processed
  5. isPasting is cleared only if no new paste arrived during processing

Testing

Tested over SSH with MobaXterm - multi-line pastes now correctly show [Pasted ~X lines] 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 150ms 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 150ms 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(150ms)
    
    Terminal->>onPaste: Paste Event 2 (fragment)
    onPaste->>Timer: clearTimeout (cancel previous)
    onPaste->>Buffer: chunks.push(normalizedText)
    onPaste->>Timer: setTimeout(150ms) (reset)
    
    Note over Timer: 150ms 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

ariane-emory and others added 30 commits January 16, 2026 21:57
actions-user and others added 24 commits January 18, 2026 06:42
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 150ms 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.
@b3nw
Copy link
Author

b3nw commented Jan 19, 2026

Closing as discovered new issue need to verify.

@b3nw b3nw closed this Jan 19, 2026
@b3nw b3nw reopened this Jan 19, 2026
@b3nw b3nw changed the base branch from dev to shuvcode-dev January 19, 2026 04:58
@b3nw
Copy link
Author

b3nw commented Jan 19, 2026

Closing - the paste coalescing fix is already in shuvcode-dev branch.

@b3nw b3nw closed this Jan 19, 2026
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.