diff --git a/packages/tui/src/components-new/editor.ts b/packages/tui/src/components-new/editor.ts index f5f6a429..0474363b 100644 --- a/packages/tui/src/components-new/editor.ts +++ b/packages/tui/src/components-new/editor.ts @@ -265,10 +265,11 @@ export class Editor implements Component { // Get text and substitute paste markers with actual content let result = this.state.lines.join("\n").trim(); - // Replace all [paste #N] markers with actual paste content + // Replace all [paste #N +xxx lines] markers with actual paste content for (const [pasteId, pasteContent] of this.pastes) { - const marker = `[paste #${pasteId}]`; - result = result.replace(marker, pasteContent); + // Match both old format [paste #N] and new format [paste #N +xxx lines] + const markerRegex = new RegExp(`\\[paste #${pasteId}( \\+\\d+ lines)?\\]`, "g"); + result = result.replace(markerRegex, pasteContent); } // Reset editor and clear pastes @@ -472,8 +473,8 @@ export class Editor implements Component { const pasteId = this.pasteCounter; this.pastes.set(pasteId, filteredText); - // Insert marker like "[paste #1]" - const marker = `[paste #${pasteId}]`; + // Insert marker like "[paste #1 +123 lines]" + const marker = `[paste #${pasteId} +${pastedLines.length} lines]`; for (const char of marker) { this.insertCharacter(char); } diff --git a/packages/tui/test/chat-debug.ts b/packages/tui/test/chat-debug.ts new file mode 100644 index 00000000..f1352477 --- /dev/null +++ b/packages/tui/test/chat-debug.ts @@ -0,0 +1,48 @@ +/** + * Debug version of chat-simple with logging + */ + +import fs from "fs"; +import { ProcessTerminal } from "../src/terminal.js"; +import { Input, Text, TUI } from "../src/tui-new.js"; + +// Clear debug log +fs.writeFileSync("debug.log", ""); + +function log(msg: string) { + fs.appendFileSync("debug.log", msg + "\n"); +} + +// Create terminal +const terminal = new ProcessTerminal(); + +// Wrap terminal methods to log +const originalWrite = terminal.write.bind(terminal); +const originalMoveBy = terminal.moveBy.bind(terminal); + +terminal.write = (data: string) => { + log(`WRITE: ${JSON.stringify(data)}`); + originalWrite(data); +}; + +terminal.moveBy = (lines: number) => { + log(`MOVEBY: ${lines}`); + originalMoveBy(lines); +}; + +// Create TUI +const tui = new TUI(terminal); + +// Create chat container with some initial messages +tui.addChild(new Text("Welcome to Simple Chat!")); +tui.addChild(new Text("Type your messages below. Press Ctrl+C to exit.\n")); + +// Create input field +const input = new Input(); +tui.addChild(input); + +// Focus the input +tui.setFocus(input); + +// Start the TUI +tui.start();