Skip to content

Commit 1d49058

Browse files
committed
feat: encapsulate common workspace Actions API based on moanco api
1 parent cd82228 commit 1d49058

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/monaco/common.ts

+29
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { ContextKeyExpr } from 'monaco-editor/esm/vs/platform/contextkey/common/
66
import { KeybindingsRegistry } from 'monaco-editor/esm/vs/platform/keybinding/common/keybindingsRegistry';
77
import { ServicesAccessor } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation';
88
import { CommandsRegistry } from 'monaco-editor/esm/vs/platform/commands/common/commands';
9+
import {
10+
MenuRegistry,
11+
MenuId,
12+
} from 'monaco-editor/esm/vs/platform/actions/common/actions';
913

1014
export enum KeybindingWeight {
1115
EditorCore = 0,
@@ -36,6 +40,31 @@ export function registerAction2(ctor: { new (): Action2 }): IDisposable {
3640
})
3741
);
3842

43+
// menu
44+
if (Array.isArray(menu)) {
45+
disposables.add(
46+
MenuRegistry.appendMenuItems(
47+
menu.map((item) => ({
48+
id: item.id,
49+
item: { command, ...item },
50+
}))
51+
)
52+
);
53+
} else if (menu) {
54+
disposables.add(
55+
MenuRegistry.appendMenuItem(menu.id, { command, ...menu })
56+
);
57+
}
58+
if (f1) {
59+
disposables.add(
60+
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
61+
command,
62+
when: command.precondition,
63+
})
64+
);
65+
disposables.add(MenuRegistry.addCommand(command));
66+
}
67+
3968
// keybinding
4069
if (Array.isArray(keybinding)) {
4170
for (const item of keybinding) {

0 commit comments

Comments
 (0)