Skip to content

Commit

Permalink
feat: encapsulate common workspace Actions API based on moanco api
Browse files Browse the repository at this point in the history
  • Loading branch information
wewoor committed May 17, 2021
1 parent cd82228 commit 1d49058
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/monaco/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { ContextKeyExpr } from 'monaco-editor/esm/vs/platform/contextkey/common/
import { KeybindingsRegistry } from 'monaco-editor/esm/vs/platform/keybinding/common/keybindingsRegistry';
import { ServicesAccessor } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation';
import { CommandsRegistry } from 'monaco-editor/esm/vs/platform/commands/common/commands';
import {
MenuRegistry,
MenuId,
} from 'monaco-editor/esm/vs/platform/actions/common/actions';

export enum KeybindingWeight {
EditorCore = 0,
Expand Down Expand Up @@ -36,6 +40,31 @@ export function registerAction2(ctor: { new (): Action2 }): IDisposable {
})
);

// menu
if (Array.isArray(menu)) {
disposables.add(
MenuRegistry.appendMenuItems(
menu.map((item) => ({
id: item.id,
item: { command, ...item },
}))
)
);
} else if (menu) {
disposables.add(
MenuRegistry.appendMenuItem(menu.id, { command, ...menu })
);
}
if (f1) {
disposables.add(
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
command,
when: command.precondition,
})
);
disposables.add(MenuRegistry.addCommand(command));
}

// keybinding
if (Array.isArray(keybinding)) {
for (const item of keybinding) {
Expand Down

0 comments on commit 1d49058

Please sign in to comment.