Skip to content

Commit 4ce2cdd

Browse files
committed
ResolvedKeybindingItem as undefined instead of null
1 parent aeb7669 commit 4ce2cdd

9 files changed

Lines changed: 12 additions & 13 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
352352

353353
if (!keybinding) {
354354
// This might be a removal keybinding item in user settings => accept it
355-
result[resultLen++] = new ResolvedKeybindingItem(null, item.command, item.commandArgs, when, isDefault);
355+
result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault);
356356
} else {
357357
const resolvedKeybindings = this.resolveKeybinding(keybinding);
358358
for (const resolvedKeybinding of resolvedKeybindings) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
1717
import { INotificationService } from 'vs/platform/notification/common/notification';
1818
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
1919
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
20-
import { withNullAsUndefined } from 'vs/base/common/types';
2120

2221
interface CurrentChord {
2322
keypress: string;
@@ -96,11 +95,11 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
9695
}
9796

9897
public lookupKeybinding(commandId: string): ResolvedKeybinding | undefined {
99-
let result = this._getResolver().lookupPrimaryKeybinding(commandId);
98+
const result = this._getResolver().lookupPrimaryKeybinding(commandId);
10099
if (!result) {
101100
return undefined;
102101
}
103-
return withNullAsUndefined(result.resolvedKeybinding);
102+
return result.resolvedKeybinding;
104103
}
105104

106105
public dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1010
export class ResolvedKeybindingItem {
1111
_resolvedKeybindingItemBrand: void;
1212

13-
public readonly resolvedKeybinding: ResolvedKeybinding | null;
13+
public readonly resolvedKeybinding: ResolvedKeybinding | undefined;
1414
public readonly keypressParts: string[];
1515
public readonly bubble: boolean;
1616
public readonly command: string | null;
1717
public readonly commandArgs: any;
1818
public readonly when: ContextKeyExpr | undefined;
1919
public readonly isDefault: boolean;
2020

21-
constructor(resolvedKeybinding: ResolvedKeybinding | null, command: string | null, commandArgs: any, when: ContextKeyExpr | undefined, isDefault: boolean) {
21+
constructor(resolvedKeybinding: ResolvedKeybinding | undefined, command: string | null, commandArgs: any, when: ContextKeyExpr | undefined, isDefault: boolean) {
2222
this.resolvedKeybinding = resolvedKeybinding;
2323
this.keypressParts = resolvedKeybinding ? removeElementsAfterNulls(resolvedKeybinding.getDispatchParts()) : [];
2424
this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ suite('AbstractKeybindingService', () => {
180180
});
181181

182182
function kbItem(keybinding: number, command: string, when?: ContextKeyExpr): ResolvedKeybindingItem {
183-
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : null);
183+
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : undefined);
184184
return new ResolvedKeybindingItem(
185185
resolvedKeybinding,
186186
command,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function createContext(ctx: any) {
2121
suite('KeybindingResolver', () => {
2222

2323
function kbItem(keybinding: number, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean): ResolvedKeybindingItem {
24-
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : null);
24+
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : undefined);
2525
return new ResolvedKeybindingItem(
2626
resolvedKeybinding,
2727
command,

src/vs/workbench/services/keybinding/electron-browser/keybindingService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
396396
const keybinding = item.keybinding;
397397
if (!keybinding) {
398398
// This might be a removal keybinding item in user settings => accept it
399-
result[resultLen++] = new ResolvedKeybindingItem(null, item.command, item.commandArgs, when, isDefault);
399+
result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault);
400400
} else {
401401
const resolvedKeybindings = this.resolveKeybinding(keybinding);
402402
for (const resolvedKeybinding of resolvedKeybindings) {
@@ -415,7 +415,7 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
415415
const parts = item.parts;
416416
if (parts.length === 0) {
417417
// This might be a removal keybinding item in user settings => accept it
418-
result[resultLen++] = new ResolvedKeybindingItem(null, item.command, item.commandArgs, when, isDefault);
418+
result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault);
419419
} else {
420420
const resolvedKeybindings = this._keyboardMapper.resolveUserBinding(parts);
421421
for (const resolvedKeybinding of resolvedKeybindings) {

src/vs/workbench/services/keybinding/test/electron-browser/keybindingEditing.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ suite('KeybindingsEditing', () => {
274274
parts.push(aSimpleKeybinding(chordPart));
275275
}
276276
}
277-
let keybinding = parts.length > 0 ? new USLayoutResolvedKeybinding(new ChordKeybinding(parts), OS) : null;
277+
const keybinding = parts.length > 0 ? new USLayoutResolvedKeybinding(new ChordKeybinding(parts), OS) : undefined;
278278
return new ResolvedKeybindingItem(keybinding, command || 'some command', null, when ? ContextKeyExpr.deserialize(when) : undefined, isDefault === undefined ? true : isDefault);
279279
}
280280

src/vs/workbench/services/preferences/common/keybindingsEditorModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class KeybindingsEditorModel extends EditorModel {
174174

175175
const commandsWithDefaultKeybindings = this.keybindingsService.getDefaultKeybindings().map(keybinding => keybinding.command);
176176
for (const command of KeybindingResolver.getAllUnboundCommands(boundCommands)) {
177-
const keybindingItem = new ResolvedKeybindingItem(null, command, null, undefined, commandsWithDefaultKeybindings.indexOf(command) === -1);
177+
const keybindingItem = new ResolvedKeybindingItem(undefined, command, null, undefined, commandsWithDefaultKeybindings.indexOf(command) === -1);
178178
this._keybindingItemsSortedByPrecedence.push(KeybindingsEditorModel.toKeybindingEntry(command, keybindingItem, workbenchActionsRegistry, editorActionsLabels));
179179
}
180180
this._keybindingItems = this._keybindingItemsSortedByPrecedence.slice(0).sort((a, b) => KeybindingsEditorModel.compareKeybindingData(a, b));

src/vs/workbench/services/preferences/test/common/keybindingsEditorModel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ suite('KeybindingsEditorModel test', () => {
617617
parts.push(aSimpleKeybinding(chordPart));
618618
}
619619
}
620-
let keybinding = parts.length > 0 ? new USLayoutResolvedKeybinding(new ChordKeybinding(parts), OS) : null;
620+
const keybinding = parts.length > 0 ? new USLayoutResolvedKeybinding(new ChordKeybinding(parts), OS) : undefined;
621621
return new ResolvedKeybindingItem(keybinding, command || 'some command', null, when ? ContextKeyExpr.deserialize(when) : undefined, isDefault === undefined ? true : isDefault);
622622
}
623623

0 commit comments

Comments
 (0)