mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 02:03:16 +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", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue