mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 01:01:42 +00:00
Add helper functions for key detection and update usage
- Add isCtrlA/C/E/K/O/P/T/U/W helper functions that check both raw and Kitty formats - Add isAltBackspace helper function - Refactor editor.ts, input.ts, select-list.ts to use helper functions - Refactor custom-editor.ts, session-selector.ts, user-message-selector.ts - Add CHANGELOG entry for the Shift+Enter fix
This commit is contained in:
parent
4a4531f887
commit
c3c2bffc68
9 changed files with 146 additions and 50 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import type { AutocompleteProvider, CombinedAutocompleteProvider } from "../autocomplete.js";
|
||||
import { Keys } from "../keys.js";
|
||||
import { isAltBackspace, isCtrlA, isCtrlC, isCtrlE, isCtrlK, isCtrlU, isCtrlW, Keys } from "../keys.js";
|
||||
import type { Component } from "../tui.js";
|
||||
import { visibleWidth } from "../utils.js";
|
||||
import { SelectList, type SelectListTheme } from "./select-list.js";
|
||||
|
|
@ -260,8 +260,7 @@ export class Editor implements Component {
|
|||
// Handle special key combinations first
|
||||
|
||||
// Ctrl+C - Exit (let parent handle this)
|
||||
// Handle both raw byte (\x03) and Kitty keyboard protocol
|
||||
if (data.charCodeAt(0) === 3 || data === Keys.CTRL_C) {
|
||||
if (isCtrlC(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -360,28 +359,28 @@ export class Editor implements Component {
|
|||
}
|
||||
|
||||
// Continue with rest of input handling
|
||||
// Ctrl+K - Delete to end of line (raw byte or Kitty protocol)
|
||||
if (data.charCodeAt(0) === 11 || data === Keys.CTRL_K) {
|
||||
// Ctrl+K - Delete to end of line
|
||||
if (isCtrlK(data)) {
|
||||
this.deleteToEndOfLine();
|
||||
}
|
||||
// Ctrl+U - Delete to start of line (raw byte or Kitty protocol)
|
||||
else if (data.charCodeAt(0) === 21 || data === Keys.CTRL_U) {
|
||||
// Ctrl+U - Delete to start of line
|
||||
else if (isCtrlU(data)) {
|
||||
this.deleteToStartOfLine();
|
||||
}
|
||||
// Ctrl+W - Delete word backwards (raw byte or Kitty protocol)
|
||||
else if (data.charCodeAt(0) === 23 || data === Keys.CTRL_W) {
|
||||
// Ctrl+W - Delete word backwards
|
||||
else if (isCtrlW(data)) {
|
||||
this.deleteWordBackwards();
|
||||
}
|
||||
// Option/Alt+Backspace (e.g. Ghostty sends ESC + DEL, or Kitty protocol)
|
||||
else if (data === "\x1b\x7f" || data === Keys.ALT_BACKSPACE) {
|
||||
// Option/Alt+Backspace - Delete word backwards
|
||||
else if (isAltBackspace(data)) {
|
||||
this.deleteWordBackwards();
|
||||
}
|
||||
// Ctrl+A - Move to start of line (raw byte or Kitty protocol)
|
||||
else if (data.charCodeAt(0) === 1 || data === Keys.CTRL_A) {
|
||||
// Ctrl+A - Move to start of line
|
||||
else if (isCtrlA(data)) {
|
||||
this.moveToLineStart();
|
||||
}
|
||||
// Ctrl+E - Move to end of line (raw byte or Kitty protocol)
|
||||
else if (data.charCodeAt(0) === 5 || data === Keys.CTRL_E) {
|
||||
// Ctrl+E - Move to end of line
|
||||
else if (isCtrlE(data)) {
|
||||
this.moveToLineEnd();
|
||||
}
|
||||
// New line shortcuts (but not plain LF/CR which should be submit)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Keys } from "../keys.js";
|
||||
import { isAltBackspace, isCtrlA, isCtrlE, isCtrlK, isCtrlU, isCtrlW } from "../keys.js";
|
||||
import type { Component } from "../tui.js";
|
||||
import { visibleWidth } from "../utils.js";
|
||||
|
||||
|
|
@ -102,39 +102,39 @@ export class Input implements Component {
|
|||
return;
|
||||
}
|
||||
|
||||
if (data === "\x01" || data === Keys.CTRL_A) {
|
||||
// Ctrl+A - beginning of line (raw byte or Kitty protocol)
|
||||
if (isCtrlA(data)) {
|
||||
// Ctrl+A - beginning of line
|
||||
this.cursor = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (data === "\x05" || data === Keys.CTRL_E) {
|
||||
// Ctrl+E - end of line (raw byte or Kitty protocol)
|
||||
if (isCtrlE(data)) {
|
||||
// Ctrl+E - end of line
|
||||
this.cursor = this.value.length;
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.charCodeAt(0) === 23 || data === Keys.CTRL_W) {
|
||||
// Ctrl+W - delete word backwards (raw byte or Kitty protocol)
|
||||
if (isCtrlW(data)) {
|
||||
// Ctrl+W - delete word backwards
|
||||
this.deleteWordBackwards();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data === "\x1b\x7f" || data === Keys.ALT_BACKSPACE) {
|
||||
// Option/Alt+Backspace - delete word backwards (legacy or Kitty protocol)
|
||||
if (isAltBackspace(data)) {
|
||||
// Option/Alt+Backspace - delete word backwards
|
||||
this.deleteWordBackwards();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.charCodeAt(0) === 21 || data === Keys.CTRL_U) {
|
||||
// Ctrl+U - delete from cursor to start of line (raw byte or Kitty protocol)
|
||||
if (isCtrlU(data)) {
|
||||
// Ctrl+U - delete from cursor to start of line
|
||||
this.value = this.value.slice(this.cursor);
|
||||
this.cursor = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.charCodeAt(0) === 11 || data === Keys.CTRL_K) {
|
||||
// Ctrl+K - delete from cursor to end of line (raw byte or Kitty protocol)
|
||||
if (isCtrlK(data)) {
|
||||
// Ctrl+K - delete from cursor to end of line
|
||||
this.value = this.value.slice(0, this.cursor);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Keys } from "../keys.js";
|
||||
import { isCtrlC } from "../keys.js";
|
||||
import type { Component } from "../tui.js";
|
||||
import { truncateToWidth } from "../utils.js";
|
||||
|
||||
|
|
@ -162,8 +162,8 @@ export class SelectList implements Component {
|
|||
this.onSelect(selectedItem);
|
||||
}
|
||||
}
|
||||
// Escape or Ctrl+C (raw byte or Kitty keyboard protocol)
|
||||
else if (keyData === "\x1b" || keyData === "\x03" || keyData === Keys.CTRL_C) {
|
||||
// Escape or Ctrl+C
|
||||
else if (keyData === "\x1b" || isCtrlC(keyData)) {
|
||||
if (this.onCancel) {
|
||||
this.onCancel();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue