Skip to content
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

Closed
fabiospampinato opened this issue Mar 8, 2019 · 5 comments
Closed

Change shortcuts #1350

fabiospampinato opened this issue Mar 8, 2019 · 5 comments

Comments

@fabiospampinato
Copy link

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 the toggleFindRegex command rather than the default one, how should I go about it?

@fabiospampinato
Copy link
Author

fabiospampinato commented Mar 8, 2019

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 );
    };

@hyvyys
Copy link

hyvyys commented Oct 3, 2019

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?

@hyvyys
Copy link

hyvyys commented Oct 3, 2019

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
      );

@hyvyys
Copy link

hyvyys commented Oct 5, 2019

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.

@alexdima
Copy link
Member

Let's track in #102

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 26, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants