From f4ac4622c7d9d4e6260ae88315aacb454029cce1 Mon Sep 17 00:00:00 2001 From: Kingsword Date: Tue, 1 Sep 2026 00:53:54 +0800 Subject: [PATCH] feat(tui): clear non-empty drafts on Ctrl+C --- README.md | 3 ++- packages/zcode-tui/src/index.ts | 6 +++--- scripts/smoke-tui-features.ts | 8 ++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bc3aed5..8a943e5 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,8 @@ boundary, the steer stays in a waiting row next to the editor instead of being shown as committed conversation history. Once the runtime confirms injection, the message moves into the transcript at its actual position and uses the normal user-message `›` prefix. The `↪` marker is reserved for the temporary waiting -row. +row. `Ctrl+C` clears a non-empty editor draft first, including during an active +turn. With an empty editor it cancels the active turn, or exits when idle. To keep a follow-up editable instead, press `Tab` while the editor contains text and completion is closed. The input remains in the local next-turn queue. diff --git a/packages/zcode-tui/src/index.ts b/packages/zcode-tui/src/index.ts index 0075a60..8e03ab1 100644 --- a/packages/zcode-tui/src/index.ts +++ b/packages/zcode-tui/src/index.ts @@ -1408,12 +1408,12 @@ class ZCodeTui { return { consume: true }; } if (matchesKey(data, "ctrl+c")) { - if (this.turnAbortController) { + if (this.editor.getText()) { + this.editor.setText(""); + } else if (this.turnAbortController) { this.pendingSteerInterrupt = undefined; this.turnAbortController.abort(); this.updateActivity("cancelling…"); - } else if (this.editor.getText()) { - this.editor.setText(""); } else { this.stop(); } diff --git a/scripts/smoke-tui-features.ts b/scripts/smoke-tui-features.ts index 9e361cb..29dc9e7 100644 --- a/scripts/smoke-tui-features.ts +++ b/scripts/smoke-tui-features.ts @@ -220,6 +220,14 @@ try { featureTurnStart, 4_000 ); + await sendAndWait( + "Discard this active-turn draft.", + "active-turn draft", + /Discard this active-turn draft\./i + ); + terminal.write("\x03"); + await Bun.sleep(renderSettleMilliseconds); + if (child.exitCode !== null) throw new Error("Ctrl+C exited ZCode instead of clearing the active-turn draft."); await sendAndWait( "Keep the final response concise.\r", "pending active-turn steer",