1(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(a){"use strict";var b=a.commands;var c=a.Pos;function d(b,d,e){if(e<0&&d.ch==0)return b.clipPos(c(d.line-1));var f=b.getLine(d.line);if(e>0&&d.ch>=f.length)return b.clipPos(c(d.line+1,0));var g="start",h,i=d.ch;for(var j=i,k=e<0?0:f.length,l=0;j!=k;j+=e,l++){var m=f.charAt(e<0?j-1:j);var n=m!="_"&&a.isWordChar(m)?"w":"o";if(n=="w"&&m.toUpperCase()==m)n="W";if(g=="start"){if(n!="o"){g="in";h=n}else i=j+e}else if(g=="in"){if(h!=n){if(h=="w"&&n=="W"&&e<0)j--;if(h=="W"&&n=="w"&&e>0){if(j==i+1){h="w";continue}else j--}break}}}return c(d.line,j)}function e(a,b){a.extendSelectionsBy(function(c){if(a.display.shift||a.doc.extend||c.empty())return d(a.doc,c.head,b);else return b<0?c.from():c.to()})}b.goSubwordLeft=function(a){e(a,-1)};b.goSubwordRight=function(a){e(a,1)};b.scrollLineUp=function(a){var b=a.getScrollInfo();if(!a.somethingSelected()){var c=a.lineAtHeight(b.top+b.clientHeight,"local");if(a.getCursor().line>=c)a.execCommand("goLineUp")}a.scrollTo(null,b.top-a.defaultTextHeight())};b.scrollLineDown=function(a){var b=a.getScrollInfo();if(!a.somethingSelected()){var c=a.lineAtHeight(b.top,"local")+1;if(a.getCursor().line<=c)a.execCommand("goLineDown")}a.scrollTo(null,b.top+a.defaultTextHeight())};b.splitSelectionByLine=function(a){var b=a.listSelections(),d=[];for(var e=0;e<b.length;e++){var f=b[e].from(),g=b[e].to();for(var h=f.line;h<=g.line;++h)if(!(g.line>f.line&&h==g.line&&g.ch==0))d.push({anchor:h==f.line?f:c(h,0),head:h==g.line?g:c(h)})}a.setSelections(d,0)};b.singleSelectionTop=function(a){var b=a.listSelections()[0];a.setSelection(b.anchor,b.head,{scroll:false})};b.selectLine=function(a){var b=a.listSelections(),d=[];for(var e=0;e<b.length;e++){var f=b[e];d.push({anchor:c(f.from().line,0),head:c(f.to().line+1,0)})}a.setSelections(d)};function f(b,d){if(b.isReadOnly())return a.Pass;b.operation(function(){var a=b.listSelections().length,e=[],f=-1;for(var g=0;g<a;g++){var h=b.listSelections()[g].head;if(h.line<=f)continue;var i=c(h.line+(d?0:1),0);b.replaceRange("\n",i,null,"+insertLine");b.indentLine(i.line,null,true);e.push({head:i,anchor:i});f=h.line+1}b.setSelections(e)});b.execCommand("indentAuto")}b.insertLineAfter=function(a){return f(a,false)};b.insertLineBefore=function(a){return f(a,true)};function g(b,d){var e=d.ch,f=e,g=b.getLine(d.line);while(e&&a.isWordChar(g.charAt(e-1)))--e;while(f<g.length&&a.isWordChar(g.charAt(f)))++f;return{from:c(d.line,e),to:c(d.line,f),word:g.slice(e,f)}}b.selectNextOccurrence=function(b){var d=b.getCursor("from"),e=b.getCursor("to");var f=b.state.sublimeFindFullWord==b.doc.sel;if(a.cmpPos(d,e)==0){var h=g(b,d);if(!h.word)return;b.setSelection(h.from,h.to);f=true}else{var j=b.getRange(d,e);var k=f?new RegExp("\\b"+j+"\\b"):j;var l=b.getSearchCursor(k,e);var m=l.findNext();if(!m){l=b.getSearchCursor(k,c(b.firstLine(),0));m=l.findNext()}if(!m||i(b.listSelections(),l.from(),l.to()))return;b.addSelection(l.from(),l.to())}if(f)b.state.sublimeFindFullWord=b.doc.sel};b.skipAndSelectNextOccurrence=function(c){var d=c.getCursor("anchor"),e=c.getCursor("head");b.selectNextOccurrence(c);if(a.cmpPos(d,e)!=0){c.doc.setSelections(c.doc.listSelections().filter(function(a){return a.anchor!=d||a.head!=e}))}};function h(a,b){var c=a.listSelections(),d=[];for(var e=0;e<c.length;e++){var f=c[e];var g=a.findPosV(f.anchor,b,"line",f.anchor.goalColumn);var h=a.findPosV(f.head,b,"line",f.head.goalColumn);g.goalColumn=f.anchor.goalColumn!=null?f.anchor.goalColumn:a.cursorCoords(f.anchor,"div").left;h.goalColumn=f.head.goalColumn!=null?f.head.goalColumn:a.cursorCoords(f.head,"div").left;var i={anchor:g,head:h};d.push(f);d.push(i)}a.setSelections(d)}b.addCursorToPrevLine=function(a){h(a,-1)};b.addCursorToNextLine=function(a){h(a,1)};function i(b,c,d){for(var e=0;e<b.length;e++)if(a.cmpPos(b[e].from(),c)==0&&a.cmpPos(b[e].to(),d)==0)return true;return false}var j="(){}[]";function k(b){var d=b.listSelections(),e=[];for(var f=0;f<d.length;f++){var g=d[f],h=g.head,i=b.scanForBracket(h,-1);if(!i)return false;for(;;){var k=b.scanForBracket(h,1);if(!k)return false;if(k.ch==j.charAt(j.indexOf(i.ch)+1)){var l=c(i.pos.line,i.pos.ch+1);if(a.cmpPos(l,g.from())==0&&a.cmpPos(k.pos,g.to())==0){i=b.scanForBracket(i.pos,-1);if(!i)return false}else{e.push({anchor:l,head:k.pos});break}}h=c(k.pos.line,k.pos.ch+1)}}b.setSelections(e);return true}b.selectScope=function(a){k(a)||a.execCommand("selectAll")};b.selectBetweenBrackets=function(b){if(!k(b))return a.Pass};function l(a){return!a?null:/\bpunctuation\b/.test(a)?a:undefined}b.goToBracket=function(b){b.extendSelectionsBy(function(d){var e=b.scanForBracket(d.head,1,l(b.getTokenTypeAt(d.head)));if(e&&a.cmpPos(e.pos,d.head)!=0)return e.pos;var f=b.scanForBracket(d.head,-1,l(b.getTokenTypeAt(c(d.head.line,d.head.ch+1))));return f&&c(f.pos.line,f.pos.ch+1)||d.head})};b.swapLineUp=function(b){if(b.isReadOnly())return a.Pass;var d=b.listSelections(),e=[],f=b.firstLine()-1,g=[];for(var h=0;h<d.length;h++){var i=d[h],j=i.from().line-1,k=i.to().line;g.push({anchor:c(i.anchor.line-1,i.anchor.ch),head:c(i.head.line-1,i.head.ch)});if(i.to().ch==0&&!i.empty())--k;if(j>f)e.push(j,k);else if(e.length)e[e.length-1]=k;f=k}b.operation(function(){for(var a=0;a<e.length;a+=2){var d=e[a],f=e[a+1];var h=b.getLine(d);b.replaceRange("",c(d,0),c(d+1,0),"+swapLine");if(f>b.lastLine())b.replaceRange("\n"+h,c(b.lastLine()),null,"+swapLine");else b.replaceRange(h+"\n",c(f,0),null,"+swapLine")}b.setSelections(g);b.scrollIntoView()})};b.swapLineDown=function(b){if(b.isReadOnly())return a.Pass;var d=b.listSelections(),e=[],f=b.lastLine()+1;for(var g=d.length-1;g>=0;g--){var h=d[g],i=h.to().line+1,j=h.from().line;if(h.to().ch==0&&!h.empty())i--;if(i<f)e.push(i,j);else if(e.length)e[e.length-1]=j;f=j}b.operation(function(){for(var a=e.length-2;a>=0;a-=2){var d=e[a],f=e[a+1];var g=b.getLine(d);if(d==b.lastLine())b.replaceRange("",c(d-1),c(d),"+swapLine");else b.replaceRange("",c(d,0),c(d+1,0),"+swapLine");b.replaceRange(g+"\n",c(f,0),null,"+swapLine")}b.scrollIntoView()})};b.toggleCommentIndented=function(a){a.toggleComment({indent:true})};b.joinLines=function(a){var b=a.listSelections(),d=[];for(var e=0;e<b.length;e++){var f=b[e],g=f.from();var h=g.line,i=f.to().line;while(e<b.length-1&&b[e+1].from().line==i)i=b[++e].to().line;d.push({start:h,end:i,anchor:!f.empty()&&g})}a.operation(function(){var b=0,e=[];for(var f=0;f<d.length;f++){var g=d[f];var h=g.anchor&&c(g.anchor.line-b,g.anchor.ch),i;for(var j=g.start;j<=g.end;j++){var k=j-b;if(j==g.end)i=c(k,a.getLine(k).length+1);if(k<a.lastLine()){a.replaceRange(" ",c(k),c(k+1,/^\s*/.exec(a.getLine(k+1))[0].length));++b}}e.push({anchor:h||i,head:i})}a.setSelections(e,0)})};b.duplicateLine=function(a){a.operation(function(){var b=a.listSelections().length;for(var d=0;d<b;d++){var e=a.listSelections()[d];if(e.empty())a.replaceRange(a.getLine(e.head.line)+"\n",c(e.head.line,0));else a.replaceRange(a.getRange(e.from(),e.to()),e.from())}a.scrollIntoView()})};function m(b,d){if(b.isReadOnly())return a.Pass;var e=b.listSelections(),f=[],g;for(var h=0;h<e.length;h++){var i=e[h];if(i.empty())continue;var j=i.from().line,k=i.to().line;while(h<e.length-1&&e[h+1].from().line==k)k=e[++h].to().line;if(!e[h].to().ch)k--;f.push(j,k)}if(f.length)g=true;else f.push(b.firstLine(),b.lastLine());b.operation(function(){var a=[];for(var e=0;e<f.length;e+=2){var h=f[e],i=f[e+1];var j=c(h,0),k=c(i);var l=b.getRange(j,k,false);if(d)l.sort();else l.sort(function(a,b){var c=a.toUpperCase(),d=b.toUpperCase();if(c!=d){a=c;b=d}return a<b?-1:a==b?0:1});b.replaceRange(l,j,k);if(g)a.push({anchor:j,head:c(i+1,0)})}if(g)b.setSelections(a,0)})}b.sortLines=function(a){m(a,true)};b.sortLinesInsensitive=function(a){m(a,false)};b.nextBookmark=function(a){var b=a.state.sublimeBookmarks;if(b)while(b.length){var c=b.shift();var d=c.find();if(d){b.push(c);return a.setSelection(d.from,d.to)}}};b.prevBookmark=function(a){var b=a.state.sublimeBookmarks;if(b)while(b.length){b.unshift(b.pop());var c=b[b.length-1].find();if(!c)b.pop();else return a.setSelection(c.from,c.to)}};b.toggleBookmark=function(a){var b=a.listSelections();var c=a.state.sublimeBookmarks||(a.state.sublimeBookmarks=[]);for(var d=0;d<b.length;d++){var e=b[d].from(),f=b[d].to();var g=b[d].empty()?a.findMarksAt(e):a.findMarks(e,f);for(var h=0;h<g.length;h++){if(g[h].sublimeBookmark){g[h].clear();for(var i=0;i<c.length;i++)if(c[i]==g[h])c.splice(i--,1);break}}if(h==g.length)c.push(a.markText(e,f,{sublimeBookmark:true,clearWhenEmpty:false}))}};b.clearBookmarks=function(a){var b=a.state.sublimeBookmarks;if(b)for(var c=0;c<b.length;c++)b[c].clear();b.length=0};b.selectBookmarks=function(a){var b=a.state.sublimeBookmarks,c=[];if(b)for(var d=0;d<b.length;d++){var e=b[d].find();if(!e)b.splice(d--,0);else c.push({anchor:e.from,head:e.to})}if(c.length)a.setSelections(c,0)};function n(b,c){b.operation(function(){var d=b.listSelections(),e=[],f=[];for(var h=0;h<d.length;h++){var i=d[h];if(i.empty()){e.push(h);f.push("")}else f.push(c(b.getRange(i.from(),i.to())))}b.replaceSelections(f,"around","case");for(var h=e.length-1,j;h>=0;h--){var i=d[e[h]];if(j&&a.cmpPos(i.head,j)>0)continue;var k=g(b,i.head);j=k.from;b.replaceRange(c(k.word),k.from,k.to)}})}b.smartBackspace=function(b){if(b.somethingSelected())return a.Pass;b.operation(function(){var d=b.listSelections();var e=b.getOption("indentUnit");for(var f=d.length-1;f>=0;f--){var g=d[f].head;var h=b.getRange({line:g.line,ch:0},g);var i=a.countColumn(h,null,b.getOption("tabSize"));var j=b.findPosH(g,-1,"char",false);if(h&&!/\S/.test(h)&&i%e==0){var k=new c(g.line,a.findColumn(h,i-e,e));if(k.ch!=g.ch)j=k}b.replaceRange("",j,g,"+delete")}})};b.delLineRight=function(a){a.operation(function(){var b=a.listSelections();for(var d=b.length-1;d>=0;d--)a.replaceRange("",b[d].anchor,c(b[d].to().line),"+delete");a.scrollIntoView()})};b.upcaseAtCursor=function(a){n(a,function(a){return a.toUpperCase()})};b.downcaseAtCursor=function(a){n(a,function(a){return a.toLowerCase()})};b.setSublimeMark=function(a){if(a.state.sublimeMark)a.state.sublimeMark.clear();a.state.sublimeMark=a.setBookmark(a.getCursor())};b.selectToSublimeMark=function(a){var b=a.state.sublimeMark&&a.state.sublimeMark.find();if(b)a.setSelection(a.getCursor(),b)};b.deleteToSublimeMark=function(b){var c=b.state.sublimeMark&&b.state.sublimeMark.find();if(c){var d=b.getCursor(),e=c;if(a.cmpPos(d,e)>0){var f=e;e=d;d=f}b.state.sublimeKilled=b.getRange(d,e);b.replaceRange("",d,e)}};b.swapWithSublimeMark=function(a){var b=a.state.sublimeMark&&a.state.sublimeMark.find();if(b){a.state.sublimeMark.clear();a.state.sublimeMark=a.setBookmark(a.getCursor());a.setCursor(b)}};b.sublimeYank=function(a){if(a.state.sublimeKilled!=null)a.replaceSelection(a.state.sublimeKilled,null,"paste")};b.showInCenter=function(a){var b=a.cursorCoords(null,"local");a.scrollTo(null,(b.top+b.bottom)/2-a.getScrollInfo().clientHeight/2)};function o(b){var c=b.getCursor("from"),d=b.getCursor("to");if(a.cmpPos(c,d)==0){var e=g(b,c);if(!e.word)return;c=e.from;d=e.to}return{from:c,to:d,query:b.getRange(c,d),word:e}}function p(a,b){var d=o(a);if(!d)return;var e=d.query;var f=a.getSearchCursor(e,b?d.to:d.from);if(b?f.findNext():f.findPrevious()){a.setSelection(f.from(),f.to())}else{f=a.getSearchCursor(e,b?c(a.firstLine(),0):a.clipPos(c(a.lastLine())));if(b?f.findNext():f.findPrevious())a.setSelection(f.from(),f.to());else if(d.word)a.setSelection(d.from,d.to)}}b.findUnder=function(a){p(a,true)};b.findUnderPrevious=function(a){p(a,false)};b.findAllUnder=function(a){var b=o(a);if(!b)return;var c=a.getSearchCursor(b.query);var d=[];var e=-1;while(c.findNext()){d.push({anchor:c.from(),head:c.to()});if(c.from().line<=b.from.line&&c.from().ch<=b.from.ch)e++}a.setSelections(d,e)};var q=a.keyMap;q.macSublime={"Cmd-Left":"goLineStartSmart","Shift-Tab":"indentLess","Shift-Ctrl-K":"deleteLine","Alt-Q":"wrapLines","Ctrl-Left":"goSubwordLeft","Ctrl-Right":"goSubwordRight","Ctrl-Alt-Up":"scrollLineUp","Ctrl-Alt-Down":"scrollLineDown","Cmd-L":"selectLine","Shift-Cmd-L":"splitSelectionByLine",Esc:"singleSelectionTop","Cmd-Enter":"insertLineAfter","Shift-Cmd-Enter":"insertLineBefore","Cmd-D":"selectNextOccurrence","Shift-Cmd-Space":"selectScope","Shift-Cmd-M":"selectBetweenBrackets","Cmd-M":"goToBracket","Cmd-Ctrl-Up":"swapLineUp","Cmd-Ctrl-Down":"swapLineDown","Cmd-/":"toggleCommentIndented","Cmd-J":"joinLines","Shift-Cmd-D":"duplicateLine",F5:"sortLines","Cmd-F5":"sortLinesInsensitive",F2:"nextBookmark","Shift-F2":"prevBookmark","Cmd-F2":"toggleBookmark","Shift-Cmd-F2":"clearBookmarks","Alt-F2":"selectBookmarks",Backspace:"smartBackspace","Cmd-K Cmd-D":"skipAndSelectNextOccurrence","Cmd-K Cmd-K":"delLineRight","Cmd-K Cmd-U":"upcaseAtCursor","Cmd-K Cmd-L":"downcaseAtCursor","Cmd-K Cmd-Space":"setSublimeMark","Cmd-K Cmd-A":"selectToSublimeMark","Cmd-K Cmd-W":"deleteToSublimeMark","Cmd-K Cmd-X":"swapWithSublimeMark","Cmd-K Cmd-Y":"sublimeYank","Cmd-K Cmd-C":"showInCenter","Cmd-K Cmd-G":"clearBookmarks","Cmd-K Cmd-Backspace":"delLineLeft","Cmd-K Cmd-1":"foldAll","Cmd-K Cmd-0":"unfoldAll","Cmd-K Cmd-J":"unfoldAll","Ctrl-Shift-Up":"addCursorToPrevLine","Ctrl-Shift-Down":"addCursorToNextLine","Cmd-F3":"findUnder","Shift-Cmd-F3":"findUnderPrevious","Alt-F3":"findAllUnder","Shift-Cmd-[":"fold","Shift-Cmd-]":"unfold","Cmd-I":"findIncremental","Shift-Cmd-I":"findIncrementalReverse","Cmd-H":"replace",F3:"findNext","Shift-F3":"findPrev",fallthrough:"macDefault"};a.normalizeKeyMap(q.macSublime);q.pcSublime={"Shift-Tab":"indentLess","Shift-Ctrl-K":"deleteLine","Alt-Q":"wrapLines","Ctrl-T":"transposeChars","Alt-Left":"goSubwordLeft","Alt-Right":"goSubwordRight","Ctrl-Up":"scrollLineUp","Ctrl-Down":"scrollLineDown","Ctrl-L":"selectLine","Shift-Ctrl-L":"splitSelectionByLine",Esc:"singleSelectionTop","Ctrl-Enter":"insertLineAfter","Shift-Ctrl-Enter":"insertLineBefore","Ctrl-D":"selectNextOccurrence","Shift-Ctrl-Space":"selectScope","Shift-Ctrl-M":"selectBetweenBrackets","Ctrl-M":"goToBracket","Shift-Ctrl-Up":"swapLineUp","Shift-Ctrl-Down":"swapLineDown","Ctrl-/":"toggleCommentIndented","Ctrl-J":"joinLines","Shift-Ctrl-D":"duplicateLine",F9:"sortLines","Ctrl-F9":"sortLinesInsensitive",F2:"nextBookmark","Shift-F2":"prevBookmark","Ctrl-F2":"toggleBookmark","Shift-Ctrl-F2":"clearBookmarks","Alt-F2":"selectBookmarks",Backspace:"smartBackspace","Ctrl-K Ctrl-D":"skipAndSelectNextOccurrence","Ctrl-K Ctrl-K":"delLineRight","Ctrl-K Ctrl-U":"upcaseAtCursor","Ctrl-K Ctrl-L":"downcaseAtCursor","Ctrl-K Ctrl-Space":"setSublimeMark","Ctrl-K Ctrl-A":"selectToSublimeMark","Ctrl-K Ctrl-W":"deleteToSublimeMark","Ctrl-K Ctrl-X":"swapWithSublimeMark","Ctrl-K Ctrl-Y":"sublimeYank","Ctrl-K Ctrl-C":"showInCenter","Ctrl-K Ctrl-G":"clearBookmarks","Ctrl-K Ctrl-Backspace":"delLineLeft","Ctrl-K Ctrl-1":"foldAll","Ctrl-K Ctrl-0":"unfoldAll","Ctrl-K Ctrl-J":"unfoldAll","Ctrl-Alt-Up":"addCursorToPrevLine","Ctrl-Alt-Down":"addCursorToNextLine","Ctrl-F3":"findUnder","Shift-Ctrl-F3":"findUnderPrevious","Alt-F3":"findAllUnder","Shift-Ctrl-[":"fold","Shift-Ctrl-]":"unfold","Ctrl-I":"findIncremental","Shift-Ctrl-I":"findIncrementalReverse","Ctrl-H":"replace",F3:"findNext","Shift-F3":"findPrev",fallthrough:"pcDefault"};a.normalizeKeyMap(q.pcSublime);var r=q.default==q.macDefault;q.sublime=r?q.macSublime:q.pcSublime}); 2//# sourceMappingURL=sublime.min.js.map