From 0d477d39f9ed9246af6238d5b8b7b07d309f648d Mon Sep 17 00:00:00 2001 From: Aliou Diallo Date: Sun, 4 Jan 2026 18:11:42 +0100 Subject: [PATCH] fix(tui): expand paste markers when opening external editor (#444) * fix(tui): expand paste markers when opening external editor Add getExpandedText() method to Editor that substitutes paste markers with actual content. Use it in Ctrl-G external editor flow so users see full pasted content instead of [paste #N ...] placeholders. * docs: add changelog entries for #444 --- packages/coding-agent/CHANGELOG.md | 2 ++ .../src/modes/interactive/interactive-mode.ts | 2 +- packages/tui/CHANGELOG.md | 4 ++++ packages/tui/src/components/editor.ts | 13 +++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index 3826cb37..11ba4ff4 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -1,9 +1,11 @@ # Changelog ## [Unreleased] + ### Fixed - Fixed potential text decoding issues in bash executor by using streaming TextDecoder instead of Buffer.toString() +- External editor (Ctrl-G) now shows full pasted content instead of `[paste #N ...]` placeholders ([#444](https://github.com/badlogic/pi-mono/pull/444) by [@aliou](https://github.com/aliou)) ## [0.33.0] - 2026-01-04 diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts index 82bc764b..fff4267d 100644 --- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts +++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts @@ -1627,7 +1627,7 @@ export class InteractiveMode { return; } - const currentText = this.editor.getText(); + const currentText = this.editor.getExpandedText(); const tmpFile = path.join(os.tmpdir(), `pi-editor-${Date.now()}.pi.md`); try { diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md index 2c740e18..dadd236e 100644 --- a/packages/tui/CHANGELOG.md +++ b/packages/tui/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- `Editor.getExpandedText()` method that returns text with paste markers expanded to their actual content ([#444](https://github.com/badlogic/pi-mono/pull/444) by [@aliou](https://github.com/aliou)) + ## [0.33.0] - 2026-01-04 ### Breaking Changes diff --git a/packages/tui/src/components/editor.ts b/packages/tui/src/components/editor.ts index bee20d5a..03ec7243 100644 --- a/packages/tui/src/components/editor.ts +++ b/packages/tui/src/components/editor.ts @@ -696,6 +696,19 @@ export class Editor implements Component { return this.state.lines.join("\n"); } + /** + * Get text with paste markers expanded to their actual content. + * Use this when you need the full content (e.g., for external editor). + */ + getExpandedText(): string { + let result = this.state.lines.join("\n"); + for (const [pasteId, pasteContent] of this.pastes) { + const markerRegex = new RegExp(`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`, "g"); + result = result.replace(markerRegex, pasteContent); + } + return result; + } + getLines(): string[] { return [...this.state.lines]; }