提交 b5a2ab1e 编写于 作者: B Benjamin Pasero

quick access - allow to search by command alias but not show it

上级 e6872f46
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AbstractCommandsQuickAccessProvider, ICommandQuickPick } from 'vs/platform/quickinput/browser/commandsQuickAccess';
import { AbstractCommandsQuickAccessProvider, ICommandQuickPick, ICommandsQuickAccessOptions } from 'vs/platform/quickinput/browser/commandsQuickAccess';
import { IEditor } from 'vs/editor/common/editorCommon';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
......@@ -11,24 +11,17 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ICommandService } from 'vs/platform/commands/common/commands';
export interface IEditorCommandsQuickAccessOptions {
alias: {
enable: boolean;
verify: boolean;
}
}
export abstract class AbstractEditorCommandsQuickAccessProvider extends AbstractCommandsQuickAccessProvider {
constructor(
options: ICommandsQuickAccessOptions,
instantiationService: IInstantiationService,
keybindingService: IKeybindingService,
commandService: ICommandService,
telemetryService: ITelemetryService,
notificationService: INotificationService,
private options?: IEditorCommandsQuickAccessOptions
notificationService: INotificationService
) {
super(instantiationService, keybindingService, commandService, telemetryService, notificationService);
super(options, instantiationService, keybindingService, commandService, telemetryService, notificationService);
}
/**
......@@ -44,28 +37,13 @@ export abstract class AbstractEditorCommandsQuickAccessProvider extends Abstract
const editorCommandPicks: ICommandQuickPick[] = [];
for (const editorAction of activeTextEditorControl.getSupportedActions()) {
const label = editorAction.label || editorAction.id;
const alias: string | undefined = this.verifyAlias(editorAction.alias, label, editorAction.id);
editorCommandPicks.push({
commandId: editorAction.id,
label,
detail: alias
commandAlias: editorAction.alias,
label: editorAction.label || editorAction.id,
});
}
return editorCommandPicks;
}
protected verifyAlias(alias: string | undefined, label: string, commandId: string): string | undefined {
if (this.options?.alias.verify && alias && alias !== label) {
console.warn(`Command alias '${label}' and label '${alias}' differ (${commandId})`);
}
if (!this.options?.alias.enable) {
return undefined; // we unset the alias if it is not enabled
}
return alias;
}
}
......@@ -29,7 +29,7 @@ export class StandaloneCommandsQuickAccessProvider extends AbstractEditorCommand
@ITelemetryService telemetryService: ITelemetryService,
@INotificationService notificationService: INotificationService
) {
super(instantiationService, keybindingService, commandService, telemetryService, notificationService);
super({ showAlias: false }, instantiationService, keybindingService, commandService, telemetryService, notificationService);
}
protected async getCommandPicks(): Promise<Array<ICommandQuickPick>> {
......
......@@ -27,6 +27,11 @@ import { timeout } from 'vs/base/common/async';
export interface ICommandQuickPick extends IPickerQuickAccessItem {
commandId: string;
commandAlias: string | undefined;
}
export interface ICommandsQuickAccessOptions {
showAlias: boolean;
}
export abstract class AbstractCommandsQuickAccessProvider extends PickerQuickAccessProvider<ICommandQuickPick> implements IDisposable {
......@@ -40,6 +45,7 @@ export abstract class AbstractCommandsQuickAccessProvider extends PickerQuickAcc
private readonly commandsHistory = this.disposables.add(this.instantiationService.createInstance(CommandsHistory));
constructor(
private options: ICommandsQuickAccessOptions,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@ICommandService private readonly commandService: ICommandService,
......@@ -58,10 +64,14 @@ export abstract class AbstractCommandsQuickAccessProvider extends PickerQuickAcc
const filteredCommandPicks: ICommandQuickPick[] = [];
for (const commandPick of allCommandPicks) {
const labelHighlights = withNullAsUndefined(AbstractCommandsQuickAccessProvider.WORD_FILTER(filter, commandPick.label));
const detailHighlights = commandPick.detail ? withNullAsUndefined(AbstractCommandsQuickAccessProvider.WORD_FILTER(filter, commandPick.detail)) : undefined;
const aliasHighlights = commandPick.commandAlias ? withNullAsUndefined(AbstractCommandsQuickAccessProvider.WORD_FILTER(filter, commandPick.commandAlias)) : undefined;
if (labelHighlights || aliasHighlights) {
commandPick.highlights = {
label: labelHighlights,
detail: this.options.showAlias ? aliasHighlights : undefined
};
if (labelHighlights || detailHighlights) {
commandPick.highlights = { label: labelHighlights, detail: detailHighlights };
filteredCommandPicks.push(commandPick);
}
}
......@@ -128,6 +138,7 @@ export abstract class AbstractCommandsQuickAccessProvider extends PickerQuickAcc
commandPicks.push({
...commandPick,
ariaLabel,
detail: this.options.showAlias ? commandPick.commandAlias : undefined,
keybinding,
accept: async () => {
......
......@@ -46,16 +46,7 @@ export class CommandsQuickAccessProvider extends AbstractEditorCommandsQuickAcce
@ITelemetryService telemetryService: ITelemetryService,
@INotificationService notificationService: INotificationService
) {
super(instantiationService, keybindingService, commandService, telemetryService, notificationService, {
alias: {
// Show alias only when not running in english
enable: !Language.isDefaultVariant(),
// Print a warning if the alias does not match the english label
verify: !environmentService.isBuilt && Language.isDefaultVariant(),
}
});
super({ showAlias: !Language.isDefaultVariant() }, instantiationService, keybindingService, commandService, telemetryService, notificationService);
}
protected async getCommandPicks(disposables: DisposableStore, token: CancellationToken): Promise<Array<ICommandQuickPick>> {
......@@ -96,16 +87,16 @@ export class CommandsQuickAccessProvider extends AbstractEditorCommandsQuickAcce
}
// Alias
const aliasTitle = typeof action.item.title !== 'string' ? action.item.title.original : undefined;
const aliasLabel = typeof action.item.title !== 'string' ? action.item.title.original : undefined;
const aliasCategory = (category && action.item.category && typeof action.item.category !== 'string') ? action.item.category.original : undefined;
let alias = this.verifyAlias((aliasTitle && category) ?
aliasCategory ? `${aliasCategory}: ${aliasTitle}` : `${category}: ${aliasTitle}` :
aliasTitle, label, action.item.id);
const commandAlias = (aliasLabel && category) ?
aliasCategory ? `${aliasCategory}: ${aliasLabel}` : `${category}: ${aliasLabel}` :
aliasLabel;
globalCommandPicks.push({
commandId: action.item.id,
label,
detail: alias
commandAlias,
label
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册