(function(g){"object"==typeof exports&&"object"==typeof module?g(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],g):g(CodeMirror)})(function(g){function n(c){if(c.getOption("disableInput"))return g.Pass;for(var d=c.listSelections(),a,m=[],k=0;k<d.length;k++){var h=d[k].head;if(!/\bcomment\b/.test(c.getTokenTypeAt(h)))return g.Pass;var b=c.getModeAt(h);if(!a)a=b;else if(a!=b)return g.Pass;b=null;if(a.blockCommentStart&&a.blockCommentContinue){var e=
c.getLine(h.line).slice(0,h.ch),l=e.lastIndexOf(a.blockCommentEnd),f;if(-1==l||l!=h.ch-a.blockCommentEnd.length)if(-1<(f=e.lastIndexOf(a.blockCommentStart))&&f>l){if(b=e.slice(0,f),/\S/.test(b))for(b="",e=0;e<f;++e)b+=" "}else-1<(f=e.indexOf(a.blockCommentContinue))&&!/\S/.test(e.slice(0,f))&&(b=e.slice(0,f));null!=b&&(b+=a.blockCommentContinue)}null==b&&a.lineComment&&p(c)&&(e=c.getLine(h.line),f=e.indexOf(a.lineComment),-1<f&&(b=e.slice(0,f),b=/\S/.test(b)?null:b+(a.lineComment+e.slice(f+a.lineComment.length).match(/^\s*/)[0])));
if(null==b)return g.Pass;m[k]="\n"+b}c.operation(function(){for(var a=d.length-1;0<=a;a--)c.replaceRange(m[a],d[a].from(),d[a].to(),"+insert")})}function p(c){return(c=c.getOption("continueComments"))&&"object"==typeof c?!1!==c.continueLineComment:!0}g.defineOption("continueComments",null,function(c,d,a){a&&a!=g.Init&&c.removeKeyMap("continueComment");d&&(a="Enter","string"==typeof d?a=d:"object"==typeof d&&d.key&&(a=d.key),d={name:"continueComment"},d[a]=n,c.addKeyMap(d))})});
