Skip to content

Commit

Permalink
#6872: Exclude all numpad keys from keyboard mapping
Browse files Browse the repository at this point in the history
Signed-off-by: Miro Spönemann <miro.spoenemann@typefox.io>
  • Loading branch information
spoenemann committed Jan 15, 2020
1 parent 7b275d2 commit 8cd3640
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/core/src/browser/keyboard/keyboard-layout-service.ts
Expand Up @@ -146,7 +146,7 @@ export class KeyboardLayoutService {
if (mapping.hasOwnProperty(code)) {
const keyMapping = mapping[code];
const mappedKey = Key.getKey(code);
if (this.isValidKey(mappedKey)) {
if (mappedKey && this.shouldIncludeKey(code)) {
if (isWindows) {
this.addWindowsKeyMapping(key2KeyCode, mappedKey, (keyMapping as IWindowsKeyMapping).vkey, keyMapping.value);
} else {
Expand All @@ -172,13 +172,12 @@ export class KeyboardLayoutService {
return { key2KeyCode, code2Character };
}

protected isValidKey(key?: Key): key is Key {
return key !== undefined
&& key !== Key.ADD
&& key !== Key.SUBTRACT
&& key !== Key.MULTIPLY
&& key !== Key.DIVIDE
&& key !== Key.DECIMAL;
protected shouldIncludeKey(code: string): boolean {
// Exclude all numpad keys because they produce values that are already found elsewhere on the keyboard.
// This can cause problems, e.g. if `Numpad3` maps to `PageDown` then commands bound to `PageDown` would
// be resolved to `Digit3` (`Numpad3` is associated with `Key.DIGIT3`), effectively blocking the user
// from typing `3` in an editor.
return !code.startsWith('Numpad');
}

private addKeyMapping(key2KeyCode: KeyCode[], mappedKey: Key, value: string, shift: boolean, alt: boolean): void {
Expand Down

0 comments on commit 8cd3640

Please sign in to comment.