Skip to content

Commit

Permalink
Merge pull request #4839 from JasonXJ/ctrl-backspace
Browse files Browse the repository at this point in the history
Send correct code for ctrl+[alt+]+backspace
  • Loading branch information
Tyriar authored Nov 2, 2023
2 parents e8da737 + 023c778 commit 1770bb1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/common/input/Keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ describe('Keyboard', () => {
it('should return \\x1b[5B for ctrl+down', () => {
assert.equal(testEvaluateKeyboardEvent({ ctrlKey: true, keyCode: 40 }).key, '\x1b[1;5B'); // CSI 5 B
});
it('should return \\x08 for ctrl+backspace', () => {
assert.equal(testEvaluateKeyboardEvent({ ctrlKey: true, keyCode: 8 }).key, '\x08');
});
it('should return \\x1b\\x7f for alt+backspace', () => {
assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 8 }).key, '\x1b\x7f');
});
it('should return \\x1b\\x08 for ctrl+alt+backspace', () => {
assert.equal(testEvaluateKeyboardEvent({ ctrlKey: true, altKey: true, keyCode: 8 }).key, '\x1b\x08');
});
it('should return \\x1b[3;2~ for shift+delete', () => {
assert.equal(testEvaluateKeyboardEvent({ shiftKey: true, keyCode: 46 }).key, '\x1b[3;2~');
});
it('should return \\x1b[3;3~ for alt+delete', () => {
assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 46 }).key, '\x1b[3;3~');
});

describe('On non-macOS platforms', () => {
// Evalueate alt + arrow key movement, which is a feature of terminal emulators but not VT100
Expand Down
5 changes: 2 additions & 3 deletions src/common/input/Keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ export function evaluateKeyboardEvent(
break;
case 8:
// backspace
result.key = ev.ctrlKey ? '\b' : C0.DEL; // ^H or ^?
if (ev.altKey) {
result.key = C0.ESC + C0.DEL; // \e ^?
break;
result.key = C0.ESC + result.key;
}
result.key = C0.DEL; // ^?
break;
case 9:
// tab
Expand Down

0 comments on commit 1770bb1

Please sign in to comment.