提交 719ac741 编写于 作者: J Johannes Rieken

fix #96970

上级 42f1a2f1
...@@ -9,12 +9,13 @@ import { IConstructorSignature2, createDecorator, BrandedService, ServicesAccess ...@@ -9,12 +9,13 @@ import { IConstructorSignature2, createDecorator, BrandedService, ServicesAccess
import { IKeybindings, KeybindingsRegistry, IKeybindingRule } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { IKeybindings, KeybindingsRegistry, IKeybindingRule } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ContextKeyExpr, IContextKeyService, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey'; import { ContextKeyExpr, IContextKeyService, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService, CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands'; import { ICommandService, CommandsRegistry, ICommandHandlerDescription } from 'vs/platform/commands/common/commands';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { IDisposable, DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event'; import { Event, Emitter } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
import { ThemeIcon } from 'vs/platform/theme/common/themeService'; import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { UriDto } from 'vs/base/common/types'; import { UriDto } from 'vs/base/common/types';
import { Iterable } from 'vs/base/common/iterator'; import { Iterable } from 'vs/base/common/iterator';
import { LinkedList } from 'vs/base/common/linkedList';
export interface ILocalizedString { export interface ILocalizedString {
value: string; value: string;
...@@ -172,7 +173,7 @@ export interface IMenuRegistry { ...@@ -172,7 +173,7 @@ export interface IMenuRegistry {
export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry { export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
private readonly _commands = new Map<string, ICommandAction>(); private readonly _commands = new Map<string, ICommandAction>();
private readonly _menuItems = new Map<MenuId, Array<IMenuItem | ISubmenuItem>>(); private readonly _menuItems = new Map<MenuId, LinkedList<IMenuItem | ISubmenuItem>>();
private readonly _onDidChangeMenu = new Emitter<IMenuRegistryChangeEvent>(); private readonly _onDidChangeMenu = new Emitter<IMenuRegistryChangeEvent>();
readonly onDidChangeMenu: Event<IMenuRegistryChangeEvent> = this._onDidChangeMenu.event; readonly onDidChangeMenu: Event<IMenuRegistryChangeEvent> = this._onDidChangeMenu.event;
...@@ -190,8 +191,7 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry { ...@@ -190,8 +191,7 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
this._commands.set(command.id, command); this._commands.set(command.id, command);
} }
this._onDidChangeMenu.fire(this._commandPaletteChangeEvent); this._onDidChangeMenu.fire(this._commandPaletteChangeEvent);
return { return toDisposable(() => {
dispose: () => {
let didChange = false; let didChange = false;
for (const command of commands) { for (const command of commands) {
didChange = this._commands.delete(command.id) || didChange; didChange = this._commands.delete(command.id) || didChange;
...@@ -199,8 +199,7 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry { ...@@ -199,8 +199,7 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
if (didChange) { if (didChange) {
this._onDidChangeMenu.fire(this._commandPaletteChangeEvent); this._onDidChangeMenu.fire(this._commandPaletteChangeEvent);
} }
} });
};
} }
getCommand(id: string): ICommandAction | undefined { getCommand(id: string): ICommandAction | undefined {
...@@ -220,39 +219,38 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry { ...@@ -220,39 +219,38 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
appendMenuItems(items: Iterable<{ id: MenuId, item: IMenuItem | ISubmenuItem }>): IDisposable { appendMenuItems(items: Iterable<{ id: MenuId, item: IMenuItem | ISubmenuItem }>): IDisposable {
const changedIds = new Set<MenuId>(); const changedIds = new Set<MenuId>();
const toRemove = new LinkedList<Function>();
for (const { id, item } of items) { for (const { id, item } of items) {
let array = this._menuItems.get(id); let list = this._menuItems.get(id);
if (!array) { if (!list) {
array = [item]; list = new LinkedList();
this._menuItems.set(id, array); this._menuItems.set(id, list);
} else {
array.push(item);
} }
toRemove.push(list.push(item));
changedIds.add(id); changedIds.add(id);
} }
this._onDidChangeMenu.fire(changedIds); this._onDidChangeMenu.fire(changedIds);
return { return toDisposable(() => {
dispose: () => { if (toRemove.size > 0) {
const changedIds = new Set<MenuId>(); for (let fn of toRemove) {
for (const { id, item } of items) { fn();
const array = this._menuItems.get(id);
const idx = array?.indexOf(item) ?? -1;
if (idx >= 0) {
array!.splice(idx, 1);
changedIds.add(id);
}
} }
this._onDidChangeMenu.fire(changedIds); this._onDidChangeMenu.fire(changedIds);
toRemove.clear();
} }
}; });
} }
getMenuItems(id: MenuId): Array<IMenuItem | ISubmenuItem> { getMenuItems(id: MenuId): Array<IMenuItem | ISubmenuItem> {
const result = (this._menuItems.get(id) || []).slice(0); let result: Array<IMenuItem | ISubmenuItem>;
if (this._menuItems.has(id)) {
result = [...this._menuItems.get(id)!];
} else {
result = [];
}
if (id === MenuId.CommandPalette) { if (id === MenuId.CommandPalette) {
// CommandPalette is special because it shows // CommandPalette is special because it shows
// all commands by default // all commands by default
...@@ -264,12 +262,12 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry { ...@@ -264,12 +262,12 @@ export const MenuRegistry: IMenuRegistry = new class implements IMenuRegistry {
private _appendImplicitItems(result: Array<IMenuItem | ISubmenuItem>) { private _appendImplicitItems(result: Array<IMenuItem | ISubmenuItem>) {
const set = new Set<string>(); const set = new Set<string>();
const temp = result.filter(item => { return isIMenuItem(item); }) as IMenuItem[]; for (const item of result) {
if (isIMenuItem(item)) {
for (const { command, alt } of temp) { set.add(item.command.id);
set.add(command.id); if (item.alt) {
if (alt) { set.add(item.alt.id);
set.add(alt.id); }
} }
} }
this._commands.forEach((command, id) => { this._commands.forEach((command, id) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册