Skip to content

Commit

Permalink
Mark only those commands ran using quick menu as recent
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>

Fix tests

Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>

Remove tests for recent commands

Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>

Revert "Fix tests"

This reverts commit 0554e1a.

Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>
  • Loading branch information
dsseng committed Apr 13, 2020
1 parent cb3db2a commit a76d705
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 67 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/browser/quick-open/quick-command-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
63 changes: 0 additions & 63 deletions packages/core/src/common/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/common/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)})` : '';
Expand Down

0 comments on commit a76d705

Please sign in to comment.