-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Change shortcuts #1350
Comments
I couldn't find a better way to do this, the only one I could find is patching the function that registers those commands: import {Command} from 'monaco-editor/esm/vs/editor/browser/editorExtensions.js';
const _register = Command.prototype.register;
Command.prototype.register = function () {
const patcher = patches[this.id];
if ( patcher && patcher ( this ) === false ) return; // Disabled
return _register.apply ( this, arguments );
}; |
Works like a charm to disable a shorcut. E.g. const patches = {
'editor.action.triggerSuggest': () => false,
} But how do I add another shorcut to this command instead? |
This worked for me, instead of the method above. function changeCommandKeybinding(editor, id, keybinding) {
editor._standaloneKeybindingService.addDynamicKeybinding('-' + id);
editor._standaloneKeybindingService.addDynamicKeybinding(id, keybinding);
}
changeCommandKeybinding(
editor,
'editor.action.triggerSuggest',
monaco.KeyMod.CtrlCmd | monaco.KeyCode.US_SLASH
); |
Btw if anyone is looking for the names of the builtin commands, I modified the code from the OP to do this: function (search) {
const _register = Command.prototype.register;
Command.prototype.register = function () {
if (!search || this.id.toLowerCase().indexOf(search.toLowerCase()) > -1)
console.log(this.id);
return _register.apply(this, arguments);
};
} I couldn't find a list of commands anywhere, and didn't feel like taking guesses all night. |
Let's track in #102 |
monaco-editor version: 0.16.0
What's the recommend way to change a shortcut assigned to a default command?
Say I want to bind
ctrl+alt+r
to thetoggleFindRegex
command rather than the default one, how should I go about it?The text was updated successfully, but these errors were encountered: