-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Remove 'context menu' items (not CSS) #1567
Comments
|
|
+1. The context menu has items like "Go to definition", "Peek definition", etc., which don't work. I'd like to remove them. |
You can remove menu items from the context menu like this: import * as actions from "monaco-editor/esm/vs/platform/actions/common/actions";
let menus = actions.MenuRegistry._menuItems;
let contextMenuEntry = [...menus].find(entry => entry[0]._debugName == "EditorContext");
let contextMenuLinks = contextMenuEntry[1];
let removableIds = ["editor.action.goToTypeDefinition"];
let removeById = (list, ids) => {
let node = list._first;
do {
let shouldRemove = ids.includes(node.element?.command?.id);
if (shouldRemove) { list._remove(node) }
} while ((node = node.next));
};
removeById(contextMenuLinks, removableIds); Further Reading
|
@KyleMit You just saved me so many hours of aggravation, thank you for that walkthrough ❤️ |
Did something change in later versions that would have affected the solution by @KyleMit? I'm using 0.27.0 and |
Having the same issue too |
Same issue persists |
This is the current fix for this issue: https://stackoverflow.com/a/73858820/11121992 A hack for sure |
This worked for me to remove everything (Peek submenu too)
|
actions.MenuRegistry._menuItems gives an empty map on newer versions like mentioned here: #1567 (comment) |
This approach got me most of the way there, I ended up posting my modified solution. https://stackoverflow.com/a/75149195/4325849 |
@kylewith solution no longer works in the newer Monaco versions. An updated version would be: let menus = actions.MenuRegistry._menuItems as Map<any, any>
const contextMenuEntry = Array.from(menus, ([key, value]) => ({key, value})).find(entry => entry.key.id == 'EditorContext')
let removableIds = ["editor.action.clipboardCopyAction", "editor.action.clipboardPasteAction"]
let removeById = (list, ids) => {
let node = list._first
do {
let shouldRemove = ids.includes(node.element?.command?.id)
if (shouldRemove) {
list._remove(node)
}
} while ((node = node.next))
}
removeById(contextMenuEntry.value, removableIds) |
This comment was marked as outdated.
This comment was marked as outdated.
Duplicate of #1280 |
How can we remove items from the context menu? Is there a native mode supported by Monaco?
monaco-editor version: 0.17.1 (latest)
Browser: Google Chrome 76
OS: Windows 10
The text was updated successfully, but these errors were encountered: