feat(ui): add bracketed paste with large-paste marker collapsing#102
Merged
Conversation
…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.
- 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
Contributor
|
@jeoor 请先将分支冲突处理一下。 |
Author
已处理 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
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.Features
ESC[200~/ESC[201~and dispatches pasted text as a single atomic eventsetTimeout(0)to mitigate rendering issues)chalk.yellowchunks[]instead of string+=concatenation to avoid O(n²) on multi-chunk pastesImplementation
src/ui/prompt/useTerminalInput.tssrc/ui/promptBuffer.tscleanPasteContent,expandPasteMarkers,findPasteMarkerBefore/At/Containing,deletePasteMarkerBackward/Forward,hasActivePasteMarkerssrc/ui/prompt/cursor.tsuseBracketedPastehook (follows existinguseTerminalExtendedKeyspattern)src/ui/prompt/index.tsuseBracketedPastesrc/ui/PromptInput.tsxhandlePaste,expandPasteMarkerAtCursor, rendering with yellow highlight, hint textVerification
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
useTerminalInput#45 (closed)