Merge pull request #3726 from Eugeny/fix-macos-alt-n

Fix Alt-N/E/U handling in macOS, handle Alt-Shift-Letter
This commit is contained in:
Daniel Imms
2022-06-26 09:04:33 -07:00
committed by GitHub
4 changed files with 25 additions and 3 deletions
+5 -2
View File
@@ -1099,14 +1099,17 @@ export class Terminal extends CoreTerminal implements ITerminal {
return false;
}
if (!this._compositionHelper!.keydown(event)) {
// Ignore composing with Alt key on Mac when macOptionIsMeta is enabled
const shouldIgnoreComposition = this.browser.isMac && this.options.macOptionIsMeta && event.altKey;
if (!shouldIgnoreComposition && !this._compositionHelper!.keydown(event)) {
if (this.buffer.ybase !== this.buffer.ydisp) {
this._bufferService.scrollToBottom();
}
return false;
}
if (event.key === 'Dead' || event.key === 'AltGraph') {
if (!shouldIgnoreComposition && (event.key === 'Dead' || event.key === 'AltGraph')) {
this._unprocessedDeadKey = true;
}
+1
View File
@@ -50,6 +50,7 @@ export interface IKeyboardEvent {
keyCode: number;
key: string;
type: string;
code: string;
}
export interface IScrollEvent {
+2
View File
@@ -13,6 +13,7 @@ function testEvaluateKeyboardEvent(partialEvent: {
shiftKey?: boolean;
metaKey?: boolean;
keyCode?: number;
code?: string;
key?: string;
type?: string;
}, partialOptions: {
@@ -26,6 +27,7 @@ function testEvaluateKeyboardEvent(partialEvent: {
shiftKey: partialEvent.shiftKey || false,
metaKey: partialEvent.metaKey || false,
keyCode: partialEvent.keyCode !== undefined ? partialEvent.keyCode : 0,
code: partialEvent.code || '',
key: partialEvent.key || '',
type: partialEvent.type || ''
};
+17 -1
View File
@@ -358,7 +358,23 @@ export function evaluateKeyboardEvent(
result.key = C0.ESC + key;
} else if (ev.keyCode >= 65 && ev.keyCode <= 90) {
const keyCode = ev.ctrlKey ? ev.keyCode - 64 : ev.keyCode + 32;
result.key = C0.ESC + String.fromCharCode(keyCode);
let keyString = String.fromCharCode(keyCode);
if (ev.shiftKey) {
keyString = keyString.toUpperCase();
}
result.key = C0.ESC + keyString;
} else if (ev.key === 'Dead' && ev.code.startsWith('Key')) {
// Reference: https://github.com/xtermjs/xterm.js/issues/3725
// Alt will produce a "dead key" (initate composition) with some
// of the letters in US layout (e.g. N/E/U).
// It's safe to match against Key* since no other `code` values begin with "Key".
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values#code_values_on_mac
let keyString = ev.code.slice(3, 4);
if (!ev.shiftKey) {
keyString = keyString.toLowerCase();
}
result.key = C0.ESC + keyString;
result.cancel = true;
}
} else if (isMac && !ev.altKey && !ev.ctrlKey && !ev.shiftKey && ev.metaKey) {
if (ev.keyCode === 65) { // cmd + a