Skip to content

Commit 72c1408

Browse files
authored
Avoid hash collisions between KeyCodeChord and ScanCodeChord (microsoft#173585)
Fixes microsoft#173325
1 parent 209abb1 commit 72c1408

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/vs/base/common/keybindings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class KeyCodeChord implements Modifiers {
9494
const shift = this.shiftKey ? '1' : '0';
9595
const alt = this.altKey ? '1' : '0';
9696
const meta = this.metaKey ? '1' : '0';
97-
return `${ctrl}${shift}${alt}${meta}${this.keyCode}`;
97+
return `K${ctrl}${shift}${alt}${meta}${this.keyCode}`;
9898
}
9999

100100
public isModifierKey(): boolean {
@@ -154,7 +154,7 @@ export class ScanCodeChord implements Modifiers {
154154
const shift = this.shiftKey ? '1' : '0';
155155
const alt = this.altKey ? '1' : '0';
156156
const meta = this.metaKey ? '1' : '0';
157-
return `${ctrl}${shift}${alt}${meta}${this.scanCode}`;
157+
return `S${ctrl}${shift}${alt}${meta}${this.scanCode}`;
158158
}
159159

160160
/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as assert from 'assert';
7+
import { KeyCode, ScanCode } from 'vs/base/common/keyCodes';
8+
import { KeyCodeChord, ScanCodeChord } from 'vs/base/common/keybindings';
9+
10+
suite('keyCodes', () => {
11+
12+
test('issue #173325: wrong interpretations of special keys (e.g. [Equal] is mistaken for V)', () => {
13+
const a = new KeyCodeChord(true, false, false, false, KeyCode.KeyV);
14+
const b = new ScanCodeChord(true, false, false, false, ScanCode.Equal);
15+
assert.strictEqual(a.getHashCode() === b.getHashCode(), false);
16+
});
17+
18+
});

0 commit comments

Comments
 (0)