Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added macOptionIsEscape according to #4904 #5033

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/browser/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
}

// Ignore composing with Alt key on Mac when macOptionIsMeta is enabled
const shouldIgnoreComposition = this.browser.isMac && this.options.macOptionIsMeta && event.altKey;
const shouldIgnoreComposition = this.browser.isMac && this.options.macOptionIsMeta && this.options.macOptionIsEscape && event.altKey;

if (!shouldIgnoreComposition && !this._compositionHelper!.keydown(event)) {
if (this.options.scrollOnUserInput && this.buffer.ybase !== this.buffer.ydisp) {
Expand All @@ -1020,7 +1020,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
this._unprocessedDeadKey = true;
}

const result = evaluateKeyboardEvent(event, this.coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta);
const result = evaluateKeyboardEvent(event, this.coreService.decPrivateModes.applicationCursorKeys, this.browser.isMac, this.options.macOptionIsMeta, this.options.macOptionIsEscape);

this.updateCursorStyle(event);

Expand Down Expand Up @@ -1084,7 +1084,7 @@ export class Terminal extends CoreTerminal implements ITerminal {

private _isThirdLevelShift(browser: IBrowser, ev: KeyboardEvent): boolean {
const thirdLevelKey =
(browser.isMac && !this.options.macOptionIsMeta && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
(browser.isMac && !this.options.macOptionIsMeta && !this.options.macOptionIsEscape && ev.altKey && !ev.ctrlKey && !ev.metaKey) ||
(browser.isWindows && ev.altKey && ev.ctrlKey && !ev.metaKey) ||
(browser.isWindows && ev.getModifierState('AltGraph'));

Expand Down
15 changes: 13 additions & 2 deletions src/common/input/Keyboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function testEvaluateKeyboardEvent(partialEvent: {
applicationCursorMode?: boolean;
isMac?: boolean;
macOptionIsMeta?: boolean;
macOptionIsEscape?: boolean;
} = {}): IKeyboardResult {
const event: IKeyboardEvent = {
altKey: partialEvent.altKey || false,
Expand All @@ -34,9 +35,10 @@ function testEvaluateKeyboardEvent(partialEvent: {
const options = {
applicationCursorMode: partialOptions.applicationCursorMode || false,
isMac: partialOptions.isMac || false,
macOptionIsMeta: partialOptions.macOptionIsMeta || false
macOptionIsMeta: partialOptions.macOptionIsMeta || false,
macOptionIsEscape: partialOptions.macOptionIsEscape || false
};
return evaluateKeyboardEvent(event, options.applicationCursorMode, options.isMac, options.macOptionIsMeta);
return evaluateKeyboardEvent(event, options.applicationCursorMode, options.isMac, options.macOptionIsMeta, options.macOptionIsEscape);
}

describe('Keyboard', () => {
Expand Down Expand Up @@ -175,6 +177,15 @@ describe('Keyboard', () => {
assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 13 }, { isMac: true, macOptionIsMeta: true }).key, '\x1b\r');
});
});
describe('with macOptionIsEscape', () => {
it('should return \\x80 for alt+@', () => {
assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 64 }, { isMac: true, macOptionIsEscape: true }).key, '\x80');
});

it('should return \\x9F for alt+_', () => {
assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 95 }, { isMac: true, macOptionIsEscape: true }).key, '\x9F');
});
});

it('should return \\x1b[5A for alt+up', () => {
assert.equal(testEvaluateKeyboardEvent({ altKey: true, keyCode: 38 }).key, '\x1b[1;5A'); // CSI 5 A
Expand Down
11 changes: 8 additions & 3 deletions src/common/input/Keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export function evaluateKeyboardEvent(
ev: IKeyboardEvent,
applicationCursorMode: boolean,
isMac: boolean,
macOptionIsMeta: boolean
macOptionIsMeta: boolean,
macOptionIsEscape: boolean
): IKeyboardResult {
const result: IKeyboardResult = {
type: KeyboardResultType.SEND_KEY,
Expand Down Expand Up @@ -346,11 +347,15 @@ export function evaluateKeyboardEvent(
} else if (ev.keyCode === 221) {
result.key = C0.GS;
}
} else if ((!isMac || macOptionIsMeta) && ev.altKey && !ev.metaKey) {
} else if ((!isMac || macOptionIsMeta || macOptionIsEscape) && ev.altKey && !ev.metaKey) {
// On macOS this is a third level shift when !macOptionIsMeta. Use <Esc> instead.
const keyMapping = KEYCODE_KEY_MAPPINGS[ev.keyCode];
const key = keyMapping?.[!ev.shiftKey ? 0 : 1];
if (key) {
if (macOptionIsEscape && ev.keyCode >= 64 && ev.keyCode <= 95) {
result.key = String.fromCharCode(128 + ev.keyCode - 64);
console.log(12);
}
else if (key) {
result.key = C0.ESC + key;
} else if (ev.keyCode >= 65 && ev.keyCode <= 90) {
const keyCode = ev.ctrlKey ? ev.keyCode - 64 : ev.keyCode + 32;
Expand Down
1 change: 1 addition & 0 deletions src/common/services/OptionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const DEFAULT_OPTIONS: Readonly<Required<ITerminalOptions>> = {
scrollSensitivity: 1,
screenReaderMode: false,
smoothScrollDuration: 0,
macOptionIsEscape: false,
macOptionIsMeta: false,
macOptionClickForcesSelection: false,
minimumContrastRatio: 1,
Expand Down
Loading