mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 20:04:55 +00:00
fix(tui): honor keybindings for submit fallback
This commit is contained in:
parent
d2139d8ed2
commit
c64e228b76
2 changed files with 43 additions and 25 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue