Merge kitty-protocol-support into main

This commit is contained in:
Mario Zechner 2025-12-19 01:21:47 +01:00
commit 139af12b37
11 changed files with 281 additions and 28 deletions

View file

@ -1,4 +1,5 @@
import type { AutocompleteProvider, CombinedAutocompleteProvider } from "../autocomplete.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";
@ -259,7 +260,7 @@ export class Editor implements Component {
// Handle special key combinations first
// Ctrl+C - Exit (let parent handle this)
if (data.charCodeAt(0) === 3) {
if (isCtrlC(data)) {
return;
}
@ -359,34 +360,36 @@ export class Editor implements Component {
// Continue with rest of input handling
// Ctrl+K - Delete to end of line
if (data.charCodeAt(0) === 11) {
if (isCtrlK(data)) {
this.deleteToEndOfLine();
}
// Ctrl+U - Delete to start of line
else if (data.charCodeAt(0) === 21) {
else if (isCtrlU(data)) {
this.deleteToStartOfLine();
}
// Ctrl+W - Delete word backwards
else if (data.charCodeAt(0) === 23) {
else if (isCtrlW(data)) {
this.deleteWordBackwards();
}
// Option/Alt+Backspace (e.g. Ghostty sends ESC + DEL)
else if (data === "\x1b\x7f") {
// Option/Alt+Backspace - Delete word backwards
else if (isAltBackspace(data)) {
this.deleteWordBackwards();
}
// Ctrl+A - Move to start of line
else if (data.charCodeAt(0) === 1) {
else if (isCtrlA(data)) {
this.moveToLineStart();
}
// Ctrl+E - Move to end of line
else if (data.charCodeAt(0) === 5) {
else if (isCtrlE(data)) {
this.moveToLineEnd();
}
// New line shortcuts (but not plain LF/CR which should be submit)
else if (
(data.charCodeAt(0) === 10 && data.length > 1) || // Ctrl+Enter with modifiers
data === "\x1b\r" || // Option+Enter in some terminals
data === "\x1b[13;2~" || // Shift+Enter in some terminals
data === "\x1b\r" || // Option+Enter in some terminals (legacy)
data === "\x1b[13;2~" || // Shift+Enter in some terminals (legacy format)
data === Keys.SHIFT_ENTER || // Shift+Enter in Kitty keyboard protocol
data === Keys.ALT_ENTER || // Alt+Enter in Kitty keyboard protocol
(data.length > 1 && data.includes("\x1b") && data.includes("\r")) ||
(data === "\n" && data.length === 1) || // Shift+Enter from iTerm2 mapping
data === "\\\r" // Shift+Enter in VS Code terminal

View file

@ -1,3 +1,4 @@
import { isAltBackspace, isCtrlA, isCtrlE, isCtrlK, isCtrlU, isCtrlW } from "../keys.js";
import type { Component } from "../tui.js";
import { visibleWidth } from "../utils.js";
@ -101,38 +102,38 @@ export class Input implements Component {
return;
}
if (data === "\x01") {
if (isCtrlA(data)) {
// Ctrl+A - beginning of line
this.cursor = 0;
return;
}
if (data === "\x05") {
if (isCtrlE(data)) {
// Ctrl+E - end of line
this.cursor = this.value.length;
return;
}
if (data.charCodeAt(0) === 23) {
if (isCtrlW(data)) {
// Ctrl+W - delete word backwards
this.deleteWordBackwards();
return;
}
if (data === "\x1b\x7f") {
if (isAltBackspace(data)) {
// Option/Alt+Backspace - delete word backwards
this.deleteWordBackwards();
return;
}
if (data.charCodeAt(0) === 21) {
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) {
if (isCtrlK(data)) {
// Ctrl+K - delete from cursor to end of line
this.value = this.value.slice(0, this.cursor);
return;

View file

@ -1,3 +1,4 @@
import { isCtrlC } from "../keys.js";
import type { Component } from "../tui.js";
import { truncateToWidth } from "../utils.js";
@ -162,7 +163,7 @@ export class SelectList implements Component {
}
}
// Escape or Ctrl+C
else if (keyData === "\x1b" || keyData === "\x03") {
else if (keyData === "\x1b" || isCtrlC(keyData)) {
if (this.onCancel) {
this.onCancel();
}