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:
Sviatoslav Abakumov 2026-01-29 05:47:15 +04:00 committed by GitHub
parent bac57f81be
commit d57a26c88b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 61 additions and 43 deletions

View file

@ -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", () => {