Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent the Default Event from happening with Codemirror's keymaps

I'm trying to figure out how to prevent the browser from displaying the save dialog with a ctrl-s or cmd-s event in Codemirror. I can get the extraKeys to work, I just can't get it to avoid calling resuming the event. I've tried return false and I've dug through the documentation and samples. Does anyone know how to prevent the default from happening?

Here's the code:

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true, mode: "text/html",
   extraKeys: {
      "Ctrl-S": function (instance) {
         alert("your mom");
         return false;
      },
      "Cmd-S": function (instance) {
         alert("my mom");
         return false;
      }
   }
}); 
like image 310
uadrive Avatar asked Mar 20 '13 18:03

uadrive


1 Answers

This is an old question and the solution is already inside the answer, but for anyone looking for a solution to implement Ctrl-S / Cmd-S using CodeMirror, I guess there is a better solution as noted in CodeMirrror documentaion

CodeMirror.commands.save = function() {
    /* Do your stuff */
};
like image 143
Özgür Uysal Avatar answered Sep 30 '22 09:09

Özgür Uysal