Skip to content

Commit e0f972e

Browse files
only21milcodexmaria-rcks
authored
fix(mobile): apply terminal toolbar modifiers to arrow keys (#22161)
Co-authored-by: GPT-6.1 Sol <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 1dd8c67 commit e0f972e

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎apps/mobile/src/features/terminal/terminalInput.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,38 @@ const ESC = byte(0x1b);
1212
const CTRL_V = byte(0x16);
1313

1414
describe("resolveModifiedTerminalInput", () => {
15+
it.each(["A", "B", "C", "D"])("encodes ctrl+arrow %s with the cursor modifier", (arrow) => {
16+
expect(
17+
resolveModifiedTerminalInput({
18+
data: `${ESC}[${arrow}`,
19+
modifier: "ctrl",
20+
hostPlatform: "linux",
21+
}),
22+
).toEqual({ kind: "write", data: `${ESC}[1;5${arrow}` });
23+
});
24+
25+
it.each(["A", "B", "C", "D"])("encodes meta+arrow %s with the cursor modifier", (arrow) => {
26+
expect(
27+
resolveModifiedTerminalInput({
28+
data: `${ESC}[${arrow}`,
29+
modifier: "meta",
30+
hostPlatform: "linux",
31+
}),
32+
).toEqual({ kind: "write", data: `${ESC}[1;3${arrow}` });
33+
});
34+
35+
it.each(["a", "", ESC, `${ESC}[H`, `${ESC}[1;5D`, `${ESC}[D\n`])(
36+
"preserves non-arrow modifier handling for %j",
37+
(data) => {
38+
expect(
39+
resolveModifiedTerminalInput({ data, modifier: "meta", hostPlatform: "linux" }),
40+
).toEqual({
41+
kind: "write",
42+
data: `${ESC}${data}`,
43+
});
44+
},
45+
);
46+
1547
it("pastes on ctrl+v for windows, linux, and unknown hosts", () => {
1648
for (const hostPlatform of ["windows", "linux", "unknown"] as const) {
1749
expect(resolveModifiedTerminalInput({ data: "v", modifier: "ctrl", hostPlatform })).toEqual({

‎apps/mobile/src/features/terminal/terminalInput.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export function resolveModifiedTerminalInput(input: {
4545
return { kind: "paste" };
4646
}
4747

48+
if (
49+
input.data.length === 3 &&
50+
input.data.startsWith("\u001b[") &&
51+
/[ABCD]/.test(input.data.charAt(2))
52+
) {
53+
return { kind: "write", data: `\u001b[1;${input.modifier === "ctrl" ? 5 : 3}${input.data[2]}` };
54+
}
55+
4856
return {
4957
kind: "write",
5058
data: input.modifier === "ctrl" ? applyCtrlModifier(input.data) : `\u001b${input.data}`,

0 commit comments

Comments
 (0)