Skip to content
TypeScript

fix(mobile): apply terminal toolbar modifiers to arrow keys (#22161)

Victor Vogele0f972e3759c
diff --git a/apps/mobile/src/features/terminal/terminalInput.test.ts b/apps/mobile/src/features/terminal/terminalInput.test.ts
index 74240215af0..17fabe58811 100644
--- a/apps/mobile/src/features/terminal/terminalInput.test.ts
+++ b/apps/mobile/src/features/terminal/terminalInput.test.ts
@@ -12,6 +12,38 @@ const ESC = byte(0x1b);
const CTRL_V = byte(0x16);
describe("resolveModifiedTerminalInput", () => {
+ it.each(["A", "B", "C", "D"])("encodes ctrl+arrow %s with the cursor modifier", (arrow) => {
+ expect(
+ resolveModifiedTerminalInput({
+ data: `${ESC}[${arrow}`,
+ modifier: "ctrl",
+ hostPlatform: "linux",
+ }),
+ ).toEqual({ kind: "write", data: `${ESC}[1;5${arrow}` });
+ });
+
+ it.each(["A", "B", "C", "D"])("encodes meta+arrow %s with the cursor modifier", (arrow) => {
+ expect(
+ resolveModifiedTerminalInput({
+ data: `${ESC}[${arrow}`,
+ modifier: "meta",
+ hostPlatform: "linux",
+ }),
+ ).toEqual({ kind: "write", data: `${ESC}[1;3${arrow}` });
+ });
+
+ it.each(["a", "", ESC, `${ESC}[H`, `${ESC}[1;5D`, `${ESC}[D\n`])(
+ "preserves non-arrow modifier handling for %j",
+ (data) => {
+ expect(
+ resolveModifiedTerminalInput({ data, modifier: "meta", hostPlatform: "linux" }),
+ ).toEqual({
+ kind: "write",
+ data: `${ESC}${data}`,
+ });
+ },
+ );
+
it("pastes on ctrl+v for windows, linux, and unknown hosts", () => {
for (const hostPlatform of ["windows", "linux", "unknown"] as const) {
expect(resolveModifiedTerminalInput({ data: "v", modifier: "ctrl", hostPlatform })).toEqual({
diff --git a/apps/mobile/src/features/terminal/terminalInput.ts b/apps/mobile/src/features/terminal/terminalInput.ts
index 09886b41cb2..9c5e05dcc24 100644
--- a/apps/mobile/src/features/terminal/terminalInput.ts
+++ b/apps/mobile/src/features/terminal/terminalInput.ts
@@ -45,6 +45,14 @@ export function resolveModifiedTerminalInput(input: {
return { kind: "paste" };
}
+ if (
+ input.data.length === 3 &&
+ input.data.startsWith("\u001b[") &&
+ /[ABCD]/.test(input.data.charAt(2))
+ ) {
+ return { kind: "write", data: `\u001b[1;${input.modifier === "ctrl" ? 5 : 3}${input.data[2]}` };
+ }
+
return {
kind: "write",
data: input.modifier === "ctrl" ? applyCtrlModifier(input.data) : `\u001b${input.data}`,