summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/shared/text-buffer.ts
diff options
context:
space:
mode:
authorJacob Richman <[email protected]>2025-05-16 13:17:48 -0700
committerGitHub <[email protected]>2025-05-16 13:17:48 -0700
commit8b959c2060352182889e8e056de8a62a301778df (patch)
treea0191b5f16146ba7bc9102cda5337dec2fbd1bfc /packages/cli/src/ui/components/shared/text-buffer.ts
parent1728bf3f44f7298c6f86366eee9a11913aca5aa0 (diff)
strip escape characters when pasting. (#386)
Diffstat (limited to 'packages/cli/src/ui/components/shared/text-buffer.ts')
-rw-r--r--packages/cli/src/ui/components/shared/text-buffer.ts8
1 files changed, 7 insertions, 1 deletions
diff --git a/packages/cli/src/ui/components/shared/text-buffer.ts b/packages/cli/src/ui/components/shared/text-buffer.ts
index 5f25f9e0..b13a57c6 100644
--- a/packages/cli/src/ui/components/shared/text-buffer.ts
+++ b/packages/cli/src/ui/components/shared/text-buffer.ts
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import stripAnsi from 'strip-ansi';
import { spawnSync } from 'child_process';
import fs from 'fs';
import os from 'os';
@@ -1127,7 +1128,12 @@ export function useTextBuffer({
)
backspace();
else if (key['delete']) del();
- else if (input && !key['ctrl'] && !key['meta']) insert(input);
+ else if (input && !key['ctrl'] && !key['meta']) {
+ // Heuristic for paste: if input is longer than 1 char (potential paste)
+ // strip ANSI escape codes.
+ const cleanedInput = input.length > 1 ? stripAnsi(input) : input;
+ insert(cleanedInput);
+ }
const textChanged = text !== beforeText;
// After operations, visualCursor might not be immediately updated if the change