Skip to content

Commit 68923a2

Browse files
only21milcodex
andcommitted
fix(mobile): apply terminal toolbar modifiers to arrow keys
Encode modified cursor sequences for all four toolbar arrows so Ctrl and Meta reach the shell. Co-Authored-By: GPT-6.1 Sol <[email protected]>
1 parent fb99076 commit 68923a2

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ describe("applyCtrlModifier", () => {
3030
});
3131

3232
describe("resolveModifiedTerminalInput", () => {
33+
it.each(["A", "B", "C", "D"])("encodes ctrl+arrow %s with the cursor modifier", (arrow) => {
34+
expect(
35+
resolveModifiedTerminalInput({
36+
data: `${ESC}[${arrow}`,
37+
modifier: "ctrl",
38+
hostPlatform: "linux",
39+
}),
40+
).toEqual({ kind: "write", data: `${ESC}[1;5${arrow}` });
41+
});
42+
43+
it.each(["A", "B", "C", "D"])("encodes meta+arrow %s with the cursor modifier", (arrow) => {
44+
expect(
45+
resolveModifiedTerminalInput({
46+
data: `${ESC}[${arrow}`,
47+
modifier: "meta",
48+
hostPlatform: "linux",
49+
}),
50+
).toEqual({ kind: "write", data: `${ESC}[1;3${arrow}` });
51+
});
52+
3353
it("pastes on ctrl+v for windows, linux, and unknown hosts", () => {
3454
for (const hostPlatform of ["windows", "linux", "unknown"] as const) {
3555
expect(resolveModifiedTerminalInput({ data: "v", modifier: "ctrl", hostPlatform })).toEqual({

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ export function resolveModifiedTerminalInput(input: {
5353
return { kind: "paste" };
5454
}
5555

56+
// eslint-disable-next-line no-control-regex -- Match the toolbar's arrow-key escape sequences.
57+
const arrow = /^\u001b\[([ABCD])$/.exec(input.data);
58+
if (arrow) {
59+
return { kind: "write", data: `\u001b[1;${input.modifier === "ctrl" ? 5 : 3}${arrow[1]}` };
60+
}
61+
5662
return {
5763
kind: "write",
5864
data: input.modifier === "ctrl" ? applyCtrlModifier(input.data) : `\u001b${input.data}`,

0 commit comments

Comments
 (0)