mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 23:01:30 +00:00
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.
35 lines
880 B
TypeScript
35 lines
880 B
TypeScript
import assert from "node:assert";
|
|
import { describe, it } from "node:test";
|
|
import { Input } from "../src/components/input.js";
|
|
|
|
describe("Input component", () => {
|
|
it("submits value including backslash on Enter", () => {
|
|
const input = new Input();
|
|
let submitted: string | undefined;
|
|
|
|
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");
|
|
|
|
// Input is single-line, no backslash+Enter workaround
|
|
assert.strictEqual(submitted, "hello\\");
|
|
});
|
|
|
|
it("inserts backslash as regular character", () => {
|
|
const input = new Input();
|
|
|
|
input.handleInput("\\");
|
|
input.handleInput("x");
|
|
|
|
assert.strictEqual(input.getValue(), "\\x");
|
|
});
|
|
});
|