Skip to content

Commit 542e4bf

Browse files
committed
menu - move command palette special into registry
1 parent 7eb690f commit 542e4bf

3 files changed

Lines changed: 40 additions & 14 deletions

File tree

src/vs/platform/actions/common/actions.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,29 @@ export const MenuRegistry: IMenuRegistry = new class {
111111
}
112112

113113
getMenuItems({ id }: MenuId): IMenuItem[] {
114-
return this.menuItems[id] || [];
114+
const result = this.menuItems[id] || [];
115+
116+
if (id === MenuId.CommandPalette.id) {
117+
// CommandPalette is special because it shows
118+
// all commands by default
119+
this._appendImplicitItems(result);
120+
}
121+
return result;
122+
}
123+
124+
private _appendImplicitItems(result: IMenuItem[]) {
125+
const set = new Set<string>();
126+
for (const { command, alt } of result) {
127+
set.add(command.id);
128+
if (alt) {
129+
set.add(alt.id);
130+
}
131+
}
132+
for (let id in this.commands) {
133+
if (!set.has(id)) {
134+
result.push({ command: this.commands[id] });
135+
}
136+
}
115137
}
116138
};
117139

src/vs/platform/actions/common/menu.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import { localize } from 'vs/nls';
1212
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1313
import { MenuId, MenuRegistry, MenuItemAction, IMenu, IMenuItem } from 'vs/platform/actions/common/actions';
1414
import { ICommandService } from 'vs/platform/commands/common/commands';
15-
import { values } from 'vs/base/common/collections';
16-
import { index } from 'vs/base/common/arrays';
1715

1816
type MenuItemGroup = [string, IMenuItem[]];
1917

@@ -30,17 +28,7 @@ export class Menu implements IMenu {
3028
@IContextKeyService private _contextKeyService: IContextKeyService
3129
) {
3230
startupSignal.then(_ => {
33-
let menuItems = MenuRegistry.getMenuItems(id);
34-
35-
if (id === MenuId.CommandPalette) {
36-
const ids = index(menuItems, i => i.command.id);
37-
const commandMenuItems = values(MenuRegistry.commands)
38-
.filter(c => !ids[c.id])
39-
.map(command => ({ command }));
40-
41-
menuItems = [...menuItems, ...commandMenuItems];
42-
}
43-
31+
const menuItems = MenuRegistry.getMenuItems(id);
4432
const keysFilter = new Set<string>();
4533

4634
let group: MenuItemGroup;

src/vs/platform/actions/test/common/menuService.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,20 @@ suite('MenuService', function () {
186186
assert.equal(two.id, 'b');
187187
assert.equal(three.id, 'a');
188188
});
189+
190+
test('special MenuId palette', function () {
191+
192+
disposables.push(MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
193+
command: { id: 'a', title: 'Explicit' }
194+
}));
195+
196+
MenuRegistry.addCommand({ id: 'b', title: 'Implicit' });
197+
198+
const [first, second] = MenuRegistry.getMenuItems(MenuId.CommandPalette);
199+
assert.equal(first.command.id, 'a');
200+
assert.equal(first.command.title, 'Explicit');
201+
202+
assert.equal(second.command.id, 'b');
203+
assert.equal(second.command.title, 'Implicit');
204+
});
189205
});

0 commit comments

Comments
 (0)