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" : [
|
"pins" : [
|
||||||
{
|
{
|
||||||
"identity" : "commander",
|
"identity" : "commander",
|
||||||
@@ -10,6 +10,24 @@
|
|||||||
"version" : "0.2.1"
|
"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",
|
"identity" : "swift-syntax",
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
@@ -27,6 +45,24 @@
|
|||||||
"revision" : "399f76dcd91e4c688ca2301fa24a8cc6d9927211",
|
"revision" : "399f76dcd91e4c688ca2301fa24a8cc6d9927211",
|
||||||
"version" : "0.99.0"
|
"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
|
"version" : 3
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ describe("createEditorSubmitHandler", () => {
|
|||||||
expect(editor.addToHistory).toHaveBeenCalledWith("hello world");
|
expect(editor.addToHistory).toHaveBeenCalledWith("hello world");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not trim input before adding to history", () => {
|
it("trims input before adding to history", () => {
|
||||||
const editor = {
|
const editor = {
|
||||||
setText: vi.fn(),
|
setText: vi.fn(),
|
||||||
addToHistory: vi.fn(),
|
addToHistory: vi.fn(),
|
||||||
@@ -37,7 +37,7 @@ describe("createEditorSubmitHandler", () => {
|
|||||||
|
|
||||||
handler(" hi ");
|
handler(" hi ");
|
||||||
|
|
||||||
expect(editor.addToHistory).toHaveBeenCalledWith(" hi ");
|
expect(editor.addToHistory).toHaveBeenCalledWith("hi");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not add empty-string submissions to history", () => {
|
it("does not add empty-string submissions to history", () => {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ describe("createEditorSubmitHandler", () => {
|
|||||||
expect(sendMessage).toHaveBeenCalledWith("!");
|
expect(sendMessage).toHaveBeenCalledWith("!");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not trim input", () => {
|
it("trims normal messages before sending and adding to history", () => {
|
||||||
const editor = {
|
const editor = {
|
||||||
setText: vi.fn(),
|
setText: vi.fn(),
|
||||||
addToHistory: vi.fn(),
|
addToHistory: vi.fn(),
|
||||||
@@ -68,7 +68,7 @@ describe("createEditorSubmitHandler", () => {
|
|||||||
|
|
||||||
onSubmit(" hello ");
|
onSubmit(" hello ");
|
||||||
|
|
||||||
expect(sendMessage).toHaveBeenCalledWith(" hello ");
|
expect(sendMessage).toHaveBeenCalledWith("hello");
|
||||||
expect(editor.addToHistory).toHaveBeenCalledWith(" hello ");
|
expect(editor.addToHistory).toHaveBeenCalledWith("hello");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,22 +48,25 @@ export function createEditorSubmitHandler(params: {
|
|||||||
handleBangLine: (value: string) => Promise<void> | void;
|
handleBangLine: (value: string) => Promise<void> | void;
|
||||||
}) {
|
}) {
|
||||||
return (text: string) => {
|
return (text: string) => {
|
||||||
// NOTE: We intentionally do not trim here.
|
const raw = text;
|
||||||
// The caller decides how to interpret whitespace.
|
const value = raw.trim();
|
||||||
const value = text;
|
|
||||||
params.editor.setText("");
|
params.editor.setText("");
|
||||||
|
|
||||||
|
// Keep previous behavior: ignore empty/whitespace-only submissions.
|
||||||
if (!value) return;
|
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).
|
// Enable built-in editor prompt history navigation (up/down).
|
||||||
params.editor.addToHistory(value);
|
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("/")) {
|
if (value.startsWith("/")) {
|
||||||
void params.handleCommand(value);
|
void params.handleCommand(value);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user