monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] monaco.editor.addEditorAction() doesn't add actions to the command palette

Open DavidSeptimus opened this issue 4 months ago • 3 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [x] Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.53.0#XQAAAAJxAQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscwzeuYHbpo6KbnrhSaY2QPzx4Q1upoCGK8v_c64CL466xwXvBuPPJwqjrPtSNPK6lDtG7P9m4YQa5xNAk44cdnJqyI8TZl6DGZZUFqmc0OpXNjxWjGNCEg86fg6kyoiwTrJeKBnoxEXTxCNhVt6pLDLj8Q268drIebyDMs1ye0jxwn5n7DMndjdIE-LodUf7fn5TkjkIsoP53p4U9rxoEQ1u8tnU0lyLpjEOth2wPUs0gDVjC32TB1V-4kLmkL5HXHgWJ5DyQ2qKuhhdl0qrue29y7ogIz6y0H6ksRS2HL-qpb_-rXYmA

Monaco Editor Playground Code

monaco.editor.addEditorAction({
	id: "my-unique-id",
	label: "My Label!!!",
	keybindings: [
		monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyH		
	],
	run: function (ed) {
		alert("i'm running => " + ed.getPosition());
	},
});

var editorInstance = monaco.editor.create(document.getElementById("container"));

Reproduction Steps

  1. Register an action globally with monaco.editor.addEditorAction()
  2. Open the command palette and search for an action called "My Label!!!" -- 0 results.
  3. Press cmd+h -- the action triggers and shows an alert.

Actual (Problematic) Behavior

The action gets registered in the command/keybinding registries, but isn't accessible via the command palette.

Expected Behavior

The globally registered action should be accessible via the command palette.

Additional Context

Calling addAction() on a StandaloneCodeEditor instance creates a new InternalEditorAction and stores it in this._actions (inherited from CodeEditorWidget), which is the source for the list of available actions available in the command palette. monaco.editor.AddEditorAction() doesn't bother creating the action anywhere, so CodeEditorWidget has no way of knowing that the action should be shown.

DavidSeptimus avatar Sep 14 '25 02:09 DavidSeptimus

In my own environment, I patched it to store the original descriptor in a static field on CodeEditorWidget and then create the InternalEditorActions in CodeEditorWidgets constructor just after it creates the actions from EditorExtensionsRegistry.

DavidSeptimus avatar Sep 14 '25 12:09 DavidSeptimus

Expected Behavior The globally registered action should be accessible via the command palette.

Why would you expect this? I don't think it ever worked like this for this method of registering commands.

hediet avatar Sep 22 '25 23:09 hediet

I'm not claiming it ever did, but we're talking about actions rather than commands. monaco.editor.addCommand() exists for that purpose. Aren't actions supposed to be user discoverable via UI? As it is, actions registered this way are visible in the context menu (given a supplied contextMenuGroupId), so having them not show up in the command palette seems like an oversight.

I would expect monaco.editor.addEditorAction() and StandaloneCodeEditor.addAction() to be local/global analogues, especially given they both share a descriptor interface (IActionDescriptor) and there are already separate local/global addCommand() APIs.

DavidSeptimus avatar Sep 22 '25 23:09 DavidSeptimus