Skip to content

feat(ui): add bracketed paste with large-paste marker collapsing#102

Merged
qorzj merged 3 commits into
lessweb:mainfrom
jeoor:feat/paste-marker
May 21, 2026
Merged

feat(ui): add bracketed paste with large-paste marker collapsing#102
qorzj merged 3 commits into
lessweb:mainfrom
jeoor:feat/paste-marker

Conversation

@jeoor
Copy link
Copy Markdown

@jeoor jeoor commented May 20, 2026

Summary

When pasting a large block of text (>10 lines or >1000 characters), the content is replaced with a compact marker like [paste #1 +63 lines] instead of inserting the full text.

paste-marker-demo

Features

  • Bracketed paste detection — Detects ESC[200~ / ESC[201~ and dispatches pasted text as a single atomic event
  • Large paste collapsing — Pastes >10 lines or >1000 chars are stored and replaced with a compact marker
  • Ctrl+O toggle — Expand to view/edit full content, collapse back to marker (with setTimeout(0) to mitigate rendering issues)
  • Atomic deletion — Backspace/delete on a paste marker removes the entire marker at once
  • Auto-expand on submit — Markers are expanded to full content before sending to the LLM
  • Yellow highlighting — Markers are highlighted with chalk.yellow
  • Lazy text cleaning — Control char filtering and line ending normalization are deferred to expand/submit time
  • Array-based chunk buffering — Uses chunks[] instead of string += concatenation to avoid O(n²) on multi-chunk pastes

Implementation

File Changes
src/ui/prompt/useTerminalInput.ts Paste bracketing: detection, chunk buffering, same-chunk immediate processing
src/ui/promptBuffer.ts cleanPasteContent, expandPasteMarkers, findPasteMarkerBefore/At/Containing, deletePasteMarkerBackward/Forward, hasActivePasteMarkers
src/ui/prompt/cursor.ts useBracketedPaste hook (follows existing useTerminalExtendedKeys pattern)
src/ui/prompt/index.ts Export useBracketedPaste
src/ui/PromptInput.tsx handlePaste, expandPasteMarkerAtCursor, rendering with yellow highlight, hint text

Verification

typecheck  — 0 error
eslint    — 0 error, 0 warning
prettier  — All matched files use Prettier code style
test      — 18/18 prompt buffer tests pass
build     — 414.7kb, successful

Known Limitation

Expand/collapse briefly clears Ink <Static> content above the prompt. This is a React render pipeline constraint, not introduced by this PR.

Reference

@jeoor jeoor force-pushed the feat/paste-marker branch from a4710cd to 6e1360a Compare May 20, 2026 14:16
…psing

- Detect bracketed paste (ESC[200~ / ESC[201~) and dispatch as atomic paste event
- Large pastes (>10 lines or >1000 chars) are stored and replaced with a compact marker [paste #N]
- Ctrl+O toggles expand/collapse, backspace/delete atomically remove the entire marker
- Markers are highlighted with chalk.yellow and expanded back on submit
- Follows existing terminal hook patterns (useBracketedPaste alongside useTerminalExtendedKeys)
- Array-based chunk buffering to avoid O(n²) string concatenation on multi-chunk pastes
- Lazy text cleaning deferred to expand/submit time

Known limitation: expand/collapse briefly clears Ink <Static> content above the prompt (React render pipeline constraint).

Reference: PR lessweb#45 (closed), inspired by pi project's paste marker approach.
@jeoor jeoor force-pushed the feat/paste-marker branch from 6e1360a to 3a8041f Compare May 20, 2026 14:22
- hasActivePasteMarkers now checks validIds map, not just regex match
- deletePasteMarkerBackward/Forward only atomically delete real paste markers
- renderBufferWithCursor and renderFocusedText only highlight markers with valid IDs
- PASTE_MARKER_REGEX requires line/char suffix (no bare [paste #N])
- Fix empty buffer cursor rendering in renderFocusedText regression
- All render/test call sites updated to pass pastesRef.current
@jeoor jeoor force-pushed the feat/paste-marker branch from ac1dbc0 to bb95daf Compare May 20, 2026 14:52
@hqwlkj
Copy link
Copy Markdown
Contributor

hqwlkj commented May 21, 2026

@jeoor 请先将分支冲突处理一下。

@jeoor
Copy link
Copy Markdown
Author

jeoor commented May 21, 2026

@jeoor 请先将分支冲突处理一下。

已处理

@qorzj qorzj merged commit 6c44439 into lessweb:main May 21, 2026
9 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.

3 participants