Current File : /home/pacjaorg/public_html/kmm/media/vendor/codemirror/addon/comment/comment.min.js |
(function(u){typeof exports=="object"&&typeof module=="object"?u(require("../../lib/codemirror")):typeof define=="function"&&define.amd?define(["../../lib/codemirror"],u):u(CodeMirror)})(function(u){"use strict";var p={},L=/[^\s\u00a0]/,m=u.Pos,z=u.cmpPos;function W(t){var l=t.search(L);return l==-1?0:l}u.commands.toggleComment=function(t){t.toggleComment()},u.defineExtension("toggleComment",function(t){t||(t=p);for(var l=this,n=1/0,e=this.listSelections(),g=null,c=e.length-1;c>=0;c--){var i=e[c].from(),a=e[c].to();i.line>=n||(a.line>=n&&(a=m(n,0)),n=i.line,g==null?l.uncomment(i,a,t)?g="un":(l.lineComment(i,a,t),g="line"):g=="un"?l.uncomment(i,a,t):l.lineComment(i,a,t))}});function D(t,l,n){return/\bstring\b/.test(t.getTokenTypeAt(m(l.line,0)))&&!/^[\'\"\`]/.test(n)}function M(t,l){var n=t.getMode();return n.useInnerComments===!1||!n.innerMode?n:t.getModeAt(l)}u.defineExtension("lineComment",function(t,l,n){n||(n=p);var e=this,g=M(e,t),c=e.getLine(t.line);if(!(c==null||D(e,t,c))){var i=n.lineComment||g.lineComment;if(!i){(n.blockCommentStart||g.blockCommentStart)&&(n.fullLines=!0,e.blockComment(t,l,n));return}var a=Math.min(l.ch!=0||l.line==t.line?l.line+1:l.line,e.lastLine()+1),k=n.padding==null?" ":n.padding,f=n.commentBlankLines||t.line==l.line;e.operation(function(){if(n.indent){for(var v=null,r=t.line;r<a;++r){var s=e.getLine(r),d=s.search(L)===-1?s:s.slice(0,W(s));(v==null||v.length>d.length)&&(v=d)}for(var r=t.line;r<a;++r){var s=e.getLine(r),h=v.length;!f&&!L.test(s)||(s.slice(0,h)!=v&&(h=W(s)),e.replaceRange(v+i+k,m(r,0),m(r,h)))}}else for(var r=t.line;r<a;++r)(f||L.test(e.getLine(r)))&&e.replaceRange(i+k,m(r,0))})}}),u.defineExtension("blockComment",function(t,l,n){n||(n=p);var e=this,g=M(e,t),c=n.blockCommentStart||g.blockCommentStart,i=n.blockCommentEnd||g.blockCommentEnd;if(!c||!i){(n.lineComment||g.lineComment)&&n.fullLines!=!1&&e.lineComment(t,l,n);return}if(!/\bcomment\b/.test(e.getTokenTypeAt(m(t.line,0)))){var a=Math.min(l.line,e.lastLine());a!=t.line&&l.ch==0&&L.test(e.getLine(a))&&--a;var k=n.padding==null?" ":n.padding;t.line>a||e.operation(function(){if(n.fullLines!=!1){var f=L.test(e.getLine(a));e.replaceRange(k+i,m(a)),e.replaceRange(c+k,m(t.line,0));var v=n.blockCommentLead||g.blockCommentLead;if(v!=null)for(var r=t.line+1;r<=a;++r)(r!=a||f)&&e.replaceRange(v+k,m(r,0))}else{var s=z(e.getCursor("to"),l)==0,d=!e.somethingSelected();e.replaceRange(i,l),s&&e.setSelection(d?l:e.getCursor("from"),l),e.replaceRange(c,t)}})}}),u.defineExtension("uncomment",function(t,l,n){n||(n=p);var e=this,g=M(e,t),c=Math.min(l.ch!=0||l.line==t.line?l.line:l.line-1,e.lastLine()),i=Math.min(t.line,c),a=n.lineComment||g.lineComment,k=[],f=n.padding==null?" ":n.padding,v;e:{if(!a)break e;for(var r=i;r<=c;++r){var s=e.getLine(r),d=s.indexOf(a);if(d>-1&&!/comment/.test(e.getTokenTypeAt(m(r,d+1)))&&(d=-1),d==-1&&L.test(s)||d>-1&&L.test(s.slice(0,d)))break e;k.push(s)}if(e.operation(function(){for(var C=i;C<=c;++C){var S=k[C-i],R=S.indexOf(a),b=R+a.length;R<0||(S.slice(b,b+f.length)==f&&(b+=f.length),v=!0,e.replaceRange("",m(C,R),m(C,b)))}}),v)return!0}var h=n.blockCommentStart||g.blockCommentStart,x=n.blockCommentEnd||g.blockCommentEnd;if(!h||!x)return!1;var j=n.blockCommentLead||g.blockCommentLead,E=e.getLine(i),o=E.indexOf(h);if(o==-1)return!1;var A=c==i?E:e.getLine(c),O=A.indexOf(x,c==i?o+h.length:0),q=m(i,o+1),B=m(c,O+1);if(O==-1||!/comment/.test(e.getTokenTypeAt(q))||!/comment/.test(e.getTokenTypeAt(B))||e.getRange(q,B,`
`).indexOf(x)>-1)return!1;var y=E.lastIndexOf(h,t.ch),T=y==-1?-1:E.slice(0,t.ch).indexOf(x,y+h.length);if(y!=-1&&T!=-1&&T+x.length!=t.ch)return!1;T=A.indexOf(x,l.ch);var N=A.slice(l.ch).lastIndexOf(h,T-l.ch);return y=T==-1||N==-1?-1:l.ch+N,T!=-1&&y!=-1&&y!=l.ch?!1:(e.operation(function(){e.replaceRange("",m(c,O-(f&&A.slice(O-f.length,O)==f?f.length:0)),m(c,O+x.length));var C=o+h.length;if(f&&E.slice(C,C+f.length)==f&&(C+=f.length),e.replaceRange("",m(i,o),m(i,C)),j)for(var S=i+1;S<=c;++S){var R=e.getLine(S),b=R.indexOf(j);if(!(b==-1||L.test(R.slice(0,b)))){var I=b+j.length;f&&R.slice(I,I+f.length)==f&&(I+=f.length),e.replaceRange("",m(S,b),m(S,I))}}}),!0)})});