2 var modes
= ["clike", "css", "javascript"];
3 for (var i
= 0; i
< modes
.length
; ++i
)
4 CodeMirror
.extendMode(modes
[i
], {blockCommentStart
: "/*",
6 blockCommentContinue
: " * "});
8 function continueComment(cm
) {
9 var pos
= cm
.getCursor(), token
= cm
.getTokenAt(pos
);
10 var mode
= CodeMirror
.innerMode(cm
.getMode(), token
.state
).mode
;
13 if (token
.type
== "comment" && mode
.blockCommentStart
) {
14 var end
= token
.string
.indexOf(mode
.blockCommentEnd
);
15 var full
= cm
.getRange(CodeMirror
.Pos(pos
.line
, 0), CodeMirror
.Pos(pos
.line
, token
.end
)), found
;
16 if (end
!= -1 && end
== token
.string
.length
- mode
.blockCommentEnd
.length
) {
17 // Comment ended, don't continue it
18 } else if (token
.string
.indexOf(mode
.blockCommentStart
) == 0) {
19 space
= full
.slice(0, token
.start
);
20 if (!/^\s*$/.test(space
)) {
22 for (var i
= 0; i
< token
.start
; ++i
) space
+= " ";
24 } else if ((found
= full
.indexOf(mode
.blockCommentContinue
)) != -1 &&
25 found
+ mode
.blockCommentContinue
.length
> token
.start
&&
26 /^\s*$/.test(full
.slice(0, found
))) {
27 space
= full
.slice(0, found
);
32 cm
.replaceSelection("\n" + space
+ mode
.blockCommentContinue
, "end");
34 return CodeMirror
.Pass
;
37 CodeMirror
.defineOption("continueComments", null, function(cm
, val
, prev
) {
38 if (prev
&& prev
!= CodeMirror
.Init
)
39 cm
.removeKeyMap("continueComment");
40 var map
= {name
: "continueComment"};
41 map
[typeof val
== "string" ? val
: "Enter"] = continueComment
;