|
1 | | -import { TextAttributes } from '@opentui/core' |
| 1 | +import { |
| 2 | + decodePasteBytes, |
| 3 | + stripAnsiSequences, |
| 4 | + TextAttributes, |
| 5 | +} from '@opentui/core' |
2 | 6 | import { useAppContext, useKeyboard, useRenderer } from '@opentui/react' |
3 | 7 | import { |
4 | 8 | forwardRef, |
@@ -27,6 +31,10 @@ import type { |
27 | 31 | TextRenderable, |
28 | 32 | } from '@opentui/core' |
29 | 33 |
|
| 34 | +function getPasteText(event: PasteEvent): string { |
| 35 | + return stripAnsiSequences(decodePasteBytes(event.bytes)) |
| 36 | +} |
| 37 | + |
30 | 38 | // Helper functions for text manipulation |
31 | 39 | function findLineStart(text: string, cursor: number): number { |
32 | 40 | let pos = Math.max(0, Math.min(cursor, text.length)) |
@@ -1046,7 +1054,7 @@ export const MultilineInput = forwardRef< |
1046 | 1054 |
|
1047 | 1055 | const handlePaste = (event: PasteEvent) => { |
1048 | 1056 | pasteHandledRef.current = true |
1049 | | - onPasteRef.current(event.text) |
| 1057 | + onPasteRef.current(getPasteText(event)) |
1050 | 1058 | // Reset dedup flag after microtask so scrollbox handler (which fires |
1051 | 1059 | // synchronously after global listeners) sees it as handled, but future |
1052 | 1060 | // paste events are not blocked. |
@@ -1145,7 +1153,7 @@ export const MultilineInput = forwardRef< |
1145 | 1153 | // Backup paste handler: fires if the global keyHandler listener |
1146 | 1154 | // didn't catch this event (dedup prevents double-handling) |
1147 | 1155 | if (pasteHandledRef.current) return |
1148 | | - onPasteRef.current(event.text) |
| 1156 | + onPasteRef.current(getPasteText(event)) |
1149 | 1157 | }} |
1150 | 1158 | onMouseDown={handleMouseDown} |
1151 | 1159 | style={{ |
|
0 commit comments