tui: keep trimming for normal submits; only raw ! triggers bash
This commit is contained in:
committed by
Peter Steinberger
parent
5fd699d0bf
commit
110b5dafee
@@ -22,7 +22,7 @@ describe("createEditorSubmitHandler", () => {
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith("hello world");
|
||||
});
|
||||
|
||||
it("does not trim input before adding to history", () => {
|
||||
it("trims input before adding to history", () => {
|
||||
const editor = {
|
||||
setText: vi.fn(),
|
||||
addToHistory: vi.fn(),
|
||||
@@ -37,7 +37,7 @@ describe("createEditorSubmitHandler", () => {
|
||||
|
||||
handler(" hi ");
|
||||
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith(" hi ");
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith("hi");
|
||||
});
|
||||
|
||||
it("does not add empty-string submissions to history", () => {
|
||||
|
||||
@@ -50,7 +50,7 @@ describe("createEditorSubmitHandler", () => {
|
||||
expect(sendMessage).toHaveBeenCalledWith("!");
|
||||
});
|
||||
|
||||
it("does not trim input", () => {
|
||||
it("trims normal messages before sending and adding to history", () => {
|
||||
const editor = {
|
||||
setText: vi.fn(),
|
||||
addToHistory: vi.fn(),
|
||||
@@ -68,7 +68,7 @@ describe("createEditorSubmitHandler", () => {
|
||||
|
||||
onSubmit(" hello ");
|
||||
|
||||
expect(sendMessage).toHaveBeenCalledWith(" hello ");
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith(" hello ");
|
||||
expect(sendMessage).toHaveBeenCalledWith("hello");
|
||||
expect(editor.addToHistory).toHaveBeenCalledWith("hello");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user