fix(tui): honor keybindings for submit fallback

This commit is contained in:
Mario Zechner 2026-02-03 01:10:06 +01:00
parent d2139d8ed2
commit c64e228b76
2 changed files with 43 additions and 25 deletions

View file

@ -28,6 +28,11 @@ return config
## VS Code (Integrated Terminal) ## VS Code (Integrated Terminal)
`keybindings.json` locations:
- macOS: `~/Library/Application Support/Code/User/keybindings.json`
- Linux: `~/.config/Code/User/keybindings.json`
- Windows: `%APPDATA%\\Code\\User\\keybindings.json`
Add to `keybindings.json` to enable `Shift+Enter` for multi-line input: Add to `keybindings.json` to enable `Shift+Enter` for multi-line input:
```json ```json

View file

@ -621,15 +621,13 @@ export class Editor implements Component, Focusable {
return; return;
} }
// New line (Shift+Enter, Alt+Enter, etc.) // New line
if ( if (kb.matches(data, "newLine")) {
kb.matches(data, "newLine") || if (this.shouldSubmitOnBackslashEnter(data, kb)) {
(data.charCodeAt(0) === 10 && data.length > 1) || this.handleBackspace();
data === "\x1b\r" || this.submitValue();
data === "\x1b[13;2~" || return;
(data.length > 1 && data.includes("\x1b") && data.includes("\r")) || }
(data === "\n" && data.length === 1)
) {
this.addNewLine(); this.addNewLine();
return; return;
} }
@ -647,22 +645,7 @@ export class Editor implements Component, Focusable {
return; return;
} }
let result = this.state.lines.join("\n").trim(); this.submitValue();
for (const [pasteId, pasteContent] of this.pastes) {
const markerRegex = new RegExp(`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`, "g");
result = result.replace(markerRegex, pasteContent);
}
this.state = { lines: [""], cursorLine: 0, cursorCol: 0 };
this.pastes.clear();
this.pasteCounter = 0;
this.historyIndex = -1;
this.scrollOffset = 0;
this.undoStack.length = 0;
this.lastAction = null;
if (this.onChange) this.onChange("");
if (this.onSubmit) this.onSubmit(result);
return; return;
} }
@ -1068,6 +1051,36 @@ export class Editor implements Component, Focusable {
} }
} }
private shouldSubmitOnBackslashEnter(data: string, kb: ReturnType<typeof getEditorKeybindings>): boolean {
if (this.disableSubmit) return false;
if (!matchesKey(data, "enter")) return false;
const submitKeys = kb.getKeys("submit");
const hasShiftEnter = submitKeys.includes("shift+enter") || submitKeys.includes("shift+return");
if (!hasShiftEnter) return false;
const currentLine = this.state.lines[this.state.cursorLine] || "";
return this.state.cursorCol > 0 && currentLine[this.state.cursorCol - 1] === "\\";
}
private submitValue(): void {
let result = this.state.lines.join("\n").trim();
for (const [pasteId, pasteContent] of this.pastes) {
const markerRegex = new RegExp(`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`, "g");
result = result.replace(markerRegex, pasteContent);
}
this.state = { lines: [""], cursorLine: 0, cursorCol: 0 };
this.pastes.clear();
this.pasteCounter = 0;
this.historyIndex = -1;
this.scrollOffset = 0;
this.undoStack.length = 0;
this.lastAction = null;
if (this.onChange) this.onChange("");
if (this.onSubmit) this.onSubmit(result);
}
private handleBackspace(): void { private handleBackspace(): void {
this.historyIndex = -1; // Exit history browsing mode this.historyIndex = -1; // Exit history browsing mode
this.lastAction = null; this.lastAction = null;