tui: keep trimming for normal submits; only raw ! triggers bash

This commit is contained in:
Vignesh Natarajan
2026-01-22 11:41:19 -08:00
committed by Peter Steinberger
parent 5fd699d0bf
commit 110b5dafee
4 changed files with 55 additions and 16 deletions

View File

@@ -48,22 +48,25 @@ export function createEditorSubmitHandler(params: {
handleBangLine: (value: string) => Promise<void> | void;
}) {
return (text: string) => {
// NOTE: We intentionally do not trim here.
// The caller decides how to interpret whitespace.
const value = text;
const raw = text;
const value = raw.trim();
params.editor.setText("");
// Keep previous behavior: ignore empty/whitespace-only submissions.
if (!value) return;
// Bash mode: only if the very first character is '!' and it's not just '!'.
// IMPORTANT: use the raw (untrimmed) text so leading spaces do NOT trigger.
// Per requirement: a lone '!' should be treated as a normal message.
if (raw.startsWith("!") && raw !== "!") {
params.editor.addToHistory(raw);
void params.handleBangLine(raw);
return;
}
// Enable built-in editor prompt history navigation (up/down).
params.editor.addToHistory(value);
// Bash mode: only if the very first character is '!' and it's not just '!'.
// Per requirement: a lone '!' should be treated as a normal message.
if (value.startsWith("!") && value !== "!") {
void params.handleBangLine(value);
return;
}
if (value.startsWith("/")) {
void params.handleCommand(value);
return;