Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Sharshakov <[email protected]>
  • Loading branch information
dsseng committed Apr 12, 2020
1 parent 82555f6 commit 0554e1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/core/src/browser/quick-open/quick-command-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ export class QuickCommandService implements QuickOpenModel, QuickOpenHandler {
@inject(CorePreferences)
protected readonly corePreferences: CorePreferences;

protected recent: Command[] = [];
addRecentCommand(command: Command): void {
// If this command is in recent list, remove and append to the start
const index = this.recent.findIndex(c => Command.equals(command, c));
if (index >= 0) {
this.recent.splice(index, 1);
}

const limit: number = this.corePreferences['workbench.commandPalette.history'];

this.recent = [command, ...this.recent].slice(0, limit);
}

protected readonly contexts = new Map<string, string[]>();
pushCommandContext(commandId: string, when: string): Disposable {
const contexts = this.contexts.get(commandId) || [];
Expand Down Expand Up @@ -77,7 +90,8 @@ export class QuickCommandService implements QuickOpenModel, QuickOpenHandler {
{
groupLabel: index === 0 ? 'recently used' : '',
showBorder: false,
}
},
this
)
),
...other.map((command, index) =>
Expand All @@ -88,7 +102,8 @@ export class QuickCommandService implements QuickOpenModel, QuickOpenHandler {
{
groupLabel: recent.length <= 0 ? '' : index === 0 ? 'other commands' : '',
showBorder: recent.length <= 0 ? false : index === 0 ? true : false,
}
},
this
)
),
);
Expand All @@ -114,7 +129,7 @@ export class QuickCommandService implements QuickOpenModel, QuickOpenHandler {
private getCommands(): { recent: Command[], other: Command[] } {

// Get the list of recent commands.
const recentCommands: Command[] = this.commands.recent;
const recentCommands: Command[] = this.recent;

// Get the list of all valid commands.
const allCommands: Command[] = this.getValidCommands(this.commands.commands);
Expand Down Expand Up @@ -210,6 +225,7 @@ export class CommandQuickOpenItem extends QuickOpenGroupItem {
protected readonly commands: CommandRegistry,
protected readonly keybindings: KeybindingRegistry,
protected readonly commandOptions?: QuickOpenGroupItemOptions,
protected readonly quickCommand?: QuickCommandService
) {
super(commandOptions);
this.activeElement = window.document.activeElement as HTMLElement;
Expand Down Expand Up @@ -249,8 +265,8 @@ export class CommandQuickOpenItem extends QuickOpenGroupItem {
this.activeElement.focus({ preventScroll: true });
this.commands.executeCommand(this.command.id);

if (this.command) {
this.commands.addRecentCommand(this.command);
if (this.quickCommand) {
this.quickCommand.addRecentCommand(this.command);
}
}, 50);
return true;
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/common/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ export class CommandRegistry implements CommandService {
await this.fireWillExecuteCommand(commandId, args);
const result = await handler.execute(...args);
this.onDidExecuteCommandEmitter.fire({ commandId, args });
const command = this.getCommand(commandId);
if (command) {
this.addRecentCommand(command);
}
return result;
}
const argsMessage = args && args.length > 0 ? ` (args: ${JSON.stringify(args)})` : '';
Expand Down

0 comments on commit 0554e1a

Please sign in to comment.