Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I customize context menu? I want to delete 'Go to definition' and others,and add my own meun. #1280

Open
sighWang opened this issue Jan 22, 2019 · 5 comments
Labels
contextmenu feature-request Request for new features or functionality
Milestone

Comments

@sighWang
Copy link

I have use addAction add 'add Commont', and I don't want others.How can I do?
image

@alexdima
Copy link
Member

We don't offer API to accomplish this. You could reach into the menu registrations and remove them require('vs/platform/actions/common/actions').MenuRegistry._menuItems

@alexdima alexdima changed the title How can I customize content menu? I want to delete 'Go to definition' and others,and add my own meun. How can I customize context menu? I want to delete 'Go to definition' and others,and add my own meun. Dec 12, 2019
@alexdima alexdima added contextmenu feature-request Request for new features or functionality labels Dec 12, 2019
@alexdima alexdima added this to the Backlog milestone Dec 12, 2019
@softmarshmallow
Copy link

searching "monaco editor customize context menu" brought me here. I'm aware this is not the right place, but can you share how you added "Add comment"? kindly share us some code :)

Thanks!

@spahnke
Copy link
Contributor

spahnke commented Oct 8, 2021

See https://microsoft.github.io/monaco-editor/playground.html#interacting-with-the-editor-adding-an-action-to-an-editor-instance

@AlexandreAtErgosign
Copy link

AlexandreAtErgosign commented Nov 22, 2023

See https://microsoft.github.io/monaco-editor/playground.html#interacting-with-the-editor-adding-an-action-to-an-editor-instance

The example is good. Is there a way to display which group are used in the context menu? From the doc:

The context menu of the editor has these default:

  • navigation - The navigation group comes first in all cases.
  • 1_modification - This group comes next and contains commands that modify your code.
  • 9_cutcopypaste - The last default group with the basic editing commands.

Is there a way to find the other context menu group such as the command palette group?

@codebykat
Copy link

Since #1567 is locked, and this took me absolute AGES to figure out, I wanted to share the latest workaround for removing unwanted context menu items. I didn't like the CSS hack, it seemed too fragile and I didn't know what other effects disabling the shadow DOM might have. But none of the previous hacks worked. Instead I found a solution involving monkey-patching the internals of the context menu, as suggested here:

  const removableIds = [ 'editor.action.changeAll', 'editor.action.quickCommand' ];
  const contextmenu = this.editor.getContribution('editor.contrib.contextmenu');
  const realMethod = contextmenu._getMenuActions;
  contextmenu._getMenuActions = function() {
    const items = realMethod.apply(contextmenu, arguments);
    return items.filter(function(item) {
      return ! removableIds.includes(item.id);
    });
  };

Unfortunately it does run on every click of the context menu, but c'est la vie... hope this helps someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contextmenu feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

6 participants