Skip to content

Commit f37989b

Browse files
committed
feat: access the CommandPalette globally
1 parent 1a627d5 commit f37989b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/monaco/gotoLineAction.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'reflect-metadata';
2+
import { QuickCommandNLS } from 'monaco-editor/esm/vs/editor/common/standaloneStrings';
3+
import { monacoService } from './monacoService';
4+
import { IQuickInputService } from 'monaco-editor/esm/vs/platform/quickinput/common/quickInput';
5+
import * as monaco from 'monaco-editor';
6+
import { AbstractEditorCommandsQuickAccessProvider } from 'monaco-editor/esm/vs/editor/contrib/quickAccess/commandsQuickAccess';
7+
import { Action } from 'monaco-editor/esm/vs/base/common/actions';
8+
import { EditorContextKeys } from 'monaco-editor/esm/vs/editor/common/editorContextKeys';
9+
import { CommandsRegistry } from 'monaco-editor/esm/vs/platform/commands/common/commands';
10+
import { singleton, container } from 'tsyringe';
11+
import { KeybindingWeight } from './common';
12+
13+
@singleton()
14+
export class GotoLineAction extends Action {
15+
static ID = 'editor.action.quickCommand';
16+
private readonly quickInputService: IQuickInputService;
17+
18+
constructor() {
19+
super({
20+
id: GotoLineAction.ID,
21+
label: QuickCommandNLS.quickCommandActionLabel,
22+
alias: 'Command Palette',
23+
precondition: undefined,
24+
kbOpts: {
25+
kbExpr: EditorContextKeys.focus,
26+
primary: monaco.KeyCode.F1,
27+
weight: KeybindingWeight.EditorContrib,
28+
},
29+
contextMenuOpts: {
30+
group: 'z_commands',
31+
order: 1,
32+
},
33+
});
34+
this.quickInputService = monacoService.services.get(IQuickInputService);
35+
}
36+
37+
run(): void {
38+
this.quickInputService.quickAccess.show(
39+
AbstractEditorCommandsQuickAccessProvider.PREFIX
40+
);
41+
}
42+
}
43+
44+
CommandsRegistry.registerCommand(GotoLineAction.ID, (serviceAccessor) => {
45+
const selectColorAction = container.resolve(GotoLineAction);
46+
selectColorAction.run();
47+
});

0 commit comments

Comments
 (0)