Git Product home page Git Product logo

Comments (7)

alexdima avatar alexdima commented on July 23, 2024 4

@ChrisFan You can do a chord like this:

var KM = monaco.KeyMod;
var KC = monaco.KeyCode;
editor.addCommand(KM.chord(KM.CtrlCmd | KC.KEY_K, KM.CtrlCmd | KC.KEY_M), function() {
 //...
});

from monaco-editor.

ptyork avatar ptyork commented on July 23, 2024 1

Ah, good find! Works perfectly for me, as well. Thanks!!

from monaco-editor.

alexdima avatar alexdima commented on July 23, 2024

@ptyork Your code works for me if I don't use an array:

var myBinding = editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function() {
    alert('SAVE pressed!');
});

from monaco-editor.

ptyork avatar ptyork commented on July 23, 2024

Let me clarify that this is with FF. Seems to work without issue in Chrome and Edge (Edge seemingly not pre-binding Ctrl+S). And works with or without the array for me anyway.

Incidentally, while I think this may be a real bug, is there a discussion forum for this so that I don't clutter the issue log with other questions?

from monaco-editor.

alexdima avatar alexdima commented on July 23, 2024

Ok, I could reproduce in FF. I have debugged into the keybindingServiceImpl and we do call e.preventDefault(). Here is what I could find, seems to be a problem with FF and calling alert: http://stackoverflow.com/questions/14860759/cant-override-ctrls-in-firefox-using-jquery-hotkeys/14861031#14861031

So changing your snippet to the following works for me:

var myBinding = editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, function() {
    console.log('SAVE pressed!');
});

We haven't set up a forum, so please feel free to continue creating issues. I don't think that is a problem, the main advantage is that they are searchable.

from monaco-editor.

ChrisFan avatar ChrisFan commented on July 23, 2024

is it possible to bind [⌘K W] ?

editor.addCommand(CtrlCmd | KEY_K | KEY_W, () => {
  // this is not working
});

from monaco-editor.

manideepmothe641 avatar manideepmothe641 commented on July 23, 2024

add this command on editorInstance itself...
THANKS & IT WORKS LIKE CHARM

from monaco-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.