!function(){function e(e,n,t,i){if(this.atOccurrence=!1,this.cm=e,null==i&&"string"==typeof n&&(i=!1),t=t?e.clipPos(t):{line:0,ch:0},this.pos={from:t,to:t},"string"!=typeof n)n.global||(n=new RegExp(n.source,n.ignoreCase?"ig":"g")),this.matches=function(t,i){if(t){n.lastIndex=0;for(var r=e.getLine(i.line).slice(0,i.ch),c=n.exec(r),o=0;c;){o+=c.index+1,r=r.slice(o),n.lastIndex=0;var h=n.exec(r);if(!h)break;c=h}o--}else{n.lastIndex=i.ch;r=e.getLine(i.line),o=(c=n.exec(r))&&c.index}if(c)return{from:{line:i.line,ch:o},to:{line:i.line,ch:o+c[0].length},match:c}};else{i&&(n=n.toLowerCase());var r=i?function(e){return e.toLowerCase()}:function(e){return e},c=n.split("\n");1==c.length?this.matches=function(t,i){var c,o=r(e.getLine(i.line)),h=n.length;if(t?i.ch>=h&&-1!=(c=o.lastIndexOf(n,i.ch-h)):-1!=(c=o.indexOf(n,i.ch)))return{from:{line:i.line,ch:c},to:{line:i.line,ch:c+h}}}:this.matches=function(n,t){var i=t.line,o=n?c.length-1:0,h=c[o],s=r(e.getLine(i)),l=n?s.indexOf(h)+h.length:s.lastIndexOf(h);if(!(n?l>=t.ch||l!=h.length:l<=t.ch||l!=s.length-h.length))for(;;){if(n?!i:i==e.lineCount()-1)return;if(s=r(e.getLine(i+=n?-1:1)),h=c[n?--o:++o],!(o>0&&o<c.length-1)){var f=n?s.lastIndexOf(h):s.indexOf(h)+h.length;if(n?f!=s.length-h.length:f!=h.length)return;var u={line:t.line,ch:l},a={line:i,ch:f};return{from:n?a:u,to:n?u:a}}if(s!=h)return}}}}e.prototype={findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},find:function(e){function n(e){var n={line:e,ch:0};return t.pos={from:n,to:n},t.atOccurrence=!1,!1}for(var t=this,i=this.cm.clipPos(e?this.pos.from:this.pos.to);;){if(this.pos=this.matches(e,i))return this.atOccurrence=!0,this.pos.match||!0;if(e){if(!i.line)return n(0);i={line:i.line-1,ch:this.cm.getLine(i.line-1).length}}else{var r=this.cm.lineCount();if(i.line==r-1)return n(r);i={line:i.line+1,ch:0}}}},from:function(){if(this.atOccurrence)return this.pos.from},to:function(){if(this.atOccurrence)return this.pos.to},replace:function(e){this.atOccurrence&&(this.pos.to=this.cm.replaceRange(e,this.pos.from,this.pos.to))}},CodeMirror.defineExtension("getSearchCursor",function(n,t,i){return new e(this,n,t,i)})}();