通过自定义Alt+/ 快捷键对sql语句独立行进行快捷注释
mounted() {
let cm = this.$refs.myCm.codemirror;
cm.setOption("extraKeys", {
// F11键切换全屏
"F11" (cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
},
"Ctrl-/": function(cm) {
console.log("current row:",cm.getCursor());
let origin = cm.getLine(cm.getCursor().line);
let note = '-- ' + cm.getLine(cm.getCursor().line);
if(origin.startsWith("-- ")){
cm.replaceRange(origin.substr(3),
{ch:0, line: cm.getCursor().line},
{ch:cm.getCursor().ch, line: cm.getCursor().line},null);
}else{
cm.replaceRange(note,
{ch:0, line: cm.getCursor().line},
{ch:cm.getCursor().ch, line: cm.getCursor().line},null);
}
}
});
参考网址:命令 · CodeMirror · 看云