tui: keep trimming for normal submits; only raw ! triggers bash
This commit is contained in:
committed by
Peter Steinberger
parent
5fd699d0bf
commit
110b5dafee
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"originHash" : "c0677e232394b5f6b0191b6dbb5bae553d55264f65ae725cd03a8ffdfda9cdd3",
|
||||
"originHash" : "10946d10a137b295c88bae6eb5b1d11f637a00bde46464b19cbf059f77d05e6f",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "commander",
|
||||
@@ -10,6 +10,24 @@
|
||||
"version" : "0.2.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "elevenlabskit",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/steipete/ElevenLabsKit",
|
||||
"state" : {
|
||||
"revision" : "7e3c948d8340abe3977014f3de020edf221e9269",
|
||||
"version" : "0.1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-concurrency-extras",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
|
||||
"state" : {
|
||||
"revision" : "5a3825302b1a0d744183200915a47b508c828e6f",
|
||||
"version" : "1.3.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-syntax",
|
||||
"kind" : "remoteSourceControl",
|
||||
@@ -27,6 +45,24 @@
|
||||
"revision" : "399f76dcd91e4c688ca2301fa24a8cc6d9927211",
|
||||
"version" : "0.99.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swiftui-math",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/gonzalezreal/swiftui-math",
|
||||
"state" : {
|
||||
"revision" : "0b5c2cfaaec8d6193db206f675048eeb5ce95f71",
|
||||
"version" : "0.1.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "textual",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/gonzalezreal/textual",
|
||||
"state" : {
|
||||
"revision" : "a03c1e103d88de4ea0dd8320ea1611ec0d4b29b3",
|
||||
"version" : "0.2.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 3
|
||||
|
||||
@@ -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