array destructure ftw

This commit is contained in:
Benjamin Pasero
2017-02-09 15:21:14 +01:00
parent c8dee4c016
commit b5485273fc
21 changed files with 51 additions and 98 deletions

View File

@@ -139,9 +139,9 @@ class AccessibilityHelpWidget extends Widget implements IOverlayWidget {
}
private _descriptionForCommand(commandId: string, msg: string, noKbMsg: string): string {
let keybindings = this._keybindingService.lookupKeybindings(commandId);
if (keybindings.length > 0) {
return strings.format(msg, this._keybindingService.getAriaLabelFor(keybindings[0]));
let [kb] = this._keybindingService.lookupKeybindings(commandId);
if (kb) {
return strings.format(msg, this._keybindingService.getAriaLabelFor(kb));
}
return strings.format(noKbMsg, commandId);
}

View File

@@ -200,11 +200,8 @@ export class ContextMenuController implements IEditorContribution {
}
private _keybindingFor(action: IAction): Keybinding {
var opts = this._keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
return null;
var [kb] = this._keybindingService.lookupKeybindings(action.id);
return kb;
}
public getId(): string {

View File

@@ -242,10 +242,10 @@ class DefineKeybindingLauncherWidget implements IOverlayWidget {
this._domNode.className = 'defineKeybindingLauncher';
this._domNode.style.display = 'none';
this._isVisible = false;
let keybinding = keybindingService.lookupKeybindings(DefineKeybindingAction.ID);
let [keybinding] = keybindingService.lookupKeybindings(DefineKeybindingAction.ID);
let extra = '';
if (keybinding.length > 0) {
extra += ' (' + keybindingService.getLabelFor(keybinding[0]) + ')';
if (keybinding) {
extra += ' (' + keybindingService.getLabelFor(keybinding) + ')';
}
this._domNode.appendChild(document.createTextNode(NLS_LAUNCH_MESSAGE + extra));

View File

@@ -89,11 +89,11 @@ export class FindOptionsWidget extends Widget implements IOverlayWidget {
}
private _keybindingLabelFor(actionId: string): string {
let keybindings = this._keybindingService.lookupKeybindings(actionId);
if (keybindings.length === 0) {
let [kb] = this._keybindingService.lookupKeybindings(actionId);
if (!kb) {
return '';
}
return ' (' + this._keybindingService.getLabelFor(keybindings[0]) + ')';
return ` (${this._keybindingService.getLabelFor(kb)})`;
}
public dispose(): void {

View File

@@ -420,11 +420,11 @@ export class FindWidget extends Widget implements IOverlayWidget {
// ----- initialization
private _keybindingLabelFor(actionId: string): string {
let keybindings = this._keybindingService.lookupKeybindings(actionId);
if (keybindings.length === 0) {
let [kb] = this._keybindingService.lookupKeybindings(actionId);
if (!kb) {
return '';
}
return ' (' + this._keybindingService.getLabelFor(keybindings[0]) + ')';
return ` (${this._keybindingService.getLabelFor(kb)})`;
}
private _buildFindPart(): HTMLElement {

View File

@@ -62,8 +62,8 @@ class Renderer implements IRenderer<ICompletionItem, ISuggestionTemplateData> {
private editor: ICodeEditor,
@IKeybindingService keybindingService: IKeybindingService
) {
const keybindings = keybindingService.lookupKeybindings('editor.action.triggerSuggest');
this.triggerKeybindingLabel = keybindings.length === 0 ? '' : ` (${keybindingService.getLabelFor(keybindings[0])})`;
const [kb] = keybindingService.lookupKeybindings('editor.action.triggerSuggest');
this.triggerKeybindingLabel = !kb ? '' : ` (${keybindingService.getLabelFor(kb)})`;
}
get templateId(): string {

View File

@@ -153,7 +153,7 @@ class MenuItemActionItem extends ActionItem {
_updateTooltip(): void {
const element = this.$e.getHTMLElement();
const keybinding = this._keybindingService.lookupKeybindings(this._command.id)[0];
const [keybinding] = this._keybindingService.lookupKeybindings(this._command.id);
const keybindingLabel = keybinding && this._keybindingService.getLabelFor(keybinding);
element.title = keybindingLabel

View File

@@ -140,9 +140,9 @@ export class ActivityActionItem extends BaseActionItem {
}
private getKeybindingLabel(id: string): string {
const keys = this.keybindingService.lookupKeybindings(id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
return keys[0];
const [kb] = this.keybindingService.lookupKeybindings(id);
if (kb) {
return this.keybindingService.getLabelFor(kb);
}
return null;
@@ -455,12 +455,9 @@ export class ViewletOverflowActivityActionItem extends BaseActionItem {
}
private getKeybinding(action: IAction): Keybinding {
const opts = this.keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
const [kb] = this.keybindingService.lookupKeybindings(action.id);
return null;
return kb;
}
private getActions(): OpenViewletAction[] {

View File

@@ -340,11 +340,7 @@ export abstract class CompositePart<T extends Composite> extends Part {
compositeTitle = compositeDescriptor.name;
}
let keybinding: string = null;
let keys = this.keybindingService.lookupKeybindings(compositeId).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
keybinding = keys[0];
}
let [keybinding] = this.keybindingService.lookupKeybindings(compositeId).map(k => this.keybindingService.getLabelFor(k));
this.titleLabel.updateTitle(compositeId, compositeTitle, keybinding);
@@ -426,12 +422,9 @@ export abstract class CompositePart<T extends Composite> extends Part {
actionItemProvider: (action: Action) => this.actionItemProvider(action),
orientation: ActionsOrientation.HORIZONTAL,
getKeyBinding: (action) => {
const opts = this.keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
const [kb] = this.keybindingService.lookupKeybindings(action.id);
return null;
return kb;
},
getKeyBindingLabel: (key) => this.keybindingService.getLabelFor(key)
});

View File

@@ -435,12 +435,9 @@ export abstract class TitleControl implements ITitleAreaControl {
}
protected getKeybinding(action: IAction): Keybinding {
const opts = this.keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
const [kb] = this.keybindingService.lookupKeybindings(action.id);
return null;
return kb;
}
protected getKeybindingLabel(action: IAction): string {

View File

@@ -44,12 +44,9 @@ export class PanelAction extends Action {
}
private getKeybindingLabel(id: string): string {
const keys = this.keybindingService.lookupKeybindings(id).map(k => this.keybindingService.getLabelFor(k));
if (keys && keys.length) {
return keys[0];
}
const [keys] = this.keybindingService.lookupKeybindings(id).map(k => this.keybindingService.getLabelFor(k));
return null;
return keys;
}
}

View File

@@ -344,12 +344,9 @@ export abstract class AdaptiveCollapsibleViewletView extends FixedCollapsibleVie
actionItemProvider: (action) => { return this.getActionItem(action); },
ariaLabel: nls.localize('viewToolbarAriaLabel', "{0} actions", this.viewName),
getKeyBinding: (action) => {
const opts = this.keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
const [kb] = this.keybindingService.lookupKeybindings(action.id);
return null;
return kb;
},
getKeyBindingLabel: (key) => this.keybindingService.getLabelFor(key)
});
@@ -481,12 +478,9 @@ export abstract class CollapsibleViewletView extends CollapsibleView implements
actionItemProvider: (action) => { return this.getActionItem(action); },
ariaLabel: nls.localize('viewToolbarAriaLabel', "{0} actions", this.viewName),
getKeyBinding: (action) => {
const opts = this.keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
const [kb] = this.keybindingService.lookupKeybindings(action.id);
return null;
return kb;
},
getKeyBindingLabel: (key) => this.keybindingService.getLabelFor(key)
});

View File

@@ -319,12 +319,9 @@ export class ElectronWindow {
getAnchor: () => target,
getActions: () => TPromise.as(TextInputActions),
getKeyBinding: action => {
const opts = this.keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
const [kb] = this.keybindingService.lookupKeybindings(action.id);
return null;
return kb;
}
});
}

View File

@@ -42,7 +42,7 @@ export abstract class AbstractDebugAction extends Action {
}
public get tooltip(): string {
const keybinding = this.keybindingService.lookupKeybindings(this.id)[0];
const [keybinding] = this.keybindingService.lookupKeybindings(this.id);
const keybindingLabel = keybinding && this.keybindingService.getLabelFor(keybinding);
return keybindingLabel ? `${this.label} (${keybindingLabel})` : this.label;

View File

@@ -43,7 +43,7 @@ import { Position, IResourceInput, IEditorInput } from 'vs/platform/editor/commo
import { IInstantiationService, IConstructorSignature2, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IMessageService, IMessageWithAction, IConfirmation, Severity, CancelAction } from 'vs/platform/message/common/message';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { Keybinding, KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Keybinding } from 'vs/base/common/keyCodes';
import { getCodeEditor } from 'vs/editor/common/services/codeEditorService';
import { IEditorViewState } from 'vs/editor/common/editorCommon';
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
@@ -1925,25 +1925,9 @@ export class GlobalCopyPathAction extends Action {
}
export function keybindingForAction(id: string, keybindingService: IKeybindingService): Keybinding {
switch (id) {
case GlobalNewUntitledFileAction.ID:
return new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_N);
case SaveFileAction.ID:
return new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_S);
case CopyFileAction.ID:
return new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_C);
case PasteFileAction.ID:
return new Keybinding(KeyMod.CtrlCmd | KeyCode.KEY_V);
}
const [kb] = keybindingService.lookupKeybindings(id);
if (keybindingService) {
const keys = keybindingService.lookupKeybindings(id);
if (keys.length > 0) {
return keys[0]; // only take the first one
}
}
return null;
return kb;
}
export function validateFileName(parent: IFileStat, name: string, allowOverwriting: boolean = false): string {

View File

@@ -151,10 +151,7 @@ export class Controller extends treedefaults.DefaultController {
}
private _keybindingFor(action: IAction): Keybinding {
var opts = this._keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
}
return null;
var [kb] = this._keybindingService.lookupKeybindings(action.id);
return kb;
}
}

View File

@@ -325,8 +325,8 @@ export class FloatingClickWidget extends Widget implements IOverlayWidget {
) {
super();
if (keyBindingAction) {
let keybinding = keybindingService.lookupKeybindings(keyBindingAction);
if (keybinding.length > 0) {
let [keybinding] = keybindingService.lookupKeybindings(keyBindingAction);
if (keybinding) {
this.label += ' (' + keybindingService.getLabelFor(keybinding[0]) + ')';
}
}

View File

@@ -69,8 +69,8 @@ export class SearchWidget extends Widget {
private static REPLACE_ALL_DISABLED_LABEL = nls.localize('search.action.replaceAll.disabled.label', "Replace All (Submit Search to Enable)");
private static REPLACE_ALL_ENABLED_LABEL = (keyBindingService2: IKeybindingService): string => {
let keybindings = keyBindingService2.lookupKeybindings(ReplaceAllAction.ID);
return appendKeyBindingLabel(nls.localize('search.action.replaceAll.enabled.label', "Replace All"), keybindings[0], keyBindingService2);
let [kb] = keyBindingService2.lookupKeybindings(ReplaceAllAction.ID);
return appendKeyBindingLabel(nls.localize('search.action.replaceAll.enabled.label', "Replace All"), kb, keyBindingService2);
}
public domNode: HTMLElement;

View File

@@ -167,9 +167,9 @@ export class TerminalPanel extends Panel {
getActions: () => TPromise.as(this._getContextMenuActions()),
getActionsContext: () => this._parentDomElement,
getKeyBinding: (action) => {
const opts = this._keybindingService.lookupKeybindings(action.id);
if (opts.length > 0) {
return opts[0]; // only take the first one
const [kb] = this._keybindingService.lookupKeybindings(action.id);
if (kb) {
return kb;
}
return null;
}

View File

@@ -63,7 +63,7 @@ export function loadReleaseNotes(accessor: ServicesAccessor, version: string): T
const patchKeybindings = (text: string): string => {
const kb = (match: string, kb: string) => {
const keybinding = keybindingService.lookupKeybindings(kb)[0];
const [keybinding] = keybindingService.lookupKeybindings(kb);
if (!keybinding) {
return unassigned;

View File

@@ -412,7 +412,7 @@ export class WalkThroughPart extends BaseEditor {
private expandMacros(input: string) {
return input.replace(/kb\(([a-z.\d\-]+)\)/gi, (match: string, kb: string) => {
const keybinding = this.keybindingService.lookupKeybindings(kb)[0];
const [keybinding] = this.keybindingService.lookupKeybindings(kb);
const shortcut = keybinding ? this.keybindingService.getLabelFor(keybinding) : UNBOUND_COMMAND;
return `<span class="shortcut">${shortcut}</span>`;
});
@@ -422,7 +422,7 @@ export class WalkThroughPart extends BaseEditor {
const keys = this.content.querySelectorAll('.shortcut[data-command]');
Array.prototype.forEach.call(keys, (key: Element) => {
const command = key.getAttribute('data-command');
const keybinding = command && this.keybindingService.lookupKeybindings(command)[0];
const [keybinding] = command && this.keybindingService.lookupKeybindings(command);
const label = keybinding ? this.keybindingService.getLabelFor(keybinding) : UNBOUND_COMMAND;
key.appendChild(document.createTextNode(label));
});