提交 4e89f9dc 编写于 作者: A Alex Dima

Fixes #23706: Electron cannot handle OEM key codes outside of US standard kb layout

上级 2c2cf0bd
......@@ -500,6 +500,10 @@ class ScanCodeKeyCodeMapper {
export class MacLinuxKeyboardMapper implements IKeyboardMapper {
/**
* OS (can be Linux or Macintosh)
*/
private readonly _isUSStandard: boolean;
/**
* OS (can be Linux or Macintosh)
*/
......@@ -521,7 +525,8 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
*/
private readonly _scanCodeToDispatch: string[] = [];
constructor(rawMappings: IMacLinuxKeyboardMapping, OS: OperatingSystem) {
constructor(isUSStandard: boolean, rawMappings: IMacLinuxKeyboardMapping, OS: OperatingSystem) {
this._isUSStandard = isUSStandard;
this._OS = OS;
this._codeInfo = [];
this._scanCodeKeyCodeMapper = new ScanCodeKeyCodeMapper();
......@@ -657,6 +662,7 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
];
let cnt = 0;
result.push(`isUSStandard: ${this._isUSStandard}`);
result.push(`----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------`);
for (let scanCode = ScanCode.None; scanCode < ScanCode.MAX_VALUE; scanCode++) {
if (IMMUTABLE_CODE_TO_KEY_CODE[scanCode] !== -1) {
......@@ -943,6 +949,27 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
// Check if this scanCode always maps to the same keyCode and back
let constantKeyCode: KeyCode = this._scanCodeKeyCodeMapper.guessStableKeyCode(scanCode);
if (!this._isUSStandard) {
// Electron cannot handle these key codes on anything else than standard US
const isOEMKey = (
constantKeyCode === KeyCode.US_SEMICOLON
|| constantKeyCode === KeyCode.US_EQUAL
|| constantKeyCode === KeyCode.US_COMMA
|| constantKeyCode === KeyCode.US_MINUS
|| constantKeyCode === KeyCode.US_DOT
|| constantKeyCode === KeyCode.US_SLASH
|| constantKeyCode === KeyCode.US_BACKTICK
|| constantKeyCode === KeyCode.US_OPEN_SQUARE_BRACKET
|| constantKeyCode === KeyCode.US_BACKSLASH
|| constantKeyCode === KeyCode.US_CLOSE_SQUARE_BRACKET
);
if (isOEMKey) {
return null;
}
}
if (constantKeyCode !== -1) {
return this._getElectronLabelForKeyCode(constantKeyCode);
}
......
......@@ -84,8 +84,10 @@ export class KeyboardMapperFactory {
}
public isUSStandard(): boolean {
let _kbInfo = this.getCurrentKeyboardLayout();
return KeyboardMapperFactory._isUSStandard(this.getCurrentKeyboardLayout());
}
private static _isUSStandard(_kbInfo: nativeKeymap.IKeyboardLayoutInfo): boolean {
if (OS === OperatingSystem.Linux) {
const kbInfo = <nativeKeymap.ILinuxKeyboardLayoutInfo>_kbInfo;
return (kbInfo && kbInfo.layout === 'us');
......@@ -122,11 +124,11 @@ export class KeyboardMapperFactory {
this._initialized = true;
this._rawMapping = rawMapping;
this._keyboardMapper = KeyboardMapperFactory._createKeyboardMapper(this._rawMapping);
this._keyboardMapper = KeyboardMapperFactory._createKeyboardMapper(KeyboardMapperFactory._isUSStandard(this._layoutInfo), this._rawMapping);
this._onDidChangeKeyboardMapper.fire();
}
private static _createKeyboardMapper(rawMapping: nativeKeymap.IKeyboardMapping): IKeyboardMapper {
private static _createKeyboardMapper(isUSStandard: boolean, rawMapping: nativeKeymap.IKeyboardMapping): IKeyboardMapper {
if (OS === OperatingSystem.Windows) {
return new WindowsKeyboardMapper(<IWindowsKeyboardMapping>rawMapping);
}
......@@ -136,7 +138,7 @@ export class KeyboardMapperFactory {
return new MacLinuxFallbackKeyboardMapper(OS);
}
return new MacLinuxKeyboardMapper(<IMacLinuxKeyboardMapping>rawMapping, OS);
return new MacLinuxKeyboardMapper(isUSStandard, <IMacLinuxKeyboardMapping>rawMapping, OS);
}
private static _equals(a: nativeKeymap.IKeyboardMapping, b: nativeKeymap.IKeyboardMapping): boolean {
......
isUSStandard: false
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| HW Code combination | Key | KeyCode combination | Pri | UI label | User settings | Electron accelerator | Dispatching string | WYSIWYG |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
......@@ -469,14 +470,14 @@
| Shift+Alt+Period | : | Shift+Alt+; | | Shift+Alt+. | shift+alt+[Period] | null | shift+alt+[Period] | NO |
| Ctrl+Shift+Alt+Period | ÷ | Ctrl+Shift+Alt+; | | Ctrl+Shift+Alt+. | ctrl+shift+alt+[Period] | null | ctrl+shift+alt+[Period] | NO |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Slash | - | - | | - | - | - | [Slash] | |
| Ctrl+Slash | - | Ctrl+- | | Ctrl+- | ctrl+- | Ctrl+- | ctrl+[Slash] | |
| Shift+Slash | _ | Shift+- | | Shift+- | shift+- | Shift+- | shift+[Slash] | |
| Ctrl+Shift+Slash | _ | Ctrl+Shift+- | | Ctrl+Shift+- | ctrl+shift+- | Ctrl+Shift+- | ctrl+shift+[Slash] | |
| Alt+Slash | - | Alt+- | | Alt+- | alt+- | Alt+- | alt+[Slash] | |
| Ctrl+Alt+Slash | U+323 | Ctrl+Alt+- | | Ctrl+Alt+- | ctrl+alt+- | Ctrl+Alt+- | ctrl+alt+[Slash] | |
| Shift+Alt+Slash | _ | Shift+Alt+- | | Shift+Alt+- | shift+alt+- | Shift+Alt+- | shift+alt+[Slash] | |
| Ctrl+Shift+Alt+Slash | ˙ | Ctrl+Shift+Alt+- | | Ctrl+Shift+Alt+- | ctrl+shift+alt+- | Ctrl+Shift+Alt+- | ctrl+shift+alt+[Slash] | |
| Slash | - | - | | - | - | null | [Slash] | |
| Ctrl+Slash | - | Ctrl+- | | Ctrl+- | ctrl+- | null | ctrl+[Slash] | |
| Shift+Slash | _ | Shift+- | | Shift+- | shift+- | null | shift+[Slash] | |
| Ctrl+Shift+Slash | _ | Ctrl+Shift+- | | Ctrl+Shift+- | ctrl+shift+- | null | ctrl+shift+[Slash] | |
| Alt+Slash | - | Alt+- | | Alt+- | alt+- | null | alt+[Slash] | |
| Ctrl+Alt+Slash | U+323 | Ctrl+Alt+- | | Ctrl+Alt+- | ctrl+alt+- | null | ctrl+alt+[Slash] | |
| Shift+Alt+Slash | _ | Shift+Alt+- | | Shift+Alt+- | shift+alt+- | null | shift+alt+[Slash] | |
| Ctrl+Shift+Alt+Slash | ˙ | Ctrl+Shift+Alt+- | | Ctrl+Shift+Alt+- | ctrl+shift+alt+- | null | ctrl+shift+alt+[Slash] | |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| HW Code combination | Key | KeyCode combination | Pri | UI label | User settings | Electron accelerator | Dispatching string | WYSIWYG |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
......
isUSStandard: true
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| HW Code combination | Key | KeyCode combination | Pri | UI label | User settings | Electron accelerator | Dispatching string | WYSIWYG |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
......
......@@ -18,9 +18,9 @@ import { readRawMapping, assertMapping, IResolvedKeybinding, assertResolveKeybin
const WRITE_FILE_IF_DIFFERENT = false;
function createKeyboardMapper(file: string, OS: OperatingSystem): TPromise<MacLinuxKeyboardMapper> {
function createKeyboardMapper(isUSStandard: boolean, file: string, OS: OperatingSystem): TPromise<MacLinuxKeyboardMapper> {
return readRawMapping<IMacLinuxKeyboardMapping>(file).then((rawMappings) => {
return new MacLinuxKeyboardMapper(rawMappings, OS);
return new MacLinuxKeyboardMapper(isUSStandard, rawMappings, OS);
});
}
......@@ -29,7 +29,7 @@ suite('keyboardMapper - MAC de_ch', () => {
let mapper: MacLinuxKeyboardMapper;
suiteSetup((done) => {
createKeyboardMapper('mac_de_ch', OperatingSystem.Macintosh).then((_mapper) => {
createKeyboardMapper(false, 'mac_de_ch', OperatingSystem.Macintosh).then((_mapper) => {
mapper = _mapper;
done();
}, done);
......@@ -478,7 +478,7 @@ suite('keyboardMapper - MAC en_us', () => {
let mapper: MacLinuxKeyboardMapper;
suiteSetup((done) => {
createKeyboardMapper('mac_en_us', OperatingSystem.Macintosh).then((_mapper) => {
createKeyboardMapper(true, 'mac_en_us', OperatingSystem.Macintosh).then((_mapper) => {
mapper = _mapper;
done();
}, done);
......@@ -580,7 +580,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
let mapper: MacLinuxKeyboardMapper;
suiteSetup((done) => {
createKeyboardMapper('linux_de_ch', OperatingSystem.Linux).then((_mapper) => {
createKeyboardMapper(false, 'linux_de_ch', OperatingSystem.Linux).then((_mapper) => {
mapper = _mapper;
done();
}, done);
......@@ -1024,7 +1024,7 @@ suite('keyboardMapper - LINUX en_us', () => {
let mapper: MacLinuxKeyboardMapper;
suiteSetup((done) => {
createKeyboardMapper('linux_en_us', OperatingSystem.Linux).then((_mapper) => {
createKeyboardMapper(true, 'linux_en_us', OperatingSystem.Linux).then((_mapper) => {
mapper = _mapper;
done();
}, done);
......@@ -1532,6 +1532,51 @@ suite('keyboardMapper - LINUX en_us', () => {
});
});
suite('keyboardMapper', () => {
test('issue #23706: Linux UK layout: Ctrl + Apostrophe also toggles terminal', () => {
let mapper = new MacLinuxKeyboardMapper(false, {
'Backquote': {
'value': '`',
'withShift': '¬',
'withAltGr': '|',
'withShiftAltGr': '|'
}
}, OperatingSystem.Linux);
function _simpleHTMLLabel(pieces: string[]): IHTMLContentElement {
return simpleHTMLLabel(pieces, OperatingSystem.Linux);
}
assertResolveKeyboardEvent(
mapper,
{
ctrlKey: true,
shiftKey: false,
altKey: false,
metaKey: false,
keyCode: -1,
code: 'Backquote'
},
{
label: 'Ctrl+`',
ariaLabel: 'Control+`',
HTMLLabel: [_simpleHTMLLabel(['Ctrl', '`'])],
electronAccelerator: null,
userSettingsLabel: 'ctrl+`',
isWYSIWYG: true,
isChord: false,
hasCtrlModifier: true,
hasShiftModifier: false,
hasAltModifier: false,
hasMetaModifier: false,
dispatchParts: ['ctrl+[Backquote]', null],
}
);
});
});
function _assertKeybindingTranslation(mapper: MacLinuxKeyboardMapper, OS: OperatingSystem, kb: number, _expected: string | string[]): void {
let expected: string[];
if (typeof _expected === 'string') {
......
isUSStandard: false
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| HW Code combination | Key | KeyCode combination | Pri | UI label | User settings | Electron accelerator | Dispatching string | WYSIWYG |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
......@@ -470,14 +471,14 @@
| Shift+Alt+Period | : | Shift+Alt+; | | Shift+Alt+. | shift+alt+[Period] | null | shift+alt+[Period] | NO |
| Ctrl+Shift+Alt+Period | ÷ | Ctrl+Shift+Alt+; | | Ctrl+Shift+Alt+. | ctrl+shift+alt+[Period] | null | ctrl+shift+alt+[Period] | NO |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Slash | - | - | | - | - | - | [Slash] | |
| Ctrl+Slash | - | Ctrl+- | | Ctrl+- | ctrl+- | Ctrl+- | ctrl+[Slash] | |
| Shift+Slash | _ | Shift+- | | Shift+- | shift+- | Shift+- | shift+[Slash] | |
| Ctrl+Shift+Slash | _ | Ctrl+Shift+- | | Ctrl+Shift+- | ctrl+shift+- | Ctrl+Shift+- | ctrl+shift+[Slash] | |
| Alt+Slash | - | Alt+- | | Alt+- | alt+- | Alt+- | alt+[Slash] | |
| Ctrl+Alt+Slash | – | Ctrl+Alt+- | | Ctrl+Alt+- | ctrl+alt+- | Ctrl+Alt+- | ctrl+alt+[Slash] | |
| Shift+Alt+Slash | _ | Shift+Alt+- | | Shift+Alt+- | shift+alt+- | Shift+Alt+- | shift+alt+[Slash] | |
| Ctrl+Shift+Alt+Slash | — | Ctrl+Shift+Alt+- | | Ctrl+Shift+Alt+- | ctrl+shift+alt+- | Ctrl+Shift+Alt+- | ctrl+shift+alt+[Slash] | |
| Slash | - | - | | - | - | null | [Slash] | |
| Ctrl+Slash | - | Ctrl+- | | Ctrl+- | ctrl+- | null | ctrl+[Slash] | |
| Shift+Slash | _ | Shift+- | | Shift+- | shift+- | null | shift+[Slash] | |
| Ctrl+Shift+Slash | _ | Ctrl+Shift+- | | Ctrl+Shift+- | ctrl+shift+- | null | ctrl+shift+[Slash] | |
| Alt+Slash | - | Alt+- | | Alt+- | alt+- | null | alt+[Slash] | |
| Ctrl+Alt+Slash | – | Ctrl+Alt+- | | Ctrl+Alt+- | ctrl+alt+- | null | ctrl+alt+[Slash] | |
| Shift+Alt+Slash | _ | Shift+Alt+- | | Shift+Alt+- | shift+alt+- | null | shift+alt+[Slash] | |
| Ctrl+Shift+Alt+Slash | — | Ctrl+Shift+Alt+- | | Ctrl+Shift+Alt+- | ctrl+shift+alt+- | null | ctrl+shift+alt+[Slash] | |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| HW Code combination | Key | KeyCode combination | Pri | UI label | User settings | Electron accelerator | Dispatching string | WYSIWYG |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
......
isUSStandard: true
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| HW Code combination | Key | KeyCode combination | Pri | UI label | User settings | Electron accelerator | Dispatching string | WYSIWYG |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册