Skip to content

Commit c1e2810

Browse files
committed
fix(keybindings): let xterm handle Ctrl+Arrow natively, use CSI for Alt+Arrow
1 parent f6978db commit c1e2810

2 files changed

Lines changed: 22 additions & 23 deletions

File tree

‎apps/web/src/keybindings.test.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,11 @@ describe("terminalNavigationShortcutData", () => {
662662
it("maps Option+Arrow on macOS to word movement", () => {
663663
assert.strictEqual(
664664
terminalNavigationShortcutData(event({ key: "ArrowLeft", altKey: true }), "MacIntel"),
665-
"\u001bb",
665+
"\u001b[1;5D",
666666
);
667667
assert.strictEqual(
668668
terminalNavigationShortcutData(event({ key: "ArrowRight", altKey: true }), "MacIntel"),
669-
"\u001bf",
669+
"\u001b[1;5C",
670670
);
671671
});
672672

@@ -681,14 +681,23 @@ describe("terminalNavigationShortcutData", () => {
681681
);
682682
});
683683

684-
it("maps Ctrl+Arrow on non-macOS to word movement", () => {
685-
assert.strictEqual(
684+
it("does not intercept Ctrl+Arrow on non-macOS (let xterm handle natively)", () => {
685+
assert.isNull(
686686
terminalNavigationShortcutData(event({ key: "ArrowLeft", ctrlKey: true }), "Win32"),
687-
"\u001bb",
688687
);
689-
assert.strictEqual(
688+
assert.isNull(
690689
terminalNavigationShortcutData(event({ key: "ArrowRight", ctrlKey: true }), "Linux"),
691-
"\u001bf",
690+
);
691+
});
692+
693+
it("remaps Alt+Arrow on non-macOS to CSI word movement", () => {
694+
assert.strictEqual(
695+
terminalNavigationShortcutData(event({ key: "ArrowLeft", altKey: true }), "Win32"),
696+
"\u001b[1;5D",
697+
);
698+
assert.strictEqual(
699+
terminalNavigationShortcutData(event({ key: "ArrowRight", altKey: true }), "Linux"),
700+
"\u001b[1;5C",
692701
);
693702
});
694703

‎apps/web/src/keybindings.ts‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ interface ResolvedShortcutLabelOptions extends ShortcutMatchOptions {
4242
platform?: string;
4343
}
4444

45-
const TERMINAL_WORD_BACKWARD = "\u001bb";
46-
const TERMINAL_WORD_FORWARD = "\u001bf";
45+
const TERMINAL_WORD_BACKWARD = "\u001b[1;5D";
46+
const TERMINAL_WORD_FORWARD = "\u001b[1;5C";
4747
const TERMINAL_LINE_START = "\u0001";
4848
const TERMINAL_LINE_END = "\u0005";
4949
const TERMINAL_DELETE_TO_LINE_START = "\u0015";
@@ -465,24 +465,14 @@ export function terminalNavigationShortcutData(
465465
}
466466

467467
const moveWord = key === "arrowleft" ? TERMINAL_WORD_BACKWARD : TERMINAL_WORD_FORWARD;
468-
const moveLine = key === "arrowleft" ? TERMINAL_LINE_START : TERMINAL_LINE_END;
469-
470-
if (isMacPlatform(platform)) {
471-
if (event.altKey && !event.metaKey && !event.ctrlKey) {
472-
return moveWord;
473-
}
474-
if (event.metaKey && !event.altKey && !event.ctrlKey) {
475-
return moveLine;
476-
}
477-
return null;
478-
}
479468

480-
if (event.ctrlKey && !event.metaKey && !event.altKey) {
469+
if (event.altKey && !event.metaKey && !event.ctrlKey) {
481470
return moveWord;
482471
}
483472

484-
if (event.altKey && !event.metaKey && !event.ctrlKey) {
485-
return moveWord;
473+
const moveLine = key === "arrowleft" ? TERMINAL_LINE_START : TERMINAL_LINE_END;
474+
if (isMacPlatform(platform) && event.metaKey && !event.altKey && !event.ctrlKey) {
475+
return moveLine;
486476
}
487477

488478
return null;

0 commit comments

Comments
 (0)