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