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

core: fix recently used quick-commands #7562

Merged
merged 1 commit into from
Apr 14, 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
8 changes: 4 additions & 4 deletions packages/core/src/browser/quick-open/quick-command-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export class QuickCommandService implements QuickOpenModel, QuickOpenHandler {
this.commands,
this.keybindings,
{
groupLabel: recent.length <= 0 ? '' : index === 0 ? 'other commands' : '',
showBorder: recent.length <= 0 ? false : index === 0 ? true : false,
groupLabel: recent.length > 0 && index === 0 ? 'other commands' : '',
showBorder: recent.length > 0 && index === 0 ? true : false,
}
)
),
Expand Down Expand Up @@ -160,13 +160,13 @@ export class QuickCommandService implements QuickOpenModel, QuickOpenHandler {

/**
* Normalizes a list of commands.
* Normalization includes obtaining commands that have labels and are visible.
* Normalization includes obtaining commands that have labels, are visible, and are enabled.
*
* @param commands the list of commands.
* @returns the list of normalized commands.
*/
private normalize(commands: Command[]): Command[] {
return commands.filter((a: Command) => a.label && this.commands.isVisible(a.id));
return commands.filter((a: Command) => a.label && (this.commands.isVisible(a.id) && this.commands.isEnabled(a.id)));
}

/**
Expand Down
42 changes: 42 additions & 0 deletions packages/core/src/common/command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,48 @@ describe('Commands', () => {
expect(commandRegistry.getAllHandlers('id').length).to.be.equal(2);
});

describe('compareCommands', () => {

it('should sort command \'a\' before command \'b\' with categories', () => {
const a: Command = { id: 'a', category: 'a', label: 'a' };
const b: Command = { id: 'b', category: 'b', label: 'b' };
expect(Command.compareCommands(a, b)).to.equal(-1);
expect(Command.compareCommands(b, a)).to.equal(1);
});

it('should sort command \'a\' before command \'b\' without categories', () => {
const a: Command = { id: 'a', label: 'a' };
const b: Command = { id: 'b', label: 'b' };
expect(Command.compareCommands(a, b)).to.equal(-1);
expect(Command.compareCommands(b, a)).to.equal(1);
});

it('should sort command \'a\' before command \'b\' with mix-match categories', () => {
const a: Command = { id: 'a', category: 'a', label: 'a' };
const b: Command = { id: 'b', label: 'a' };
expect(Command.compareCommands(a, b)).to.equal(1);
expect(Command.compareCommands(b, a)).to.equal(-1);
});

it('should sort irregardless of casing', () => {
const lowercase: Command = { id: 'a', label: 'a' };
const uppercase: Command = { id: 'a', label: 'A' };
expect(Command.compareCommands(lowercase, uppercase)).to.equal(0);
});

it('should not sort if commands are equal', () => {
const a: Command = { id: 'a', label: 'a' };
expect(Command.compareCommands(a, a)).to.equal(0);
});

it('should not sort commands without labels', () => {
const a: Command = { id: 'a' };
const b: Command = { id: 'b' };
expect(Command.compareCommands(a, b)).to.equal(0);
});

});

});

class EmptyContributionProvider implements ContributionProvider<CommandContribution> {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/common/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export namespace Command {
/** Comparator function for when sorting commands */
export function compareCommands(a: Command, b: Command): number {
if (a.label && b.label) {
const aCommand = (a.category) ? a.category + a.label : a.label;
const bCommand = (b.category) ? b.category + b.label : b.label;
const aCommand = (a.category ? `${a.category}: ${a.label}` : a.label).toLowerCase();
const bCommand = (b.category ? `${b.category}: ${b.label}` : b.label).toLowerCase();
return (aCommand).localeCompare(bCommand);
} else {
return 0;
Expand Down