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;
}
}
});
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 */
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With