Skip to content

Commit

Permalink
Fixes #24064: NumLock/NumPad keys stopped working in 1.11 on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Apr 10, 2017
1 parent 62abf41 commit 8281fb3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { OperatingSystem } from 'vs/base/common/platform';
import { KeyCode, ResolvedKeybinding, KeyCodeUtils, SimpleKeybinding, Keybinding, KeybindingType, USER_SETTINGS } from 'vs/base/common/keyCodes';
import { ScanCode, ScanCodeUtils, IMMUTABLE_CODE_TO_KEY_CODE, ScanCodeBinding } from 'vs/workbench/services/keybinding/common/scanCode';
import { ScanCode, ScanCodeUtils, IMMUTABLE_CODE_TO_KEY_CODE, IMMUTABLE_KEY_CODE_TO_CODE, ScanCodeBinding } from 'vs/workbench/services/keybinding/common/scanCode';
import { CharCode } from 'vs/base/common/charCode';
import { UILabelProvider, AriaLabelProvider, UserSettingsLabelProvider, ElectronAcceleratorLabelProvider, NO_MODIFIERS } from 'vs/platform/keybinding/common/keybindingLabels';
import { IKeyboardMapper } from 'vs/workbench/services/keybinding/common/keyboardMapper';
Expand Down Expand Up @@ -1055,6 +1055,29 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
if (code === ScanCode.NumpadEnter) {
code = ScanCode.Enter;
}

if (
(code === ScanCode.Numpad1)
|| (code === ScanCode.Numpad2)
|| (code === ScanCode.Numpad3)
|| (code === ScanCode.Numpad4)
|| (code === ScanCode.Numpad5)
|| (code === ScanCode.Numpad6)
|| (code === ScanCode.Numpad7)
|| (code === ScanCode.Numpad8)
|| (code === ScanCode.Numpad9)
|| (code === ScanCode.Numpad0)
|| (code === ScanCode.NumpadDecimal)
) {
// "Dispatch" on keyCode for all numpad keys in order for NumLock to work correctly
if (keyboardEvent.keyCode >= 0) {
const immutableScanCode = IMMUTABLE_KEY_CODE_TO_CODE[keyboardEvent.keyCode];
if (immutableScanCode !== -1) {
code = immutableScanCode;
}
}
}

const keypress = new ScanCodeBinding(keyboardEvent.ctrlKey, keyboardEvent.shiftKey, keyboardEvent.altKey, keyboardEvent.metaKey, code);
return new NativeResolvedKeybinding(this, this._OS, keypress, null);
}
Expand Down
25 changes: 24 additions & 1 deletion src/vs/workbench/services/keybinding/common/scanCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,15 @@ export const ScanCodeUtils = {
};

/**
* -1 if a HwCode => KeyCode mapping depends on kb layout.
* -1 if a ScanCode => KeyCode mapping depends on kb layout.
*/
export const IMMUTABLE_CODE_TO_KEY_CODE: KeyCode[] = [];

/**
* -1 if a KeyCode => ScanCode mapping depends on kb layout.
*/
export const IMMUTABLE_KEY_CODE_TO_CODE: ScanCode[] = [];

export class ScanCodeBinding {
public readonly ctrlKey: boolean;
public readonly shiftKey: boolean;
Expand Down Expand Up @@ -468,10 +473,28 @@ export class ScanCodeBinding {
IMMUTABLE_CODE_TO_KEY_CODE[i] = -1;
}

for (let i = 0; i <= KeyCode.MAX_VALUE; i++) {
IMMUTABLE_KEY_CODE_TO_CODE[i] = -1;
}

function define(code: ScanCode, keyCode: KeyCode): void {
IMMUTABLE_CODE_TO_KEY_CODE[code] = keyCode;

if (
(keyCode !== KeyCode.Unknown)
&& (keyCode !== KeyCode.Enter)
&& (keyCode !== KeyCode.Ctrl)
&& (keyCode !== KeyCode.Shift)
&& (keyCode !== KeyCode.Alt)
&& (keyCode !== KeyCode.Meta)
) {
IMMUTABLE_KEY_CODE_TO_CODE[keyCode] = code;
}
}

// Manually added due to the exclusion above (due to duplication with NumpadEnter)
IMMUTABLE_KEY_CODE_TO_CODE[KeyCode.Enter] = ScanCode.Enter;

define(ScanCode.None, KeyCode.Unknown);
define(ScanCode.Hyper, KeyCode.Unknown);
define(ScanCode.Super, KeyCode.Unknown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,51 @@ suite('keyboardMapper', () => {
);
});

test('issue #24064: NumLock/NumPad keys stopped working in 1.11 on Linux', () => {
let mapper = new MacLinuxKeyboardMapper(false, {}, OperatingSystem.Linux);

function assertNumpadKeyboardEvent(keyCode: KeyCode, code: string, label: string, electronAccelerator: string, userSettingsLabel: string, dispatch: string): void {
assertResolveKeyboardEvent(
mapper,
{
ctrlKey: false,
shiftKey: false,
altKey: false,
metaKey: false,
keyCode: keyCode,
code: code
},
{
label: label,
ariaLabel: label,
labelWithoutModifiers: label,
ariaLabelWithoutModifiers: label,
electronAccelerator: electronAccelerator,
userSettingsLabel: userSettingsLabel,
isWYSIWYG: true,
isChord: false,
hasCtrlModifier: false,
hasShiftModifier: false,
hasAltModifier: false,
hasMetaModifier: false,
dispatchParts: [dispatch, null],
}
);
}

assertNumpadKeyboardEvent(KeyCode.End, 'Numpad1', 'End', 'End', 'end', '[End]');
assertNumpadKeyboardEvent(KeyCode.DownArrow, 'Numpad2', 'DownArrow', 'Down', 'down', '[ArrowDown]');
assertNumpadKeyboardEvent(KeyCode.PageDown, 'Numpad3', 'PageDown', 'PageDown', 'pagedown', '[PageDown]');
assertNumpadKeyboardEvent(KeyCode.LeftArrow, 'Numpad4', 'LeftArrow', 'Left', 'left', '[ArrowLeft]');
assertNumpadKeyboardEvent(KeyCode.Unknown, 'Numpad5', 'NumPad5', null, 'numpad5', '[Numpad5]');
assertNumpadKeyboardEvent(KeyCode.RightArrow, 'Numpad6', 'RightArrow', 'Right', 'right', '[ArrowRight]');
assertNumpadKeyboardEvent(KeyCode.Home, 'Numpad7', 'Home', 'Home', 'home', '[Home]');
assertNumpadKeyboardEvent(KeyCode.UpArrow, 'Numpad8', 'UpArrow', 'Up', 'up', '[ArrowUp]');
assertNumpadKeyboardEvent(KeyCode.PageUp, 'Numpad9', 'PageUp', 'PageUp', 'pageup', '[PageUp]');
assertNumpadKeyboardEvent(KeyCode.Insert, 'Numpad0', 'Insert', 'Insert', 'insert', '[Insert]');
assertNumpadKeyboardEvent(KeyCode.Delete, 'NumpadDecimal', 'Delete', 'Delete', 'delete', '[Delete]');
});

});

suite('keyboardMapper - LINUX ru', () => {
Expand Down

0 comments on commit 8281fb3

Please sign in to comment.