brace-fold.js
11 years ago
brace-fold.min.js
11 years ago
comment-fold.js
11 years ago
comment-fold.min.js
11 years ago
foldcode.js
11 years ago
foldcode.min.js
11 years ago
foldgutter.css
11 years ago
foldgutter.js
11 years ago
foldgutter.min.js
11 years ago
indent-fold.js
11 years ago
indent-fold.min.js
11 years ago
markdown-fold.js
11 years ago
markdown-fold.min.js
11 years ago
xml-fold.js
11 years ago
xml-fold.min.js
11 years ago
comment-fold.min.js
10 lines
| 1 | |
| 2 | (function(mod){if(typeof exports=="object"&&typeof module=="object") |
| 3 | mod(require("../../lib/codemirror"));else if(typeof define=="function"&&define.amd) |
| 4 | define(["../../lib/codemirror"],mod);else |
| 5 | mod(CodeMirror);})(function(CodeMirror){"use strict";CodeMirror.registerGlobalHelper("fold","comment",function(mode){return mode.blockCommentStart&&mode.blockCommentEnd;},function(cm,start){var mode=cm.getModeAt(start),startToken=mode.blockCommentStart,endToken=mode.blockCommentEnd;if(!startToken||!endToken)return;var line=start.line,lineText=cm.getLine(line);var startCh;for(var at=start.ch,pass=0;;){var found=at<=0?-1:lineText.lastIndexOf(startToken,at-1);if(found==-1){if(pass==1)return;pass=1;at=lineText.length;continue;} |
| 6 | if(pass==1&&found<start.ch)return;if(/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line,found+1)))){startCh=found+startToken.length;break;} |
| 7 | at=found-1;} |
| 8 | var depth=1,lastLine=cm.lastLine(),end,endCh;outer:for(var i=line;i<=lastLine;++i){var text=cm.getLine(i),pos=i==line?startCh:0;for(;;){var nextOpen=text.indexOf(startToken,pos),nextClose=text.indexOf(endToken,pos);if(nextOpen<0)nextOpen=text.length;if(nextClose<0)nextClose=text.length;pos=Math.min(nextOpen,nextClose);if(pos==text.length)break;if(pos==nextOpen)++depth;else if(!--depth){end=i;endCh=pos;break outer;} |
| 9 | ++pos;}} |
| 10 | if(end==null||line==end&&endCh==startCh)return;return{from:CodeMirror.Pos(line,startCh),to:CodeMirror.Pos(end,endCh)};});}); |