Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark only those commands ran using quick menu as recent #7552

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 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,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;
}
Expand Down
28 changes: 14 additions & 14 deletions packages/core/src/common/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ describe('Commands', () => {
expect('abc').equals(result);
});

it('should execute a given command, and add it to recently used', async () => {
dsseng marked this conversation as resolved.
Show resolved Hide resolved
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] },
Expand All @@ -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;
Expand All @@ -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] },
Expand All @@ -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;
Expand All @@ -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();
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