From dd28c2f2bbaa6a89fbd3b4c2bdbd9a7d5bd29e6f Mon Sep 17 00:00:00 2001 From: Ting-Wai To <40179554+tingwai@users.noreply.github.com> Date: Wed, 13 Aug 2025 17:43:40 -0700 Subject: [PATCH] fix: normal multi-line paste doesn't mess up input box --- src/ui/TextBuffer.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ui/TextBuffer.ts b/src/ui/TextBuffer.ts index 47da9d3a0..4c0ef4bb4 100644 --- a/src/ui/TextBuffer.ts +++ b/src/ui/TextBuffer.ts @@ -39,9 +39,13 @@ export class TextBuffer { } insertText(text: string): void { + // Normalize line endings to prevent terminal display issues + const normalizedText = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n"); this._text = - this._text.slice(0, this._cursor) + text + this._text.slice(this._cursor); - this._cursor += text.length; + this._text.slice(0, this._cursor) + + normalizedText + + this._text.slice(this._cursor); + this._cursor += normalizedText.length; } deleteCharAt(position: number): void { @@ -268,7 +272,7 @@ export class TextBuffer { // instead of using bracketed paste mode. We detect this by timing between inputs. if ( input.length > RAPID_INPUT_THRESHOLD || - (input.length > 50 && this._rapidInputBuffer.length === 0) + (input.length >= 50 && this._rapidInputBuffer.length === 0) ) { this._rapidInputStartPos = this._cursor;