MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / createTextPasteHandler

Function createTextPasteHandler

cli/src/utils/strings.ts:86–107  ·  view source on GitHub ↗
(
  text: string,
  cursorPosition: number,
  onChange: (value: InputValue) => void,
)

Source from the content-addressed store, hash-verified

84 * Reads from clipboard with OpenTUI fallback, then inserts at cursor.
85 */
86export function createTextPasteHandler(
87 text: string,
88 cursorPosition: number,
89 onChange: (value: InputValue) => void,
90): (eventText?: string) => void {
91 return (eventText) => {
92 const rawPaste = eventText || readClipboardText()
93 if (!rawPaste) return
94 const pasteText = Bun.stripANSI(rawPaste)
95 if (!pasteText) return
96 const { newText, newCursor } = insertTextAtCursor(
97 text,
98 cursorPosition,
99 pasteText,
100 )
101 onChange({
102 text: newText,
103 cursorPosition: newCursor,
104 lastEditDueToNav: false,
105 })
106 }
107}
108
109/**
110 * Creates a paste handler that supports both image and text paste.

Callers 2

FeedbackTextSectionFunction · 0.90
strings.test.tsFile · 0.90

Calls 3

readClipboardTextFunction · 0.90
insertTextAtCursorFunction · 0.85
onChangeFunction · 0.85

Tested by

no test coverage detected