text: (function(a){if(typeof exports=="object"&&typeof module=="object"){a(require("../lib/codemirror"),require("../addon/search/searchcursor"),require("../addon/edit/matchbrackets"))}else{if(typeof define=="function"&&define.amd){define(["../lib/codemirror","../addon/search/searchcursor","../addon/edit/matchbrackets"],a)}else{a(CodeMirror)}}})(function(g){var b=g.keyMap.sublime={fallthrough:"default"};var d=g.commands;var m=g.Pos;var a=g.keyMap["default"]==g.keyMap.pcDefault?"Ctrl-":"Cmd-";function c(y,q,r){if(r<0&&q.ch==0){return y.clipPos(m(q.line-1))}var z=y.getLine(q.line);if(r>0&&q.ch>=z.length){return y.clipPos(m(q.line+1,0))}var p="start",v;for(var x=q.ch,u=r<0?0:z.length,s=0;x!=u;x+=r,s++){var t=z.charAt(r<0?x-1:x);var w=t!="_"&&g.isWordChar(t)?"w":"o";if(w=="w"&&t.toUpperCase()==t){w="W"}if(p=="start"){if(w!="o"){p="in";v=w}}else{if(p=="in"){if(v!=w){if(v=="w"&&w=="W"&&r<0){x--}if(v=="W"&&w=="w"&&r>0){v="w";continue}break}}}}return m(q.line,x)}function j(p,q){p.extendSelectionsBy(function(r){if(p.display.shift||p.doc.extend||r.empty()){return c(p.doc,r.head,q)}else{return q<0?r.from():r.to()}})}d[b["Alt-Left"]="goSubwordLeft"]=function(p){j(p,-1)};d[b["Alt-Right"]="goSubwordRight"]=function(p){j(p,1)};d[b[a+"Up"]="scrollLineUp"]=function(p){var r=p.getScrollInfo();if(!p.somethingSelected()){var q=p.lineAtHeight(r.top+r.clientHeight,"local");if(p.getCursor().line>=q){p.execCommand("goLineUp")}}p.scrollTo(null,r.top-p.defaultTextHeight())};d[b[a+"Down"]="scrollLineDown"]=function(p){var r=p.getScrollInfo();if(!p.somethingSelected()){var q=p.lineAtHeight(r.top,"local")+1;if(p.getCursor().line<=q){p.execCommand("goLineDown")}}p.scrollTo(null,r.top+p.defaultTextHeight())};d[b["Shift-"+a+"L"]="splitSelectionByLine"]=function(p){var r=p.listSelections(),t=[];for(var s=0;s<r.length;s++){var v=r[s].from(),u=r[s].to();for(var q=v.line;q<=u.line;++q){if(!(u.line>v.line&&q==u.line&&u.ch==0)){t.push({anchor:q==v.line?v:m(q,0),head:q==u.line?u:m(q)})}}}p.setSelections(t,0)};b["Shift-Tab"]="indentLess";d[b.Esc="singleSelectionTop"]=function(p){var q=p.listSelections()[0];p.setSelection(q.anchor,q.head,{scroll:false})};d[b[a+"L"]="selectLine"]=function(q){var r=q.listSelections(),p=[];for(var t=0;t<r.length;t++){var s=r[t];p.push({anchor:m(s.from().line,0),head:m(s.to().line+1,0)})}q.setSelections(p)};b["Shift-"+a+"K"]="deleteLine";function e(q,p){q.operation(function(){var t=q.listSelections().length,s=[],w=-1;for(var v=0;v<t;v++){var u=q.listSelections()[v].head;if(u.line<=w){continue}var r=m(u.line+(p?0:1),0);q.replaceRange("\n",r,null,"+insertLine");q.indentLine(r.line,null,true);s.push({head:r,anchor:r});w=u.line+1}q.setSelections(s)})}d[b[a+"Enter"]="insertLineAfter"]=function(p){e(p,false)};d[b["Shift-"+a+"Enter"]="insertLineBefore"]=function(p){e(p,true)};function f(p,t){var s=t.ch,r=s,q=p.getLine(t.line);while(s&&g.isWordChar(q.charAt(s-1))){--s}while(r<q.length&&g.isWordChar(q.charAt(r))){++r}return{from:m(t.line,s),to:m(t.line,r),word:q.slice(s,r)}}d[b[a+"D"]="selectNextOccurrence"]=function(p){var w=p.getCursor("from"),v=p.getCursor("to");var q=p.state.sublimeFindFullWord==p.doc.sel;if(g.cmpPos(w,v)==0){var s=f(p,w);if(!s.word){return}p.setSelection(s.from,s.to);q=true}else{var u=p.getRange(w,v);var r=q?new RegExp("\\b"+u+"\\b"):u;var t=p.getSearchCursor(r,v);if(t.findNext()){p.addSelection(t.from(),t.to())}else{t=p.getSearchCursor(r,m(p.firstLine(),0));if(t.findNext()){p.addSelection(t.from(),t.to())}}}if(q){p.state.sublimeFindFullWord=p.doc.sel}};var l="(){}[]";function k(q){var s=q.getCursor(),p=q.scanForBracket(s,-1);if(!p){return}for(;;){var r=q.scanForBracket(s,1);if(!r){return}if(r.ch==l.charAt(l.indexOf(p.ch)+1)){q.setSelection(m(p.pos.line,p.pos.ch+1),r.pos,false);return true}s=m(r.pos.line,r.pos.ch+1)}}d[b["Shift-"+a+"Space"]="selectScope"]=function(p){k(p)||p.execCommand("selectAll")};d[b["Shift-"+a+"M"]="selectBetweenBrackets"]=function(p){if(!k(p)){return g.Pass}};d[b[a+"M"]="goToBracket"]=function(p){p.extendSelectionsBy(function(q){var r=p.scanForBracket(q.head,1);if(r&&g.cmpPos(r.pos,q.head)!=0){return r.pos}var s=p.scanForBracket(q.head,-1);return s&&m(s.pos.line,s.pos.ch+1)||q.head})};d[b["Shift-"+a+"Up"]="swapLineUp"]=function(w){var p=w.listSelections(),t=[],q=w.firstLine()-1,x=[];for(var r=0;r<p.length;r++){var s=p[r],v=s.from().line-1,u=s.to().line;x.push({anchor:m(s.anchor.line-1,s.anchor.ch),head:m(s.head.line-1,s.head.ch)});if(s.to().ch==0&&!s.empty()){--u}if(v>q){t.push(v,u)}else{if(t.length){t[t.length-1]=u}}q=u}w.operation(function(){for(var z=0;z<t.length;z+=2){var B=t[z],A=t[z+1];var y=w.getLine(B);w.replaceRange("",m(B,0),m(B+1,0),"+swapLine");if(A>w.lastLine()){w.replaceRange("\n"+y,m(w.lastLine()),null,"+swapLine")}else{w.replaceRange(y+"\n",m(A,0),null,"+swapLine")}}w.setSelections(x);w.scrollIntoView()})};d[b["Shift-"+a+"Down"]="swapLineDown"]=function(q){var r=q.listSelections(),u=[],p=q.lastLine()+1;for(var t=r.length-1;t>=0;t--){var s=r[t],w=s.to().line+1,v=s.from().line;if(s.to().ch==0&&!s.empty()){w--}if(w<p){u.push(w,v)}else{if(u.length){u[u.length-1]=v}}p=v}q.operation(function(){for(var y=u.length-2;y>=0;y-=2){var A=u[y],z=u[y+1];var x=q.getLine(A);if(A==q.lastLine()){q.replaceRange("",m(A-1),m(A),"+swapLine")}else{q.replaceRange("",m(A,0),m(A+1,0),"+swapLine")}q.replaceRange(x+"\n",m(z,0),null,"+swapLine")}q.scrollIntoView()})};b[a+"/"]="toggleComment";d[b[a+"J"]="joinLines"]=function(p){var r=p.listSelections(),u=[];for(var t=0;t<r.length;t++){var s=r[t],w=s.from();var v=w.line,q=s.to().line;while(t<r.length-1&&r[t+1].from().line==q){q=r[++t].to().line}u.push({start:v,end:q,anchor:!s.empty()&&w})}p.operation(function(){var D=0,y=[];for(var B=0;B<u.length;B++){var C=u[B];var z=C.anchor&&m(C.anchor.line-D,C.anchor.ch),A;for(var x=C.start;x<=C.end;x++){var E=x-D;if(x==C.end){A=m(E,p.getLine(E).length+1)}if(E<p.lastLine()){p.replaceRange(" ",m(E),m(E+1,/^\s*/.exec(p.getLine(E+1))[0].length));++D}}y.push({anchor:z||A,head:A})}p.setSelections(y,0)})};d[b["Shift-"+a+"D"]="duplicateLine"]=function(p){p.operation(function(){var r=p.listSelections().length;for(var s=0;s<r;s++){var q=p.listSelections()[s];if(q.empty()){p.replaceRange(p.getLine(q.head.line)+"\n",m(q.head.line,0))}else{p.replaceRange(p.getRange(q.from(),q.to()),q.from())}}p.scrollIntoView()})};b[a+"T"]="transposeChars";function o(x,u){var p=x.listSelections(),t=[],q;for(var r=0;r<p.length;r++){var s=p[r];if(s.empty()){continue}var w=s.from().line,v=s.to().line;while(r<p.length-1&&p[r+1].from().line==v){v=s[++r].to().line}t.push(w,v)}if(t.length){q=true}else{t.push(x.firstLine(),x.lastLine())}x.operation(function(){var A=[];for(var B=0;B<t.length;B+=2){var E=t[B],D=t[B+1];var C=m(E,0),z=m(D);var y=x.getRange(C,z,false);if(u){y.sort()}else{y.sort(function(H,F){var I=H.toUpperCase(),G=F.toUpperCase();if(I!=G){H=I;F=G}return H<F?-1:H==F?0:1})}x.replaceRange(y,C,z);if(q){A.push({anchor:C,head:z})}}if(q){x.setSelections(A,0)}})}d[b.F9="sortLines"]=function(p){o(p,true)};d[b[a+"F9"]="sortLinesInsensitive"]=function(p){o(p,false)};d[b.F2="nextBookmark"]=function(p){var q=p.state.sublimeBookmarks;if(q){while(q.length){var s=q.shift();var r=s.find();if(r){q.push(s);return p.setSelection(r.from,r.to)}}}};d[b["Shift-F2"]="prevBookmark"]=function(p){var q=p.state.sublimeBookmarks;if(q){while(q.length){q.unshift(q.pop());var r=q[q.length-1].find();if(!r){q.pop()}else{return p.setSelection(r.from,r.to)}}}};d[b[a+"F2"]="toggleBookmark"]=function(w){var p=w.listSelections();var t=w.state.sublimeBookmarks||(w.state.sublimeBookmarks=[]);for(var s=0;s<p.length;s++){var u=p[s].from(),v=p[s].to();var x=w.findMarks(u,v);for(var r=0;r<x.length;r++){if(x[r].sublimeBookmark){x[r].clear();for(var q=0;q<t.length;q++){if(t[q]==x[r]){t.splice(q--,1)}}break}}if(r==x.length){t.push(w.markText(u,v,{sublimeBookmark:true,clearWhenEmpty:false}))}}};d[b["Shift-"+a+"F2"]="clearBookmarks"]=function(p){var r=p.state.sublimeBookmarks;if(r){for(var q=0;q<r.length;q++){r[q].clear()}}r.length=0};d[b["Alt-F2"]="selectBookmarks"]=function(p){var s=p.state.sublimeBookmarks,q=[];if(s){for(var r=0;r<s.length;r++){var t=s[r].find();if(!t){s.splice(r--,0)}else{q.push({anchor:t.from,head:t.to})}}}if(q.length){p.setSelections(q,0)}};b["Alt-Q"]="wrapLines";var h=g.keyMap["sublime-Ctrl-K"]={auto:"sublime",nofallthrough:true};b[a+"K"]=function(p){p.setOption("keyMap","sublime-Ctrl-K")};function i(p,q){p.operation(function(){var s=p.listSelections(),x=[],v=[];for(var u=0;u<s.length;u++){var t=s[u];if(t.empty()){x.push(u);v.push("")}else{v.push(q(p.getRange(t.from(),t.to())))}}p.replaceSelections(v,"around","case");for(var u=x.length-1,r;u>=0;u--){var t=s[x[u]];if(r&&g.cmpPos(t.head,r)>0){continue}var w=f(p,t.head);r=w.from;p.replaceRange(q(w.word),w.from,w.to)}})}h[a+"Backspace"]="delLineLeft";d[h[a+"K"]="delLineRight"]=function(p){p.operation(function(){var q=p.listSelections();for(var r=q.length-1;r>=0;r--){p.replaceRange("",q[r].anchor,m(q[r].to().line),"+delete")}p.scrollIntoView()})};d[h[a+"U"]="upcaseAtCursor"]=function(p){i(p,function(q){return q.toUpperCase()})};d[h[a+"L"]="downcaseAtCursor"]=function(p){i(p,function(q){return q.toLowerCase()})};d[h[a+"Space"]="setSublimeMark"]=function(p){if(p.state.sublimeMark){p.state.sublimeMark.clear()}p.state.sublimeMark=p.setBookmark(p.getCursor())};d[h[a+"A"]="selectToSublimeMark"]=function(p){var q=p.state.sublimeMark&&p.state.sublimeMark.find();if(q){p.setSelection(p.getCursor(),q)}};d[h[a+"W"]="deleteToSublimeMark"]=function(p){var r=p.state.sublimeMark&&p.state.sublimeMark.find();if(r){var t=p.getCursor(),s=r;if(g.cmpPos(t,s)>0){var q=s;s=t;t=q}p.state.sublimeKilled=p.getRange(t,s);p.replaceRange("",t,s)}};d[h[a+"X"]="swapWithSublimeMark"]=function(p){var q=p.state.sublimeMark&&p.state.sublimeMark.find();if(q){p.state.sublimeMark.clear();p.state.sublimeMark=p.setBookmark(p.getCursor());p.setCursor(q)}};d[h[a+"Y"]="sublimeYank"]=function(p){if(p.state.sublimeKilled!=null){p.replaceSelection(p.state.sublimeKilled,null,"paste")}};h[a+"G"]="clearBookmarks";d[h[a+"C"]="showInCenter"]=function(p){var q=p.cursorCoords(null,"local");p.scrollTo(null,(q.top+q.bottom)/2-p.getScrollInfo().clientHeight/2)};d[b["Shift-Alt-Up"]="selectLinesUpward"]=function(p){p.operation(function(){var q=p.listSelections();for(var s=0;s<q.length;s++){var r=q[s];if(r.head.line>p.firstLine()){p.addSelection(m(r.head.line-1,r.head.ch))}}})};d[b["Shift-Alt-Down"]="selectLinesDownward"]=function(p){p.operation(function(){var q=p.listSelections();for(var s=0;s<q.length;s++){var r=q[s];if(r.head.line<p.lastLine()){p.addSelection(m(r.head.line+1,r.head.ch))}}})};function n(p,q){var v=p.getCursor("from"),u=p.getCursor("to");if(g.cmpPos(v,u)==0){var s=f(p,v);if(!s.word){return}v=s.from;u=s.to}var r=p.getRange(v,u);var t=p.getSearchCursor(r,q?u:v);if(q?t.findNext():t.findPrevious()){p.setSelection(t.from(),t.to())}else{t=p.getSearchCursor(r,q?m(p.firstLine(),0):p.clipPos(m(p.lastLine())));if(q?t.findNext():t.findPrevious()){p.setSelection(t.from(),t.to())}else{if(s){p.setSelection(v,u)}}}}d[b[a+"F3"]="findUnder"]=function(p){n(p,true)};d[b["Shift-"+a+"F3"]="findUnderPrevious"]=function(p){n(p,false)};b["Shift-"+a+"["]="fold";b["Shift-"+a+"]"]="unfold";h[a+"0"]=h[a+"j"]="unfoldAll";b[a+"I"]="findIncremental";b["Shift-"+a+"I"]="findIncrementalReverse";b[a+"H"]="replace";b.F3="findNext";b["Shift-F3"]="findPrev"});