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