mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 07:04:45 +00:00
fix(tui): remove backslash input buffering (#1037)
Instead of buffering `\` and waiting for the next key, let it be inserted immediately. On Enter, check if preceded by `\` and treat as newline. Removed backslash handling from the Input component entirely.
This commit is contained in:
parent
bac57f81be
commit
d57a26c88b
4 changed files with 61 additions and 43 deletions
|
|
@ -283,8 +283,17 @@ describe("Editor component", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("Shift+Enter handling", () => {
|
||||
it("treats split VS Code Shift+Enter as a newline", () => {
|
||||
describe("Backslash+Enter newline workaround", () => {
|
||||
it("inserts backslash immediately (no buffering)", () => {
|
||||
const editor = new Editor(createTestTUI(), defaultEditorTheme);
|
||||
|
||||
editor.handleInput("\\");
|
||||
|
||||
// Backslash should be visible immediately, not buffered
|
||||
assert.strictEqual(editor.getText(), "\\");
|
||||
});
|
||||
|
||||
it("converts standalone backslash to newline on Enter", () => {
|
||||
const editor = new Editor(createTestTUI(), defaultEditorTheme);
|
||||
|
||||
editor.handleInput("\\");
|
||||
|
|
@ -293,7 +302,7 @@ describe("Editor component", () => {
|
|||
assert.strictEqual(editor.getText(), "\n");
|
||||
});
|
||||
|
||||
it("inserts a literal backslash when not followed by Enter", () => {
|
||||
it("inserts backslash normally when followed by other characters", () => {
|
||||
const editor = new Editor(createTestTUI(), defaultEditorTheme);
|
||||
|
||||
editor.handleInput("\\");
|
||||
|
|
@ -301,6 +310,35 @@ describe("Editor component", () => {
|
|||
|
||||
assert.strictEqual(editor.getText(), "\\x");
|
||||
});
|
||||
|
||||
it("does not trigger newline when backslash is not immediately before cursor", () => {
|
||||
const editor = new Editor(createTestTUI(), defaultEditorTheme);
|
||||
let submitted = false;
|
||||
|
||||
editor.onSubmit = () => {
|
||||
submitted = true;
|
||||
};
|
||||
|
||||
editor.handleInput("\\");
|
||||
editor.handleInput("x");
|
||||
editor.handleInput("\r");
|
||||
|
||||
// Should submit, not insert newline (backslash not at cursor)
|
||||
assert.strictEqual(submitted, true);
|
||||
});
|
||||
|
||||
it("only removes one backslash when multiple are present", () => {
|
||||
const editor = new Editor(createTestTUI(), defaultEditorTheme);
|
||||
|
||||
editor.handleInput("\\");
|
||||
editor.handleInput("\\");
|
||||
editor.handleInput("\\");
|
||||
assert.strictEqual(editor.getText(), "\\\\\\");
|
||||
|
||||
editor.handleInput("\r");
|
||||
// Only the last backslash is removed, newline inserted
|
||||
assert.strictEqual(editor.getText(), "\\\\\n");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Unicode text editing behavior", () => {
|
||||
|
|
|
|||
|
|
@ -3,23 +3,28 @@ import { describe, it } from "node:test";
|
|||
import { Input } from "../src/components/input.js";
|
||||
|
||||
describe("Input component", () => {
|
||||
it("treats split VS Code Shift+Enter as submit", () => {
|
||||
it("submits value including backslash on Enter", () => {
|
||||
const input = new Input();
|
||||
let submitted: string | undefined;
|
||||
|
||||
input.setValue("hello");
|
||||
input.onSubmit = (value) => {
|
||||
submitted = value;
|
||||
};
|
||||
|
||||
// Type hello, then backslash, then Enter
|
||||
input.handleInput("h");
|
||||
input.handleInput("e");
|
||||
input.handleInput("l");
|
||||
input.handleInput("l");
|
||||
input.handleInput("o");
|
||||
input.handleInput("\\");
|
||||
input.handleInput("\r");
|
||||
|
||||
assert.strictEqual(submitted, "hello");
|
||||
assert.strictEqual(input.getValue(), "hello");
|
||||
// Input is single-line, no backslash+Enter workaround
|
||||
assert.strictEqual(submitted, "hello\\");
|
||||
});
|
||||
|
||||
it("inserts a literal backslash when not followed by Enter", () => {
|
||||
it("inserts backslash as regular character", () => {
|
||||
const input = new Input();
|
||||
|
||||
input.handleInput("\\");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue