提交 4ce2cdd6 编写于 作者: M Matt Bierner

ResolvedKeybindingItem as undefined instead of null

上级 aeb7669f
......@@ -352,7 +352,7 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
if (!keybinding) {
// This might be a removal keybinding item in user settings => accept it
result[resultLen++] = new ResolvedKeybindingItem(null, item.command, item.commandArgs, when, isDefault);
result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault);
} else {
const resolvedKeybindings = this.resolveKeybinding(keybinding);
for (const resolvedKeybinding of resolvedKeybindings) {
......
......@@ -17,7 +17,6 @@ import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKe
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { withNullAsUndefined } from 'vs/base/common/types';
interface CurrentChord {
keypress: string;
......@@ -96,11 +95,11 @@ export abstract class AbstractKeybindingService extends Disposable implements IK
}
public lookupKeybinding(commandId: string): ResolvedKeybinding | undefined {
let result = this._getResolver().lookupPrimaryKeybinding(commandId);
const result = this._getResolver().lookupPrimaryKeybinding(commandId);
if (!result) {
return undefined;
}
return withNullAsUndefined(result.resolvedKeybinding);
return result.resolvedKeybinding;
}
public dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean {
......
......@@ -10,7 +10,7 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
export class ResolvedKeybindingItem {
_resolvedKeybindingItemBrand: void;
public readonly resolvedKeybinding: ResolvedKeybinding | null;
public readonly resolvedKeybinding: ResolvedKeybinding | undefined;
public readonly keypressParts: string[];
public readonly bubble: boolean;
public readonly command: string | null;
......@@ -18,7 +18,7 @@ export class ResolvedKeybindingItem {
public readonly when: ContextKeyExpr | undefined;
public readonly isDefault: boolean;
constructor(resolvedKeybinding: ResolvedKeybinding | null, command: string | null, commandArgs: any, when: ContextKeyExpr | undefined, isDefault: boolean) {
constructor(resolvedKeybinding: ResolvedKeybinding | undefined, command: string | null, commandArgs: any, when: ContextKeyExpr | undefined, isDefault: boolean) {
this.resolvedKeybinding = resolvedKeybinding;
this.keypressParts = resolvedKeybinding ? removeElementsAfterNulls(resolvedKeybinding.getDispatchParts()) : [];
this.bubble = (command ? command.charCodeAt(0) === CharCode.Caret : false);
......
......@@ -180,7 +180,7 @@ suite('AbstractKeybindingService', () => {
});
function kbItem(keybinding: number, command: string, when?: ContextKeyExpr): ResolvedKeybindingItem {
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : null);
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : undefined);
return new ResolvedKeybindingItem(
resolvedKeybinding,
command,
......
......@@ -21,7 +21,7 @@ function createContext(ctx: any) {
suite('KeybindingResolver', () => {
function kbItem(keybinding: number, command: string, commandArgs: any, when: ContextKeyExpr, isDefault: boolean): ResolvedKeybindingItem {
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : null);
const resolvedKeybinding = (keybinding !== 0 ? new USLayoutResolvedKeybinding(createKeybinding(keybinding, OS)!, OS) : undefined);
return new ResolvedKeybindingItem(
resolvedKeybinding,
command,
......
......@@ -396,7 +396,7 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
const keybinding = item.keybinding;
if (!keybinding) {
// This might be a removal keybinding item in user settings => accept it
result[resultLen++] = new ResolvedKeybindingItem(null, item.command, item.commandArgs, when, isDefault);
result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault);
} else {
const resolvedKeybindings = this.resolveKeybinding(keybinding);
for (const resolvedKeybinding of resolvedKeybindings) {
......@@ -415,7 +415,7 @@ export class WorkbenchKeybindingService extends AbstractKeybindingService {
const parts = item.parts;
if (parts.length === 0) {
// This might be a removal keybinding item in user settings => accept it
result[resultLen++] = new ResolvedKeybindingItem(null, item.command, item.commandArgs, when, isDefault);
result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault);
} else {
const resolvedKeybindings = this._keyboardMapper.resolveUserBinding(parts);
for (const resolvedKeybinding of resolvedKeybindings) {
......
......@@ -274,7 +274,7 @@ suite('KeybindingsEditing', () => {
parts.push(aSimpleKeybinding(chordPart));
}
}
let keybinding = parts.length > 0 ? new USLayoutResolvedKeybinding(new ChordKeybinding(parts), OS) : null;
const keybinding = parts.length > 0 ? new USLayoutResolvedKeybinding(new ChordKeybinding(parts), OS) : undefined;
return new ResolvedKeybindingItem(keybinding, command || 'some command', null, when ? ContextKeyExpr.deserialize(when) : undefined, isDefault === undefined ? true : isDefault);
}
......
......@@ -174,7 +174,7 @@ export class KeybindingsEditorModel extends EditorModel {
const commandsWithDefaultKeybindings = this.keybindingsService.getDefaultKeybindings().map(keybinding => keybinding.command);
for (const command of KeybindingResolver.getAllUnboundCommands(boundCommands)) {
const keybindingItem = new ResolvedKeybindingItem(null, command, null, undefined, commandsWithDefaultKeybindings.indexOf(command) === -1);
const keybindingItem = new ResolvedKeybindingItem(undefined, command, null, undefined, commandsWithDefaultKeybindings.indexOf(command) === -1);
this._keybindingItemsSortedByPrecedence.push(KeybindingsEditorModel.toKeybindingEntry(command, keybindingItem, workbenchActionsRegistry, editorActionsLabels));
}
this._keybindingItems = this._keybindingItemsSortedByPrecedence.slice(0).sort((a, b) => KeybindingsEditorModel.compareKeybindingData(a, b));
......
......@@ -617,7 +617,7 @@ suite('KeybindingsEditorModel test', () => {
parts.push(aSimpleKeybinding(chordPart));
}
}
let keybinding = parts.length > 0 ? new USLayoutResolvedKeybinding(new ChordKeybinding(parts), OS) : null;
const keybinding = parts.length > 0 ? new USLayoutResolvedKeybinding(new ChordKeybinding(parts), OS) : undefined;
return new ResolvedKeybindingItem(keybinding, command || 'some command', null, when ? ContextKeyExpr.deserialize(when) : undefined, isDefault === undefined ? true : isDefault);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册