Skip to content
Snippets Groups Projects
Commit 1850ef46 authored by Marijn Haverbeke's avatar Marijn Haverbeke
Browse files

[continuecomment addon] Don't make the line-comment option global

Issue #2182
parent c264a212
No related branches found
No related tags found
Loading
(function() {
var modes = ["clike", "css", "javascript"];
var continueLineComment = true;
for (var i = 0; i < modes.length; ++i)
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});
......@@ -29,7 +28,7 @@
}
if (insert != null) insert += mode.blockCommentContinue;
}
if (insert == null && mode.lineComment && continueLineComment) {
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
if (found > -1) {
insert = line.slice(0, found);
......@@ -44,19 +43,22 @@
return CodeMirror.Pass;
}
function continueLineCommentEnabled(cm) {
var opt = cm.getOption("continueComments");
if (opt && typeof opt == "object")
return opt.continueLineComment !== false;
return true;
}
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
if (prev && prev != CodeMirror.Init)
cm.removeKeyMap("continueComment");
if (val) {
var key = "Enter";
if (typeof val == "string") {
if (typeof val == "string")
key = val;
} else if (typeof val == "object") {
if (val.key)
key = val.key;
if (val.continueLineComment != undefined)
continueLineComment = val.continueLineComment
}
else if (typeof val == "object" && val.key)
key = val.key;
var map = {name: "continueComment"};
map[key] = continueComment;
cm.addKeyMap(map);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment