Skip to content

Commit 2ff5d6b

Browse files
committed
Add _standardKeyboardEventBrand to make it clear a StandardKeyboardEvent is expected (microsoft#68171)
1 parent b4d581b commit 2ff5d6b

10 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/vs/base/browser/keyboardEvent.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ export function getCodeForKeyCode(keyCode: KeyCode): number {
179179
}
180180

181181
export interface IKeyboardEvent {
182+
183+
readonly _standardKeyboardEventBrand: true;
184+
182185
readonly browserEvent: KeyboardEvent;
183186
readonly target: HTMLElement;
184187

@@ -206,6 +209,8 @@ const metaKeyMod = (platform.isMacintosh ? KeyMod.CtrlCmd : KeyMod.WinCtrl);
206209

207210
export class StandardKeyboardEvent implements IKeyboardEvent {
208211

212+
readonly _standardKeyboardEventBrand = true;
213+
209214
public readonly browserEvent: KeyboardEvent;
210215
public readonly target: HTMLElement;
211216

src/vs/editor/standalone/test/browser/simpleServices.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ suite('StandaloneKeybindingService', () => {
4242
}, null);
4343

4444
keybindingService.testDispatch({
45+
_standardKeyboardEventBrand: true,
4546
ctrlKey: false,
4647
shiftKey: false,
4748
altKey: false,

src/vs/monaco.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ declare namespace monaco {
380380
}
381381

382382
export interface IKeyboardEvent {
383+
readonly _standardKeyboardEventBrand: true;
383384
readonly browserEvent: KeyboardEvent;
384385
readonly target: HTMLElement;
385386
readonly ctrlKey: boolean;

src/vs/platform/keybinding/common/keybinding.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export interface IKeybindingEvent {
2828
}
2929

3030
export interface IKeyboardEvent {
31+
readonly _standardKeyboardEventBrand: true;
32+
3133
readonly ctrlKey: boolean;
3234
readonly shiftKey: boolean;
3335
readonly altKey: boolean;

src/vs/platform/keybinding/test/common/abstractKeybindingService.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ suite('AbstractKeybindingService', () => {
7272
public testDispatch(kb: number): boolean {
7373
const keybinding = createSimpleKeybinding(kb, OS);
7474
return this._dispatch({
75+
_standardKeyboardEventBrand: true,
7576
ctrlKey: keybinding.ctrlKey,
7677
shiftKey: keybinding.shiftKey,
7778
altKey: keybinding.altKey,

src/vs/workbench/contrib/markers/electron-browser/markersPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
3737
import { Separator, ActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
3838
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
3939
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
40-
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
40+
import { IKeyboardEvent, StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
4141
import { KeyCode } from 'vs/base/common/keyCodes';
4242
import { domEvent } from 'vs/base/browser/event';
4343
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
@@ -357,7 +357,7 @@ export class MarkersPanel extends Panel implements IMarkerFilterController {
357357

358358
// move focus to input, whenever a key is pressed in the panel container
359359
this._register(domEvent(parent, 'keydown')(e => {
360-
if (this.filterInputActionItem && this.keybindingService.mightProducePrintableCharacter(e)) {
360+
if (this.filterInputActionItem && this.keybindingService.mightProducePrintableCharacter(new StandardKeyboardEvent(e))) {
361361
this.filterInputActionItem.focus();
362362
}
363363
}));

src/vs/workbench/services/keybinding/common/macLinuxKeyboardMapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ export class MacLinuxKeyboardMapper implements IKeyboardMapper {
725725
const hwAltKey = (mod & 0b100) ? true : false;
726726
const scanCodeCombo = new ScanCodeCombo(hwCtrlKey, hwShiftKey, hwAltKey, scanCode);
727727
const resolvedKb = this.resolveKeyboardEvent({
728+
_standardKeyboardEventBrand: true,
728729
ctrlKey: scanCodeCombo.ctrlKey,
729730
shiftKey: scanCodeCombo.shiftKey,
730731
altKey: scanCodeCombo.altKey,

src/vs/workbench/services/keybinding/test/macLinuxFallbackKeyboardMapper.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ suite('keyboardMapper - MAC fallback', () => {
5151
assertResolveKeyboardEvent(
5252
mapper,
5353
{
54+
_standardKeyboardEventBrand: true,
5455
ctrlKey: false,
5556
shiftKey: false,
5657
altKey: false,
@@ -96,6 +97,7 @@ suite('keyboardMapper - MAC fallback', () => {
9697
assertResolveKeyboardEvent(
9798
mapper,
9899
{
100+
_standardKeyboardEventBrand: true,
99101
ctrlKey: false,
100102
shiftKey: false,
101103
altKey: false,
@@ -158,6 +160,7 @@ suite('keyboardMapper - LINUX fallback', () => {
158160
assertResolveKeyboardEvent(
159161
mapper,
160162
{
163+
_standardKeyboardEventBrand: true,
161164
ctrlKey: true,
162165
shiftKey: false,
163166
altKey: false,
@@ -216,6 +219,7 @@ suite('keyboardMapper - LINUX fallback', () => {
216219
assertResolveKeyboardEvent(
217220
mapper,
218221
{
222+
_standardKeyboardEventBrand: true,
219223
ctrlKey: true,
220224
shiftKey: false,
221225
altKey: false,

src/vs/workbench/services/keybinding/test/macLinuxKeyboardMapper.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ suite('keyboardMapper - MAC de_ch', () => {
104104
assertResolveKeyboardEvent(
105105
mapper,
106106
{
107+
_standardKeyboardEventBrand: true,
107108
ctrlKey: false,
108109
shiftKey: false,
109110
altKey: false,
@@ -142,6 +143,7 @@ suite('keyboardMapper - MAC de_ch', () => {
142143
assertResolveKeyboardEvent(
143144
mapper,
144145
{
146+
_standardKeyboardEventBrand: true,
145147
ctrlKey: false,
146148
shiftKey: false,
147149
altKey: false,
@@ -285,6 +287,7 @@ suite('keyboardMapper - MAC de_ch', () => {
285287
assertResolveKeyboardEvent(
286288
mapper,
287289
{
290+
_standardKeyboardEventBrand: true,
288291
ctrlKey: false,
289292
shiftKey: false,
290293
altKey: false,
@@ -331,6 +334,7 @@ suite('keyboardMapper - MAC de_ch', () => {
331334
assertResolveKeyboardEvent(
332335
mapper,
333336
{
337+
_standardKeyboardEventBrand: true,
334338
ctrlKey: false,
335339
shiftKey: false,
336340
altKey: false,
@@ -354,6 +358,7 @@ suite('keyboardMapper - MAC de_ch', () => {
354358
assertResolveKeyboardEvent(
355359
mapper,
356360
{
361+
_standardKeyboardEventBrand: true,
357362
ctrlKey: false,
358363
shiftKey: false,
359364
altKey: false,
@@ -410,6 +415,7 @@ suite('keyboardMapper - MAC en_us', () => {
410415
assertResolveKeyboardEvent(
411416
mapper,
412417
{
418+
_standardKeyboardEventBrand: true,
413419
ctrlKey: false,
414420
shiftKey: false,
415421
altKey: false,
@@ -433,6 +439,7 @@ suite('keyboardMapper - MAC en_us', () => {
433439
assertResolveKeyboardEvent(
434440
mapper,
435441
{
442+
_standardKeyboardEventBrand: true,
436443
ctrlKey: false,
437444
shiftKey: false,
438445
altKey: false,
@@ -523,6 +530,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
523530
assertResolveKeyboardEvent(
524531
mapper,
525532
{
533+
_standardKeyboardEventBrand: true,
526534
ctrlKey: true,
527535
shiftKey: false,
528536
altKey: false,
@@ -553,6 +561,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
553561
assertResolveKeyboardEvent(
554562
mapper,
555563
{
564+
_standardKeyboardEventBrand: true,
556565
ctrlKey: true,
557566
shiftKey: false,
558567
altKey: false,
@@ -696,6 +705,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
696705
assertResolveKeyboardEvent(
697706
mapper,
698707
{
708+
_standardKeyboardEventBrand: true,
699709
ctrlKey: true,
700710
shiftKey: false,
701711
altKey: false,
@@ -719,6 +729,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
719729
assertResolveKeyboardEvent(
720730
mapper,
721731
{
732+
_standardKeyboardEventBrand: true,
722733
ctrlKey: true,
723734
shiftKey: false,
724735
altKey: false,
@@ -760,6 +771,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
760771
assertResolveKeyboardEvent(
761772
mapper,
762773
{
774+
_standardKeyboardEventBrand: true,
763775
ctrlKey: true,
764776
shiftKey: false,
765777
altKey: false,
@@ -783,6 +795,7 @@ suite('keyboardMapper - LINUX de_ch', () => {
783795
assertResolveKeyboardEvent(
784796
mapper,
785797
{
798+
_standardKeyboardEventBrand: true,
786799
ctrlKey: true,
787800
shiftKey: false,
788801
altKey: false,
@@ -854,6 +867,7 @@ suite('keyboardMapper - LINUX en_us', () => {
854867
assertResolveKeyboardEvent(
855868
mapper,
856869
{
870+
_standardKeyboardEventBrand: true,
857871
ctrlKey: true,
858872
shiftKey: false,
859873
altKey: false,
@@ -892,6 +906,7 @@ suite('keyboardMapper - LINUX en_us', () => {
892906
assertResolveKeyboardEvent(
893907
mapper,
894908
{
909+
_standardKeyboardEventBrand: true,
895910
ctrlKey: true,
896911
shiftKey: false,
897912
altKey: false,
@@ -1035,6 +1050,7 @@ suite('keyboardMapper - LINUX en_us', () => {
10351050
assertResolveKeyboardEvent(
10361051
mapper,
10371052
{
1053+
_standardKeyboardEventBrand: true,
10381054
ctrlKey: true,
10391055
shiftKey: false,
10401056
altKey: false,
@@ -1096,6 +1112,7 @@ suite('keyboardMapper - LINUX en_us', () => {
10961112
assertResolveKeyboardEvent(
10971113
mapper,
10981114
{
1115+
_standardKeyboardEventBrand: true,
10991116
ctrlKey: true,
11001117
shiftKey: false,
11011118
altKey: false,
@@ -1154,6 +1171,7 @@ suite('keyboardMapper - LINUX en_us', () => {
11541171
assertResolveKeyboardEvent(
11551172
mapper,
11561173
{
1174+
_standardKeyboardEventBrand: true,
11571175
ctrlKey: true,
11581176
shiftKey: false,
11591177
altKey: false,
@@ -1177,6 +1195,7 @@ suite('keyboardMapper - LINUX en_us', () => {
11771195
assertResolveKeyboardEvent(
11781196
mapper,
11791197
{
1198+
_standardKeyboardEventBrand: true,
11801199
ctrlKey: true,
11811200
shiftKey: false,
11821201
altKey: false,
@@ -1212,6 +1231,7 @@ suite('keyboardMapper', () => {
12121231
assertResolveKeyboardEvent(
12131232
mapper,
12141233
{
1234+
_standardKeyboardEventBrand: true,
12151235
ctrlKey: true,
12161236
shiftKey: false,
12171237
altKey: false,
@@ -1238,6 +1258,7 @@ suite('keyboardMapper', () => {
12381258
assertResolveKeyboardEvent(
12391259
mapper,
12401260
{
1261+
_standardKeyboardEventBrand: true,
12411262
ctrlKey: false,
12421263
shiftKey: false,
12431264
altKey: false,
@@ -1277,6 +1298,7 @@ suite('keyboardMapper', () => {
12771298
assertResolveKeyboardEvent(
12781299
mapper,
12791300
{
1301+
_standardKeyboardEventBrand: true,
12801302
ctrlKey: false,
12811303
shiftKey: false,
12821304
altKey: false,
@@ -1372,6 +1394,7 @@ suite('keyboardMapper - LINUX en_uk', () => {
13721394
assertResolveKeyboardEvent(
13731395
mapper,
13741396
{
1397+
_standardKeyboardEventBrand: true,
13751398
ctrlKey: true,
13761399
shiftKey: false,
13771400
altKey: true,

src/vs/workbench/services/keybinding/test/windowsKeyboardMapper.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
6969
assertResolveKeyboardEvent(
7070
mapper,
7171
{
72+
_standardKeyboardEventBrand: true,
7273
ctrlKey: true,
7374
shiftKey: false,
7475
altKey: false,
@@ -108,6 +109,7 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
108109
assertResolveKeyboardEvent(
109110
mapper,
110111
{
112+
_standardKeyboardEventBrand: true,
111113
ctrlKey: true,
112114
shiftKey: false,
113115
altKey: false,
@@ -251,6 +253,7 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
251253
assertResolveKeyboardEvent(
252254
mapper,
253255
{
256+
_standardKeyboardEventBrand: true,
254257
ctrlKey: true,
255258
shiftKey: false,
256259
altKey: false,
@@ -296,6 +299,7 @@ suite('keyboardMapper - WINDOWS de_ch', () => {
296299
assertResolveKeyboardEvent(
297300
mapper,
298301
{
302+
_standardKeyboardEventBrand: true,
299303
ctrlKey: true,
300304
shiftKey: false,
301305
altKey: false,
@@ -383,6 +387,7 @@ suite('keyboardMapper - WINDOWS en_us', () => {
383387
assertResolveKeyboardEvent(
384388
mapper,
385389
{
390+
_standardKeyboardEventBrand: true,
386391
ctrlKey: true,
387392
shiftKey: false,
388393
altKey: false,
@@ -419,6 +424,7 @@ suite('keyboardMapper - WINDOWS por_ptb', () => {
419424
assertResolveKeyboardEvent(
420425
mapper,
421426
{
427+
_standardKeyboardEventBrand: true,
422428
ctrlKey: true,
423429
shiftKey: false,
424430
altKey: false,
@@ -442,6 +448,7 @@ suite('keyboardMapper - WINDOWS por_ptb', () => {
442448
assertResolveKeyboardEvent(
443449
mapper,
444450
{
451+
_standardKeyboardEventBrand: true,
445452
ctrlKey: true,
446453
shiftKey: false,
447454
altKey: false,

0 commit comments

Comments
 (0)