Improve mobile terminal input, selection, and resizing (#1607)

* Improve mobile terminal typing and selection

* Address mobile terminal review feedback

* Remove dead native terminal input branch

* Replay bracketed paste in terminal preamble

* Stop per-key terminal resize claims

* Stabilize terminal resize browser test

* Use tracked terminal mode for native paste

* Restore terminal toolbar focus handling

* Adapt native terminal to active visibility state

* Stabilize native mobile terminal interactions

* Add native terminal fallback boundary

* test(app): expect explicit terminal resize reclaim

* fix(app): stabilize terminal buffer coordinates

* fix(app): restrict terminal resize ownership

* fix(terminal): gate restored input modes

* fix(app): recover stalled terminal WebViews

* chore(app): remove obsolete terminal harnesses

* fix(app): make terminal resize claims explicit

* test(app): stabilize native terminal device flows

* test(app): track absolute scrollback coordinates

* fix(app): isolate terminal WebView streams

* fix(terminal): arbitrate size ownership across clients

The daemon now distinguishes explicit ownership claims from passive geometry updates. This keeps the active client authoritative while allowing its split, viewport, and keyboard changes to resize the PTY without idle clients stealing it.

* test(server): make worker resize assertion portable

Query the worker's authoritative terminal snapshot instead of invoking a Unix-only shell command, so the resize regression exercises the same boundary on Windows and Unix.
This commit is contained in:
Mohamed Boudra
2026-08-03 19:01:34 +08:00
committed by GitHub
parent 2948a435ed
commit 04fe30a3e2
119 changed files with 9843 additions and 1032 deletions
+40 -6
View File
@@ -6,15 +6,21 @@ export interface TerminalInputModeFeedResult {
export interface TerminalInputModeState {
kittyKeyboardFlags: number;
win32InputMode: boolean;
applicationCursorKeys?: boolean;
bracketedPaste?: boolean;
}
export const DEFAULT_TERMINAL_INPUT_MODE_STATE: TerminalInputModeState = {
kittyKeyboardFlags: 0,
win32InputMode: false,
applicationCursorKeys: false,
bracketedPaste: false,
};
const ESC = String.fromCharCode(0x1b);
const APPLICATION_CURSOR_KEYS_MODE = 1;
const WIN32_INPUT_MODE = 9001;
const BRACKETED_PASTE_MODE = 2004;
const CSI_INPUT_MODE_SEQUENCE = new RegExp(
`${ESC}\\[(?:([<>=?]?)([0-9;]*)u|\\?([0-9;]*)([hl]))`,
"g",
@@ -57,13 +63,17 @@ export function terminalInputModeStatesEqual(
): boolean {
return (
left.kittyKeyboardFlags === right.kittyKeyboardFlags &&
left.win32InputMode === right.win32InputMode
left.win32InputMode === right.win32InputMode &&
Boolean(left.applicationCursorKeys) === Boolean(right.applicationCursorKeys) &&
Boolean(left.bracketedPaste) === Boolean(right.bracketedPaste)
);
}
export class TerminalInputModeTracker {
private kittyKeyboardFlags = 0;
private win32InputMode = false;
private applicationCursorKeys = false;
private bracketedPaste = false;
private readonly kittyKeyboardStack: number[] = [];
private pending = "";
@@ -112,6 +122,8 @@ export class TerminalInputModeTracker {
reset(): void {
this.kittyKeyboardFlags = 0;
this.win32InputMode = false;
this.applicationCursorKeys = false;
this.bracketedPaste = false;
this.kittyKeyboardStack.length = 0;
this.pending = "";
}
@@ -120,6 +132,8 @@ export class TerminalInputModeTracker {
return {
kittyKeyboardFlags: this.kittyKeyboardFlags,
win32InputMode: this.win32InputMode,
applicationCursorKeys: this.applicationCursorKeys,
bracketedPaste: this.bracketedPaste,
};
}
@@ -139,6 +153,12 @@ export class TerminalInputModeTracker {
if (this.win32InputMode) {
parts.push("\x1b[?9001h");
}
if (this.applicationCursorKeys) {
parts.push("\x1b[?1h");
}
if (this.bracketedPaste) {
parts.push("\x1b[?2004h");
}
return parts.join("");
}
@@ -183,12 +203,26 @@ export class TerminalInputModeTracker {
private applyPrivateModeSequence(params: string, final: string): boolean {
const modes = parsePrivateModeParams(params);
if (!modes.has(WIN32_INPUT_MODE)) {
return false;
let changed = false;
if (modes.has(WIN32_INPUT_MODE)) {
const previous = this.win32InputMode;
this.win32InputMode = final === "h";
changed = this.win32InputMode !== previous || changed;
}
const previous = this.win32InputMode;
this.win32InputMode = final === "h";
return this.win32InputMode !== previous;
if (modes.has(APPLICATION_CURSOR_KEYS_MODE)) {
const previous = this.applicationCursorKeys;
this.applicationCursorKeys = final === "h";
changed = this.applicationCursorKeys !== previous || changed;
}
if (modes.has(BRACKETED_PASTE_MODE)) {
const previous = this.bracketedPaste;
this.bracketedPaste = final === "h";
changed = this.bracketedPaste !== previous || changed;
}
return changed;
}
}