From a76d7054a37d11807edb1edb2987c8c8acf7c64f Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Sun, 12 Apr 2020 15:19:15 +0300 Subject: [PATCH] Mark only those commands ran using quick menu as recent Signed-off-by: Dmitry Sharshakov Fix tests Signed-off-by: Dmitry Sharshakov Remove tests for recent commands Signed-off-by: Dmitry Sharshakov Revert "Fix tests" This reverts commit 0554e1a58609cc5fba2df30f8e5dbb5ae9b32159. Signed-off-by: Dmitry Sharshakov --- .../quick-open/quick-command-service.ts | 4 ++ packages/core/src/common/command.spec.ts | 63 ------------------- packages/core/src/common/command.ts | 4 -- 3 files changed, 4 insertions(+), 67 deletions(-) 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..f72c7a9ef8b97 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,10 @@ export class CommandQuickOpenItem extends QuickOpenGroupItem { // reset focus on the previously active element. this.activeElement.focus({ preventScroll: true }); this.commands.executeCommand(this.command.id); + + if (this.command) { + 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..70ed8dea48ddc 100644 --- a/packages/core/src/common/command.spec.ts +++ b/packages/core/src/common/command.spec.ts @@ -37,69 +37,6 @@ describe('Commands', () => { expect('abc').equals(result); }); - it('should execute a given command, and add it to recently used', async () => { - const commandId = 'stub'; - const command: Command = { id: commandId }; - commandRegistry.registerCommand(command, new StubCommandHandler()); - await commandRegistry.executeCommand(commandId); - expect(commandRegistry.recent.length).equal(1); - }); - - it('should execute multiple commands, and add them to recently used in the order they were used', async () => { - const commandIds = ['a', 'b', 'c']; - const commands: Command[] = [ - { id: commandIds[0] }, - { id: commandIds[1] }, - { id: commandIds[2] }, - ]; - - // Register each command. - commands.forEach((c: Command) => { - commandRegistry.registerCommand(c, new StubCommandHandler()); - }); - - // Execute order c, b, a. - await commandRegistry.executeCommand(commandIds[2]); - await commandRegistry.executeCommand(commandIds[1]); - await commandRegistry.executeCommand(commandIds[0]); - - // Expect recently used to be a, b, c. - const result: Command[] = commandRegistry.recent; - - expect(result.length).equal(3); - expect(result[0].id).equal(commandIds[0]); - expect(result[1].id).equal(commandIds[1]); - 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 () => { - const commandIds = ['a', 'b', 'c']; - const commands: Command[] = [ - { id: commandIds[0] }, - { id: commandIds[1] }, - { id: commandIds[2] }, - ]; - - // Register each command. - commands.forEach((c: Command) => { - commandRegistry.registerCommand(c, new StubCommandHandler()); - }); - - // 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]); - - // Expect recently used to be a, b, c. - const result: Command[] = commandRegistry.recent; - - expect(result.length).equal(3); - expect(result[0].id).equal(commandIds[0]); - expect(result[1].id).equal(commandIds[2]); - expect(result[2].id).equal(commandIds[1]); - }); - it('should clear the recently used command history', async () => { const commandIds = ['a', 'b', 'c']; const commands: Command[] = [ 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)})` : '';