diff --git a/packages/core/src/browser/quick-open/quick-command-service.ts b/packages/core/src/browser/quick-open/quick-command-service.ts index 270c9ecce97c4..4c74088b30edf 100644 --- a/packages/core/src/browser/quick-open/quick-command-service.ts +++ b/packages/core/src/browser/quick-open/quick-command-service.ts @@ -248,6 +248,8 @@ export class CommandQuickOpenItem extends QuickOpenGroupItem { // reset focus on the previously active element. this.activeElement.focus({ preventScroll: true }); this.commands.executeCommand(this.command.id); + + this.commands.addRecentCommand(this.command); }, 50); return true; } diff --git a/packages/core/src/common/command.spec.ts b/packages/core/src/common/command.spec.ts index 4f15c463f5117..f1f9e2bb1a056 100644 --- a/packages/core/src/common/command.spec.ts +++ b/packages/core/src/common/command.spec.ts @@ -37,15 +37,15 @@ describe('Commands', () => { expect('abc').equals(result); }); - it('should execute a given command, and add it to recently used', async () => { + it('should add command to recently used', async () => { const commandId = 'stub'; const command: Command = { id: commandId }; commandRegistry.registerCommand(command, new StubCommandHandler()); - await commandRegistry.executeCommand(commandId); + commandRegistry.addRecentCommand(command); expect(commandRegistry.recent.length).equal(1); }); - it('should execute multiple commands, and add them to recently used in the order they were used', async () => { + it('should add multiple commands to recently used in the order they were used', async () => { const commandIds = ['a', 'b', 'c']; const commands: Command[] = [ { id: commandIds[0] }, @@ -59,9 +59,9 @@ describe('Commands', () => { }); // Execute order c, b, a. - await commandRegistry.executeCommand(commandIds[2]); - await commandRegistry.executeCommand(commandIds[1]); - await commandRegistry.executeCommand(commandIds[0]); + commandRegistry.addRecentCommand(commands[2]); + commandRegistry.addRecentCommand(commands[1]); + commandRegistry.addRecentCommand(commands[0]); // Expect recently used to be a, b, c. const result: Command[] = commandRegistry.recent; @@ -72,7 +72,7 @@ describe('Commands', () => { expect(result[2].id).equal(commandIds[2]); }); - it('should execute a command that\'s already been executed, and add it to the top of the most recently used', async () => { + it('should add a previously used command to the top of the most recently used', async () => { const commandIds = ['a', 'b', 'c']; const commands: Command[] = [ { id: commandIds[0] }, @@ -86,10 +86,10 @@ describe('Commands', () => { }); // Execute order a, b, c, a. - await commandRegistry.executeCommand(commandIds[0]); - await commandRegistry.executeCommand(commandIds[1]); - await commandRegistry.executeCommand(commandIds[2]); - await commandRegistry.executeCommand(commandIds[0]); + commandRegistry.addRecentCommand(commands[0]); + commandRegistry.addRecentCommand(commands[1]); + commandRegistry.addRecentCommand(commands[2]); + commandRegistry.addRecentCommand(commands[0]); // Expect recently used to be a, b, c. const result: Command[] = commandRegistry.recent; @@ -114,9 +114,9 @@ describe('Commands', () => { }); // Execute each command. - await commandRegistry.executeCommand(commandIds[0]); - await commandRegistry.executeCommand(commandIds[1]); - await commandRegistry.executeCommand(commandIds[2]); + commandRegistry.addRecentCommand(commands[0]); + commandRegistry.addRecentCommand(commands[1]); + commandRegistry.addRecentCommand(commands[2]); // Clear the list of recently used commands. commandRegistry.clearCommandHistory(); diff --git a/packages/core/src/common/command.ts b/packages/core/src/common/command.ts index c4d53c74332f5..e1f5987709384 100644 --- a/packages/core/src/common/command.ts +++ b/packages/core/src/common/command.ts @@ -289,10 +289,6 @@ 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)})` : '';