(function(m){"object"==typeof exports&&"object"==typeof module?m(require("../lib/codemirror")):"function"==typeof define&&define.amd?define(["../lib/codemirror"],m):m(CodeMirror)})(function(m){var ja=[{keys:["<Left>"],type:"keyToKey",toKeys:["h"]},{keys:["<Right>"],type:"keyToKey",toKeys:["l"]},{keys:["<Up>"],type:"keyToKey",toKeys:["k"]},{keys:["<Down>"],type:"keyToKey",toKeys:["j"]},{keys:["<Space>"],type:"keyToKey",toKeys:["l"]},{keys:["<BS>"],type:"keyToKey",toKeys:["h"]},{keys:["<C-Space>"],
type:"keyToKey",toKeys:["W"]},{keys:["<C-BS>"],type:"keyToKey",toKeys:["B"]},{keys:["<S-Space>"],type:"keyToKey",toKeys:["w"]},{keys:["<S-BS>"],type:"keyToKey",toKeys:["b"]},{keys:["<C-n>"],type:"keyToKey",toKeys:["j"]},{keys:["<C-p>"],type:"keyToKey",toKeys:["k"]},{keys:["<C-[>"],type:"keyToKey",toKeys:["<Esc>"]},{keys:["<C-c>"],type:"keyToKey",toKeys:["<Esc>"]},{keys:["s"],type:"keyToKey",toKeys:["c","l"],context:"normal"},{keys:["s"],type:"keyToKey",toKeys:["x","i"],context:"visual"},{keys:["S"],
type:"keyToKey",toKeys:["c","c"],context:"normal"},{keys:["S"],type:"keyToKey",toKeys:["d","c","c"],context:"visual"},{keys:["<Home>"],type:"keyToKey",toKeys:["0"]},{keys:["<End>"],type:"keyToKey",toKeys:["$"]},{keys:["<PageUp>"],type:"keyToKey",toKeys:["<C-b>"]},{keys:["<PageDown>"],type:"keyToKey",toKeys:["<C-f>"]},{keys:["<CR>"],type:"keyToKey",toKeys:["j","^"],context:"normal"},{keys:["H"],type:"motion",motion:"moveToTopLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:["M"],type:"motion",motion:"moveToMiddleLine",
motionArgs:{linewise:!0,toJumplist:!0}},{keys:["L"],type:"motion",motion:"moveToBottomLine",motionArgs:{linewise:!0,toJumplist:!0}},{keys:["h"],type:"motion",motion:"moveByCharacters",motionArgs:{forward:!1}},{keys:["l"],type:"motion",motion:"moveByCharacters",motionArgs:{forward:!0}},{keys:["j"],type:"motion",motion:"moveByLines",motionArgs:{forward:!0,linewise:!0}},{keys:["k"],type:"motion",motion:"moveByLines",motionArgs:{forward:!1,linewise:!0}},{keys:["g","j"],type:"motion",motion:"moveByDisplayLines",
motionArgs:{forward:!0}},{keys:["g","k"],type:"motion",motion:"moveByDisplayLines",motionArgs:{forward:!1}},{keys:["w"],type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1}},{keys:["W"],type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!1,bigWord:!0}},{keys:["e"],type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,inclusive:!0}},{keys:["E"],type:"motion",motion:"moveByWords",motionArgs:{forward:!0,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:["b"],type:"motion",
motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1}},{keys:["B"],type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1,bigWord:!0}},{keys:["g","e"],type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,inclusive:!0}},{keys:["g","E"],type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,bigWord:!0,inclusive:!0}},{keys:["{"],type:"motion",motion:"moveByParagraph",motionArgs:{forward:!1,toJumplist:!0}},{keys:["}"],type:"motion",motion:"moveByParagraph",
motionArgs:{forward:!0,toJumplist:!0}},{keys:["<C-f>"],type:"motion",motion:"moveByPage",motionArgs:{forward:!0}},{keys:["<C-b>"],type:"motion",motion:"moveByPage",motionArgs:{forward:!1}},{keys:["<C-d>"],type:"motion",motion:"moveByScroll",motionArgs:{forward:!0,explicitRepeat:!0}},{keys:["<C-u>"],type:"motion",motion:"moveByScroll",motionArgs:{forward:!1,explicitRepeat:!0}},{keys:["g","g"],type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0,toJumplist:!0}},
{keys:["G"],type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!0,explicitRepeat:!0,linewise:!0,toJumplist:!0}},{keys:["0"],type:"motion",motion:"moveToStartOfLine"},{keys:["^"],type:"motion",motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:["+"],type:"motion",motion:"moveByLines",motionArgs:{forward:!0,toFirstChar:!0}},{keys:["-"],type:"motion",motion:"moveByLines",motionArgs:{forward:!1,toFirstChar:!0}},{keys:["_"],type:"motion",motion:"moveByLines",motionArgs:{forward:!0,toFirstChar:!0,
repeatOffset:-1}},{keys:["$"],type:"motion",motion:"moveToEol",motionArgs:{inclusive:!0}},{keys:["%"],type:"motion",motion:"moveToMatchedSymbol",motionArgs:{inclusive:!0,toJumplist:!0}},{keys:["f","character"],type:"motion",motion:"moveToCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:["F","character"],type:"motion",motion:"moveToCharacter",motionArgs:{forward:!1}},{keys:["t","character"],type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:["T","character"],
type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!1}},{keys:[";"],type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!0}},{keys:[","],type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!1}},{keys:["'","character"],type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0}},{keys:["`","character"],type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0}},{keys:["]","`"],type:"motion",motion:"jumpToMark",motionArgs:{forward:!0}},{keys:["[","`"],type:"motion",
motion:"jumpToMark",motionArgs:{forward:!1}},{keys:["]","'"],type:"motion",motion:"jumpToMark",motionArgs:{forward:!0,linewise:!0}},{keys:["[","'"],type:"motion",motion:"jumpToMark",motionArgs:{forward:!1,linewise:!0}},{keys:["]","character"],type:"motion",motion:"moveToSymbol",motionArgs:{forward:!0,toJumplist:!0}},{keys:["[","character"],type:"motion",motion:"moveToSymbol",motionArgs:{forward:!1,toJumplist:!0}},{keys:["|"],type:"motion",motion:"moveToColumn",motionArgs:{}},{keys:["d"],type:"operator",
operator:"delete"},{keys:["y"],type:"operator",operator:"yank"},{keys:["c"],type:"operator",operator:"change"},{keys:[">"],type:"operator",operator:"indent",operatorArgs:{indentRight:!0}},{keys:["<"],type:"operator",operator:"indent",operatorArgs:{indentRight:!1}},{keys:["g","~"],type:"operator",operator:"swapcase"},{keys:["n"],type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:!0}},{keys:["N"],type:"motion",motion:"findNext",motionArgs:{forward:!1,toJumplist:!0}},{keys:["x"],type:"operatorMotion",
operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!0},operatorMotionArgs:{visualLine:!1}},{keys:["X"],type:"operatorMotion",operator:"delete",motion:"moveByCharacters",motionArgs:{forward:!1},operatorMotionArgs:{visualLine:!0}},{keys:["D"],type:"operatorMotion",operator:"delete",motion:"moveToEol",motionArgs:{inclusive:!0},operatorMotionArgs:{visualLine:!0}},{keys:["Y"],type:"operatorMotion",operator:"yank",motion:"moveToEol",motionArgs:{inclusive:!0},operatorMotionArgs:{visualLine:!0}},
{keys:["C"],type:"operatorMotion",operator:"change",motion:"moveToEol",motionArgs:{inclusive:!0},operatorMotionArgs:{visualLine:!0}},{keys:["~"],type:"operatorMotion",operator:"swapcase",operatorArgs:{shouldMoveCursor:!0},motion:"moveByCharacters",motionArgs:{forward:!0}},{keys:["<C-i>"],type:"action",action:"jumpListWalk",actionArgs:{forward:!0}},{keys:["<C-o>"],type:"action",action:"jumpListWalk",actionArgs:{forward:!1}},{keys:["<C-e>"],type:"action",action:"scroll",actionArgs:{forward:!0,linewise:!0}},
{keys:["<C-y>"],type:"action",action:"scroll",actionArgs:{forward:!1,linewise:!0}},{keys:["a"],type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"charAfter"}},{keys:["A"],type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"eol"}},{keys:["i"],type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"inplace"}},{keys:["I"],type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"firstNonBlank"}},{keys:["o"],type:"action",action:"newLineAndEnterInsertMode",
isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!0}},{keys:["O"],type:"action",action:"newLineAndEnterInsertMode",isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!1}},{keys:["v"],type:"action",action:"toggleVisualMode"},{keys:["V"],type:"action",action:"toggleVisualMode",actionArgs:{linewise:!0}},{keys:["J"],type:"action",action:"joinLines",isEdit:!0},{keys:["p"],type:"action",action:"paste",isEdit:!0,actionArgs:{after:!0,isEdit:!0}},{keys:["P"],type:"action",action:"paste",isEdit:!0,actionArgs:{after:!1,
isEdit:!0}},{keys:["r","character"],type:"action",action:"replace",isEdit:!0},{keys:["@","character"],type:"action",action:"replayMacro"},{keys:["q","character"],type:"action",action:"enterMacroRecordMode"},{keys:["R"],type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{replace:!0}},{keys:["u"],type:"action",action:"undo"},{keys:["<C-r>"],type:"action",action:"redo"},{keys:["m","character"],type:"action",action:"setMark"},{keys:['"',"character"],type:"action",action:"setRegister"},{keys:["z",
"z"],type:"action",action:"scrollToCursor",actionArgs:{position:"center"}},{keys:["z","."],type:"action",action:"scrollToCursor",actionArgs:{position:"center"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:["z","t"],type:"action",action:"scrollToCursor",actionArgs:{position:"top"}},{keys:["z","<CR>"],type:"action",action:"scrollToCursor",actionArgs:{position:"top"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:["z","-"],type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"}},
{keys:["z","b"],type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:["."],type:"action",action:"repeatLastEdit"},{keys:["<C-a>"],type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!0,backtrack:!1}},{keys:["<C-x>"],type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!1,backtrack:!1}},{keys:["a","character"],type:"motion",motion:"textObjectManipulation"},{keys:["i","character"],type:"motion",
motion:"textObjectManipulation",motionArgs:{textObjectInner:!0}},{keys:["/"],type:"search",searchArgs:{forward:!0,querySrc:"prompt",toJumplist:!0}},{keys:["?"],type:"search",searchArgs:{forward:!1,querySrc:"prompt",toJumplist:!0}},{keys:["*"],type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:["#"],type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:[":"],type:"ex"}],n=m.Pos,Z=function(){function ka(a,b){var c=a.state.vim;if(!c.insertMode&&
!c.exMode){var c=b.ranges[0].head,d=b.ranges[0].anchor;if(c.ch&&c.ch==a.doc.getLine(c.line).length){var e=n(c.line,c.ch-1);b.update([{anchor:r(c,d)?e:d,head:e}])}}}function la(a){var b=a.state.vim;b.onPasteFn||(b.onPasteFn=function(){b.insertMode||(a.setCursor(O(a.getCursor(),0,1)),P.enterInsertMode(a,{},b))});return b.onPasteFn}function $(a,b){for(var c=[],d=a;d<a+b;d++)c.push(String.fromCharCode(d));return c}function ma(a,b){return b>=a.firstLine()&&b<=a.lastLine()}function M(a){return/^[A-Z]$/.test(a)}
function aa(a,b){for(var c=0;c<b.length;c++)if(b[c]==a)return!0;return!1}function ba(a){a.state.vim||(a.state.vim={inputState:new D,lastEditInputState:void 0,lastEditActionCommand:void 0,lastHPos:-1,lastHSPos:-1,lastMotion:null,marks:{},insertMode:!1,insertModeRepeat:void 0,visualMode:!1,visualLine:!1});return a.state.vim}function na(){q={searchQuery:null,searchIsReversed:!1,jumpList:Ga(),macroModeState:Ha(),lastChararacterSearch:{increment:0,forward:!0,selectedCharacter:""},registerController:new oa({})}}
function D(){this.prefixRepeat=[];this.motionRepeat=[];this.motionArgs=this.motion=this.operatorArgs=this.operator=null;this.keyBuffer=[];this.registerName=null}function I(a,b){this.clear();a&&this.set(a,b)}function oa(a){this.registers=a;this.unamedRegister=a['"']=new I}function G(a,b,c){var d=Math.min(Math.max(a.firstLine(),b.line),a.lastLine());a=v(a,d)-1;a=c?a+1:a;b=Math.min(Math.max(0,b.ch),a);return n(d,b)}function Q(a){var b={},c;for(c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function O(a,
b,c){return n(a.line+b,a.ch+c)}function Ia(a,b){for(var c=0;c<a.length;c++)if(a[c]!=b[c]&&"character"!=b[c])return!1;return!0}function pa(a,b,c){return function(){for(var d=0;d<c;d++)b(a)}}function A(a){return n(a.line,a.ch)}function r(a,b){return a.ch==b.ch&&a.line==b.line}function t(a,b){return a.line<b.line||a.line==b.line&&a.ch<b.ch?!0:!1}function qa(a,b,c){a=t(a,b);b=t(b,c);return a&&b}function v(a,b){return a.getLine(b).length}function ca(a){return a.trim?a.trim():a.replace(/^\s+|\s+$/g,"")}
function E(a){a.off("mousedown",E);var b=a.state.vim;b.visualMode=!1;b.visualLine=!1;var b=a.getCursor("anchor"),c=a.getCursor("head");r(b,c)||a.setCursor(G(a,c));m.signal(a,"vim-mode-change",{mode:"normal"})}function y(a){if(!a)return 0;var b=a.search(/\S/);return-1==b?a.length:b}function R(a,b,c,d,e){c=a.getCursor();a=a.getLine(c.line);var f=c.ch,g=a.substring(f);e=e?g.search(/\w/):g.search(/\S/);if(-1==e)return null;f+=e;g=a.substring(f);e=a.substring(0,f);var h;h=d?/^\S+/:/\w/.test(a.charAt(f))?
/^\w+/:/^[^\w\s]+/;g=h.exec(g);d=f;f+=g[0].length;e=e.split("").reverse().join("");(h=h.exec(e))&&(d-=h[0].length);b&&(b=a.substring(f).match(/^\s*/)[0].length,0<b?f+=b:(b=e.substring(e.length-d).match(/^\s*/)[0].length,d-=b));return{start:n(c.line,d),end:n(c.line,f)}}function ra(a,b){q.lastChararacterSearch.increment=a;q.lastChararacterSearch.forward=b.forward;q.lastChararacterSearch.selectedCharacter=b.selectedCharacter}function da(a,b,c,d){for(var e=a.getCursor(),f=e.ch,g,h=0;h<b;h++){g=a.getLine(e.line);
var k=d,l=void 0;g=l=c?g.indexOf(k,f+1):g.lastIndexOf(k,f-1);if(-1==g)return null;f=g}return n(a.getCursor().line,g)}function N(a,b,c,d){aa(c,Ja)&&(b.marks[c]&&b.marks[c].clear(),b.marks[c]=a.setBookmark(d))}function S(a){return"string"===a||"comment"===a?1:0}function ea(a,b,c){var d=b.line,e=b.ch;c=c?c:a.getLine(d).charAt(e);var f=a.getTokenAt(n(d,e+1)).type,f=S(f),g={"(":")",")":"(","[":"]","]":"[","{":"}","}":"{"}[c];if(!g)return b;for(var h={"(":1,"{":1,"[":1}[c]||-1,k=1===h?a.lineCount():-1,
l=1,B=c,m=e,e=a.getLine(d);d!==k&&0<l;){m+=h;B=e.charAt(m);B||(d+=h,e=a.getLine(d)||"",0<h?m=0:(B=e.length,m=0<B?B-1:0),B=e.charAt(m));var p=a.getTokenAt(n(d,m+1)).type,p=S(p);f>=p&&(B===c?l++:B===g&&l--)}return B?n(d,m):b}function sa(){}function x(a){a=a.state.vim;return a.searchState_||(a.searchState_=new sa)}function ta(a){for(var b=!1,c=[],d=0;d<a.length;d++){var e=a.charAt(d);b||"/"!=e||c.push(d);b=!b&&"\\"==e}return c}function ua(a,b){for(var c=!1,d=[],e=-1;e<a.length;e++){for(var f=a.charAt(e)||
"",g=a.charAt(e+1)||"",h=!1,k=0;k<b.length;k++)if(g===b[k]){h=!0;break}c?"\\"===f&&h?c=!0:(d.push(f),c=!1):"\\"===f?(c=!0,h||d.push("\\")):(d.push(f),h&&"\\"!==g&&d.push("\\"))}return d.join("")}function u(a,b){a.openNotification?a.openNotification('<span style="color: red">'+b+"</span>",{bottom:!0,duration:5E3}):alert(b)}function T(a,b){var c=(b.prefix||"")+" "+(b.desc||""),d;d=b.prefix;var e=b.desc,f="";d&&(f+='<span style="font-family: monospace">'+d+"</span>");f+='<input type="text"/> <span style="color: #888">';
e&&(f=f+'<span style="color: #888">'+e,f+="</span>");d=f;e=b.onClose;a.openDialog?a.openDialog(d,e,{bottom:!0,value:b.value,onKeyDown:b.onKeyDown,onKeyUp:b.onKeyUp}):e(prompt(c,""))}function U(a,b,c,d){if(b){var e=x(a);c=!!c;d=!!d;if(!(b instanceof RegExp)){var f=ta(b),g,h;f.length?(g=b.substring(0,f[0]),h=-1!=b.substring(f[0]).indexOf("i")):g=b;g?(g=ua(g,["|","(",")"]),d&&(c=/^[^A-Z]*$/.test(g)),b=RegExp(g,c||h?"i":void 0)):b=null}if(b){va(a,b);a:if(a=e.getQuery(),b instanceof RegExp&&a instanceof
RegExp){h=["global","multiline","ignoreCase","source"];for(c=0;c<h.length;c++)if(d=h[c],b[d]!==a[d]){a=!1;break a}a=!0}else a=!1;if(a)return b;e.setQuery(b);return b}}}function Ka(a){if("^"==a.source.charAt(0))var b=!0;return{token:function(c){if(b&&!c.sol())c.skipToEnd();else{var d=c.match(a,!1);if(d){if(0==d[0].length)return c.next(),"searching";if(!c.sol()&&(c.backUp(1),!a.exec(c.next()+d[0])))return c.next(),null;c.match(a);return"searching"}for(;!c.eol()&&(c.next(),!c.match(a,!1)););}},query:a}}
function va(a,b){var c=x(a).getOverlay();c&&b==c.query||(c&&a.removeOverlay(c),c=Ka(b),a.addOverlay(c),x(a).setOverlay(c))}function wa(a,b,c,d){void 0===d&&(d=1);return a.operation(function(){for(var e=a.getCursor(),f=a.getSearchCursor(c,e),g=0;g<d;g++){var h=f.find(b);0==g&&h&&r(f.from(),e)&&(h=f.find(b));if(!h&&(f=a.getSearchCursor(c,b?n(a.lastLine()):n(a.firstLine(),0)),!f.find(b)))return}return f.from()})}function fa(a){a.removeOverlay(x(a).getOverlay());x(a).setOverlay(null)}function ga(a){var b=
a.getScrollInfo(),c=a.coordsChar({left:0,top:6+b.top},"local");a=a.coordsChar({left:0,top:b.clientHeight-10+b.top},"local");return{top:c.line,bottom:a.line}}function V(a){for(var b,c,d=[];a;){c=/<\w+-.+?>|<\w+>|./.exec(a);if(null===c)break;b=c[0];a=a.substring(c.index+b.length);d.push(b)}return d}function La(a,b,c,d,e,f,g){function h(){a.operation(function(){for(;!p;)k(),l();n()})}function k(){var b=a.getRange(e.from(),e.to()).replace(f,g);e.replace(b)}function l(){if(e.findNext()){var b;b=e.from();
var f=c,g=d;"number"!=typeof b&&(b=b.line);b=f instanceof Array?aa(b,f):g?b>=f&&b<=g:b==f;b?(a.scrollIntoView(e.from(),30),a.setSelection(e.from(),e.to()),s=e.from(),p=!1):p=!0}else p=!0}function n(b){b&&b();a.focus();s&&(a.setCursor(s),b=a.state.vim,b.exMode=!1,b.lastHPos=b.lastHSPos=s.ch)}function F(b,c,d){m.e_stop(b);switch(m.keyName(b)){case "Y":k();l();break;case "N":l();break;case "A":a.operation(h);break;case "L":k();case "Q":case "Esc":case "Ctrl-C":case "Ctrl-[":n(d)}p&&n(d)}a.state.vim.exMode=
!0;var p=!1,s=e.from();l();p?u(a,"No matches for "+f.source):b?T(a,{prefix:"replace with <strong>"+g+"</strong> (y/n/a/q/l)",onKeyDown:F}):h()}function W(a){var b=a.state.vim,c=q.macroModeState.inReplay;c||(a.off("change",xa),a.off("cursorActivity",ya),m.off(a.getInputField(),"keydown",za));!c&&1<b.insertModeRepeat&&(Aa(a,b,b.insertModeRepeat-1,!0),b.lastEditInputState.repeatOverride=b.insertModeRepeat);delete b.insertModeRepeat;a.setCursor(a.getCursor().line,a.getCursor().ch-1);b.insertMode=!1;a.setOption("keyMap",
"vim");a.setOption("disableInput",!0);a.toggleOverwrite(!1);m.signal(a,"vim-mode-change",{mode:"normal"})}function xa(a,b){for(var c=q.macroModeState.lastInsertModeChanges;b;){c.expectCursorActivityForChange=!0;if("+input"==b.origin||"paste"==b.origin||void 0===b.origin){var d=b.text.join("\n");c.changes.push(d)}b=b.next}}function ya(){var a=q.macroModeState.lastInsertModeChanges;a.expectCursorActivityForChange?a.expectCursorActivityForChange=!1:a.changes=[]}function ha(a){this.keyName=a}function za(a){function b(){c.changes.push(new ha(d));
return!0}var c=q.macroModeState.lastInsertModeChanges,d=m.keyName(a);-1==d.indexOf("Delete")&&-1==d.indexOf("Backspace")||m.lookupKey(d,["vim-insert"],b)}function Aa(a,b,c,d){function e(){h?J.processAction(a,b,b.lastEditActionCommand):J.evalInput(a,b)}function f(c){0<g.lastInsertModeChanges.changes.length&&(c=b.lastEditActionCommand?c:1,Ma(a,c,g))}var g=q.macroModeState;g.inReplay=!0;var h=!!b.lastEditActionCommand,k=b.inputState;b.inputState=b.lastEditInputState;if(h&&b.lastEditActionCommand.interlaceInsertRepeat)for(var l=
0;l<c;l++)e(),f(1);else d||e(),f(c);b.inputState=k;b.insertMode&&!d&&W(a);g.inReplay=!1}function Ma(a,b,c){function d(b){if("string"==typeof b)m.commands[b](a);else b(a);return!0}c=c.lastInsertModeChanges;for(var e=0;e<b;e++)for(var f=0;f<c.changes.length;f++){var g=c.changes[f];if(g instanceof ha)m.lookupKey(g.keyName,["vim-insert"],d);else{var h=a.getCursor();a.replaceRange(g,h,h)}}}m.defineOption("vimMode",!1,function(a,b){b?(a.setOption("keyMap","vim"),a.setOption("disableInput",!0),m.signal(a,
"vim-mode-change",{mode:"normal"}),a.on("beforeSelectionChange",ka),ba(a),m.on(a.getInputField(),"paste",la(a))):a.state.vim&&(a.setOption("keyMap","default"),a.setOption("disableInput",!1),a.off("beforeSelectionChange",ka),m.off(a.getInputField(),"paste",la(a)),a.state.vim=null)});var Na=/[\d]/,Oa=[/\w/,/[^\w\s]/],Pa=[/\S/],X=$(65,26),ia=$(97,26),Y=$(48,10),Ba="~`!@#$%^&*()_-+=[{}]\\|/?.,<>:;\"'".split(""),Ca="Left Right Up Down Space Backspace Esc Home End PageUp PageDown Enter".split(" "),Ja=[].concat(X,
ia,Y,["<",">"]),Qa=[].concat(X,ia,Y,["-",'"']),Ga=function(){var a=100,b=-1,c=0,d=0,e=Array(a);return{cachedCursor:void 0,add:function(f,g,h){function k(c){var d=++b%a,g=e[d];g&&g.clear();e[d]=f.setBookmark(c)}var l=e[b%a];l?(l=l.find())&&!r(l,g)&&k(g):k(g);k(h);c=b;d=b-a+1;0>d&&(d=0)},move:function(f,g){b+=g;b>c?b=c:b<d&&(b=d);var h=e[(a+b)%a];if(h&&!h.find()){var k=0<g?1:-1,l,m=f.getCursor();do if(b+=k,(h=e[(a+b)%a])&&(l=h.find())&&!r(m,l))break;while(b<c&&b>d)}return h}}},Ha=function(){return{macroKeyBuffer:[],
latestRegister:void 0,inReplay:!1,lastInsertModeChanges:{changes:[],expectCursorActivityForChange:!1},enteredMacroMode:void 0,isMacroPlaying:!1,toggle:function(a,b){this.enteredMacroMode?(this.enteredMacroMode(),this.enteredMacroMode=void 0):(this.latestRegister=b,this.enteredMacroMode=a.openDialog("(recording)["+b+"]",null,{bottom:!0}))}}},q,Ra={buildKeyMap:function(){},getRegisterController:function(){return q.registerController},resetVimGlobalState_:na,getVimGlobalState_:function(){return q},maybeInitVimState_:ba,
InsertModeKey:ha,map:function(a,b,c){K.map(a,b,c)},defineEx:function(a,b,c){if(0!==a.indexOf(b))throw Error('(Vim.defineEx) "'+b+'" is not a prefix of "'+a+'", command not registered');Da[a]=c;K.commandMap_[b]={name:a,shortName:b,type:"api"}},handleKey:function(a,b){var c,d=ba(a),e=q.macroModeState;if(e.enteredMacroMode&&"q"==b)P.exitMacroRecordMode(),d.inputState=new D;else if("<Esc>"==b)d.inputState=new D,d.visualMode&&E(a);else{d.visualMode||r(a.getCursor("head"),a.getCursor("anchor"))||(d.visualMode=
!0,d.visualLine=!1,m.signal(a,"vim-mode-change",{mode:"visual"}),a.on("mousedown",E));if("0"!=b||"0"==b&&0===d.inputState.getRepeat())c=J.matchCommand(b,ja,d);if(c)if("keyToKey"==c.type)for(d=0;d<c.toKeys.length;d++)this.handleKey(a,c.toKeys[d]);else e.enteredMacroMode&&(e.isMacroPlaying||e.macroKeyBuffer.push(b)),J.processCommand(a,d,c);else Na.test(b)&&d.inputState.pushRepeatDigit(b)}},handleEx:function(a,b){K.processCommand(a,b)}};D.prototype.pushRepeatDigit=function(a){this.operator?this.motionRepeat=
this.motionRepeat.concat(a):this.prefixRepeat=this.prefixRepeat.concat(a)};D.prototype.getRepeat=function(){var a=0;if(0<this.prefixRepeat.length||0<this.motionRepeat.length)a=1,0<this.prefixRepeat.length&&(a*=parseInt(this.prefixRepeat.join(""),10)),0<this.motionRepeat.length&&(a*=parseInt(this.motionRepeat.join(""),10));return a};I.prototype={set:function(a,b){this.text=a;this.linewise=!!b},append:function(a,b){b||this.linewise?(this.text+="\n"+a,this.linewise=!0):this.text+=a},clear:function(){this.text=
"";this.linewise=!1},toString:function(){return this.text}};oa.prototype={pushText:function(a,b,c,d){d&&"\n"==c.charAt(0)&&(c=c.slice(1)+"\n");d&&"\n"!==c.charAt(c.length-1)&&(c+="\n");var e=this.isValidRegister(a)?this.getRegister(a):null;if(e)M(a)?(e.append(c,d),this.unamedRegister.append(c,d)):(e.set(c,d),this.unamedRegister.set(c,d));else{switch(b){case "yank":this.registers["0"]=new I(c,d);break;case "delete":case "change":-1==c.indexOf("\n")?this.registers["-"]=new I(c,d):(this.shiftNumericRegisters_(),
this.registers["1"]=new I(c,d))}this.unamedRegister.set(c,d)}},setRegisterText:function(a,b,c){this.getRegister(a).set(b,c)},getRegister:function(a){if(!this.isValidRegister(a))return this.unamedRegister;a=a.toLowerCase();this.registers[a]||(this.registers[a]=new I);return this.registers[a]},isValidRegister:function(a){return a&&aa(a,Qa)},shiftNumericRegisters_:function(){for(var a=9;2<=a;a--)this.registers[a]=this.getRegister(""+(a-1))}};var J={matchCommand:function(a,b,c){function d(b){if(f.length<
b.keys.length)return e.keyBuffer.push(a),null;"character"==b.keys[f.length-1]&&(e.selectedCharacter=h);e.keyBuffer=[];return b}for(var e=c.inputState,f=e.keyBuffer.concat(a),g=[],h,k=0;k<b.length;k++){var l=b[k];if(Ia(f,l.keys)&&(!e.operator||"action"!=l.type)){if("character"==l.keys[f.length-1]&&(h=f[f.length-1],1<h.length))switch(h){case "<CR>":h="\n";break;case "<Space>":h=" ";break;default:continue}g.push(l)}}if(g.length){if(1==g.length)return d(g[0]);b=c.visualMode?"visual":"normal";for(var m,
k=0;k<g.length;k++)if(c=g[k],c.context==b){m=c;break}else m||c.context||(m=c);return d(m)}e.keyBuffer=[];return null},processCommand:function(a,b,c){b.inputState.repeatOverride=c.repeatOverride;switch(c.type){case "motion":this.processMotion(a,b,c);break;case "operator":this.processOperator(a,b,c);break;case "operatorMotion":this.processOperatorMotion(a,b,c);break;case "action":this.processAction(a,b,c);break;case "search":this.processSearch(a,b,c);break;case "ex":case "keyToEx":this.processEx(a,
b,c)}},processMotion:function(a,b,c){b.inputState.motion=c.motion;b.inputState.motionArgs=Q(c.motionArgs);this.evalInput(a,b)},processOperator:function(a,b,c){var d=b.inputState;if(d.operator){if(d.operator==c.operator){d.motion="expandToLine";d.motionArgs={linewise:!0};this.evalInput(a,b);return}b.inputState=new D}d.operator=c.operator;d.operatorArgs=Q(c.operatorArgs);b.visualMode&&this.evalInput(a,b)},processOperatorMotion:function(a,b,c){var d=b.visualMode,e=Q(c.operatorMotionArgs);e&&d&&e.visualLine&&
(b.visualLine=!0);this.processOperator(a,b,c);d||this.processMotion(a,b,c)},processAction:function(a,b,c){var d=b.inputState,e=d.getRepeat(),f=!!e,g=Q(c.actionArgs)||{};d.selectedCharacter&&(g.selectedCharacter=d.selectedCharacter);c.operator&&this.processOperator(a,b,c);c.motion&&this.processMotion(a,b,c);(c.motion||c.operator)&&this.evalInput(a,b);g.repeat=e||1;g.repeatIsExplicit=f;g.registerName=d.registerName;b.inputState=new D;b.lastMotion=null;c.isEdit&&this.recordLastEdit(b,d,c);P[c.action](a,
g,b)},processSearch:function(a,b,c){function d(d,e,f){try{U(a,d,e,f)}catch(g){u(a,"Invalid regex: "+d);return}J.processMotion(a,b,{type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:c.searchArgs.toJumplist}})}function e(b){a.scrollTo(n.left,n.top);d(b,!0,!0)}function f(b,c){var d;try{d=U(a,c,!0,!0)}catch(e){}d?a.scrollIntoView(wa(a,!h,d),30):(fa(a),a.scrollTo(n.left,n.top))}function g(b,c,d){c=m.keyName(b);if("Esc"==c||"Ctrl-C"==c||"Ctrl-["==c)U(a,l),fa(a),a.scrollTo(n.left,n.top),
m.e_stop(b),d(),a.focus()}if(a.getSearchCursor){var h=c.searchArgs.forward;x(a).setReversed(!h);var k=h?"/":"?",l=x(a).getQuery(),n=a.getScrollInfo();switch(c.searchArgs.querySrc){case "prompt":T(a,{onClose:e,prefix:k,desc:Sa,onKeyUp:f,onKeyDown:g});break;case "wordUnderCursor":var k=R(a,!1,!0,!1,!0),F=!0;k||(k=R(a,!1,!0,!1,!1),F=!1);if(!k)break;var p=a.getLine(k.start.line).substring(k.start.ch,k.end.ch),p=F?"\\b"+p+"\\b":p.replace(/([.?*+$\[\]\/\\(){}|\-])/g,"\\$1");q.jumpList.cachedCursor=a.getCursor();
a.setCursor(k.start);d(p,!0,!1)}}},processEx:function(a,b,c){function d(b){K.processCommand(a,b)}function e(b,c,d){c=m.keyName(b);if("Esc"==c||"Ctrl-C"==c||"Ctrl-["==c)m.e_stop(b),d(),a.focus()}"keyToEx"==c.type?K.processCommand(a,c.exArgs.input):b.visualMode?T(a,{onClose:d,prefix:":",value:"'<,'>",onKeyDown:e}):T(a,{onClose:d,prefix:":",onKeyDown:e})},evalInput:function(a,b){var c=b.inputState,d=c.motion,e=c.motionArgs||{},f=c.operator,g=c.operatorArgs||{},h=c.registerName,k=A(a.getCursor("head")),
l=A(a.getCursor("anchor")),m=A(k),F=A(m),p,s;f&&this.recordLastEdit(b,c);s=void 0!==c.repeatOverride?c.repeatOverride:c.getRepeat();if(0<s&&e.explicitRepeat)e.repeatIsExplicit=!0;else if(e.noRepeat||!e.explicitRepeat&&0===s)s=1,e.repeatIsExplicit=!1;c.selectedCharacter&&(e.selectedCharacter=g.selectedCharacter=c.selectedCharacter);e.repeat=s;b.inputState=new D;if(d){p=L[d](a,e,b);b.lastMotion=L[d];if(!p)return;e.toJumplist&&(d=q.jumpList,(c=d.cachedCursor)?(r(c,p)||q.jumpList.add(a,c,p),delete d.cachedCursor):
r(F,p)||q.jumpList.add(a,F,p));p instanceof Array&&(m=p[0],p=p[1]);p||(p=n(m.line,m.ch));b.visualMode?(t(l,k)&&(r(l,p)||t(p,l))?l.ch+=1:t(k,l)&&(r(l,p)||t(l,p))&&(l.ch-=1),k=p,b.visualLine&&(t(l,k)?(l.ch=0,d=a.lastLine(),k.line>d&&(k.line=d),k.ch=v(a,k.line)):(k.ch=0,l.ch=v(a,l.line))),a.setSelection(l,k),N(a,b,"<",t(l,k)?l:k),N(a,b,">",t(l,k)?k:l)):f||(p=G(a,p),a.setCursor(p.line,p.ch))}if(f){d=!1;b.lastMotion=null;g.repeat=s;b.visualMode&&(m=l,p=k,e.inclusive=!0);t(p,m)&&(k=m,m=p,p=k,d=!0);!e.inclusive||
b.visualMode&&d||p.ch++;if(k=e.linewise||b.visualMode&&b.visualLine)e=p,m.ch=0,e.ch=0,e.line++;else if(e.forward&&(e=p,l=a.getRange(m,e),/\n\s*$/.test(l))){l=l.split("\n");l.pop();for(s=l.pop();0<l.length&&s&&/^\s*$/.test(s);s=l.pop())e.line--,e.ch=0;s?(e.line--,e.ch=v(a,e.line)):e.ch=0}g.registerName=h;g.linewise=k;Ta[f](a,g,b,m,p,F);b.visualMode&&E(a)}},recordLastEdit:function(a,b,c){var d=q.macroModeState;d.inReplay||(a.lastEditInputState=b,a.lastEditActionCommand=c,d.lastInsertModeChanges.changes=
[],d.lastInsertModeChanges.expectCursorActivityForChange=!1)}},L={moveToTopLine:function(a,b){var c=ga(a).top+b.repeat-1;return n(c,y(a.getLine(c)))},moveToMiddleLine:function(a){var b=ga(a),b=Math.floor(0.5*(b.top+b.bottom));return n(b,y(a.getLine(b)))},moveToBottomLine:function(a,b){var c=ga(a).bottom-b.repeat+1;return n(c,y(a.getLine(c)))},expandToLine:function(a,b){var c=a.getCursor();return n(c.line+b.repeat-1,Infinity)},findNext:function(a,b){var c=x(a),d=c.getQuery();if(d){var e=!b.forward,
e=c.isReversed()?!e:e;va(a,d);return wa(a,e,d,b.repeat)}},goToMark:function(a,b,c){return(a=c.marks[b.selectedCharacter])?a.find():null},jumpToMark:function(a,b,c){for(var d=a.getCursor(),e=0;e<b.repeat;e++){var f=d,g;for(g in c.marks)if(/^[a-z]$/.test(g)){var h=c.marks[g].find();if(b.forward?!t(h,f):!t(f,h))if(!b.linewise||h.line!=f.line){var k=r(f,d),l=b.forward?qa(f,h,d):qa(d,h,f);if(k||l)d=h}}}b.linewise&&(d=n(d.line,y(a.getLine(d.line))));return d},moveByCharacters:function(a,b){var c=a.getCursor(),
d=b.repeat;return n(c.line,b.forward?c.ch+d:c.ch-d)},moveByLines:function(a,b,c){var d=a.getCursor(),e=d.ch;switch(c.lastMotion){case this.moveByLines:case this.moveByDisplayLines:case this.moveByScroll:case this.moveToColumn:case this.moveToEol:e=c.lastHPos;break;default:c.lastHPos=e}var f=b.repeat+(b.repeatOffset||0),f=b.forward?d.line+f:d.line-f,g=a.firstLine(),h=a.lastLine();if(!(f<g&&d.line==g||f>h&&d.line==h))return b.toFirstChar&&(e=y(a.getLine(f)),c.lastHPos=e),c.lastHSPos=a.charCoords(n(f,
e),"div").left,n(f,e)},moveByDisplayLines:function(a,b,c){var d=a.getCursor();switch(c.lastMotion){case this.moveByDisplayLines:case this.moveByScroll:case this.moveByLines:case this.moveToColumn:case this.moveToEol:break;default:c.lastHSPos=a.charCoords(d,"div").left}var e=b.repeat,d=a.findPosV(d,b.forward?e:-e,"line",c.lastHSPos);d.hitSide&&(b.forward?b={top:a.charCoords(d,"div").top+8,left:c.lastHSPos}:(b=a.charCoords(n(a.firstLine(),0),"div"),b.left=c.lastHSPos),d=a.coordsChar(b,"div"));c.lastHPos=
d.ch;return d},moveByPage:function(a,b){var c=a.getCursor(),d=b.repeat;a.moveV(b.forward?d:-d,"page");d=a.getCursor();a.setCursor(c);return d},moveByParagraph:function(a,b){for(var c=a.getCursor().line,d=b.repeat,e=b.forward?1:-1,f=0;f<d&&!(!b.forward&&c===a.firstLine()||b.forward&&c==a.lastLine());f++)for(c+=e;c!==a.firstLine()&&c!=a.lastLine()&&a.getLine(c);)c+=e;return n(c,0)},moveByScroll:function(a,b,c){var d=a.getScrollInfo(),e=null;(e=b.repeat)||(e=d.clientHeight/(2*a.defaultTextHeight()));
var f=a.charCoords(a.getCursor(),"local");b.repeat=e;e=L.moveByDisplayLines(a,b,c);if(!e)return null;b=a.charCoords(e,"local");a.scrollTo(null,d.top+b.top-f.top);return e},moveByWords:function(a,b){var c;var d=b.repeat;c=!!b.forward;var e=!!b.wordEnd,f=!!b.bigWord,g=a.getCursor(),h=A(g),k=[];(c&&!e||!c&&e)&&d++;for(var l=!(c&&e),m=0;m<d;m++){var q;b:{q=a;var p=c,s=f,t=l,w=g.line,z=g.ch,C=q.getLine(w),H=p?1:-1,s=s?Pa:Oa;if(t&&""==C){w+=H;C=q.getLine(w);if(!ma(q,w)){q=null;break b}z=p?0:C.length}for(;;){if(t&&
""==C){q={from:0,to:0,line:w};break b}for(var u=p=0<H?C.length:-1,r=p;z!=p;){for(var y=!1,x=0;x<s.length&&!y;++x)if(s[x].test(C.charAt(z))){for(u=z;z!=p&&s[x].test(C.charAt(z));)z+=H;r=z;y=u!=r;if(u!=g.ch||w!=g.line||r!=u+H){q={from:Math.min(u,r+1),to:Math.max(u,r),line:w};break b}}y||(z+=H)}w+=H;if(!ma(q,w)){q=null;break b}C=q.getLine(w);z=0<H?0:C.length}throw Error("The impossible happened.");}if(!q){f=v(a,a.lastLine());k.push(c?{line:a.lastLine(),from:f,to:f}:{line:0,from:0,to:0});break}k.push(q);
g=n(q.line,c?q.to-1:q.from)}d=k.length!=d;f=k[0];l=k.pop();c&&!e?(d||f.from==h.ch&&f.line==h.line||(l=k.pop()),c=n(l.line,l.from)):c&&e?c=n(l.line,l.to-1):!c&&e?(d||f.to==h.ch&&f.line==h.line||(l=k.pop()),c=n(l.line,l.to)):c=n(l.line,l.from);return c},moveTillCharacter:function(a,b){var c=da(a,b.repeat,b.forward,b.selectedCharacter),d=b.forward?-1:1;ra(d,b);if(!c)return null;c.ch+=d;return c},moveToCharacter:function(a,b){var c=b.repeat;ra(0,b);return da(a,c,b.forward,b.selectedCharacter)||a.getCursor()},
moveToSymbol:function(a,b){var c;c=b.repeat;var d=b.forward,e=b.selectedCharacter,f=A(a.getCursor()),g=d?1:-1,h=d?a.lineCount():-1,k=f.ch,l=f.line,m=a.getLine(l),d={lineText:m,nextCh:m.charAt(k),lastCh:null,index:k,symb:e,reverseSymb:(d?{")":"(","}":"{"}:{"(":")","{":"}"})[e],forward:d,depth:0,curMoveThrough:!1};if(k=Ua[e]){e=Ea[k].init;k=Ea[k].isComplete;for(e&&e(d);l!==h&&c;)d.index+=g,d.nextCh=d.lineText.charAt(d.index),d.nextCh||(l+=g,d.lineText=a.getLine(l)||"",0<g?d.index=0:(e=d.lineText.length,
d.index=0<e?e-1:0),d.nextCh=d.lineText.charAt(d.index)),k(d)&&(f.line=l,f.ch=d.index,c--);c=d.nextCh||d.curMoveThrough?n(l,d.index):f}else c=f;return c||a.getCursor()},moveToColumn:function(a,b,c){b=b.repeat;c.lastHPos=b-1;c.lastHSPos=a.charCoords(a.getCursor(),"div").left;c=a.getCursor().line;return G(a,n(c,b-1))},moveToEol:function(a,b,c){var d=a.getCursor();c.lastHPos=Infinity;b=n(d.line+b.repeat-1,Infinity);d=a.clipPos(b);d.ch--;c.lastHSPos=a.charCoords(d,"div").left;return b},moveToFirstNonWhiteSpaceCharacter:function(a){var b=
a.getCursor();return n(b.line,y(a.getLine(b.line)))},moveToMatchedSymbol:function(a){var b=a.getCursor(),c=b.line,d=b.ch,e=a.getLine(c),f;f=a.getTokenAt(b).type;var g=S(f);do if((f=e.charAt(d++))&&-1!="()[]{}".indexOf(f)){var h=a.getTokenAt(n(c,d)).type,h=S(h);if(g>=h)break}while(f);return f?ea(a,n(c,d-1),f):b},moveToStartOfLine:function(a){a=a.getCursor();return n(a.line,0)},moveToLineOrEdgeOfDocument:function(a,b){var c=b.forward?a.lastLine():a.firstLine();b.repeatIsExplicit&&(c=b.repeat-a.getOption("firstLineNumber"));
return n(c,y(a.getLine(c)))},textObjectManipulation:function(a,b){var c={"(":")",")":"(","{":"}","}":"{","[":"]","]":"["},d={"'":!0,'"':!0},e=b.selectedCharacter,f=!b.textObjectInner;if(c[e]){var e=c[e],g=A(a.getCursor()),e=ea(a,g,e),g=ea(a,e);if(g.line==e.line&&g.ch>e.ch||g.line>e.line)var h=g,g=e,e=h;f?e.ch+=1:g.ch+=1;f={start:g,end:e}}else if(d[e]){var c=A(a.getCursor()),d=a.getLine(c.line).split(""),k,l;k=d.indexOf(e);c.ch<k?c.ch=k:k<c.ch&&d[c.ch]==e&&(h=c.ch,--c.ch);if(d[c.ch]!=e||h)for(k=c.ch;-1<
k&&!g;k--)d[k]==e&&(g=k+1);else g=c.ch+1;if(g&&!h)for(k=g,l=d.length;k<l&&!h;k++)d[k]==e&&(h=k);g&&h?(f&&(--g,++h),f={start:n(c.line,g),end:n(c.line,h)}):f={start:c,end:c}}else if("W"===e)f=R(a,f,!0,!0);else if("w"===e)f=R(a,f,!0,!1);else return null;return[f.start,f.end]},repeatLastCharacterSearch:function(a,b){var c=q.lastChararacterSearch,d=b.repeat,e=b.forward===c.forward,f=(c.increment?1:0)*(e?-1:1);a.moveH(-f,"char");b.inclusive=e?!0:!1;c=da(a,d,e,c.selectedCharacter);if(!c)return a.moveH(f,
"char"),a.getCursor();c.ch+=f;return c}},Ta={change:function(a,b,c,d,e){q.registerController.pushText(b.registerName,"change",a.getRange(d,e),b.linewise);b.linewise?(b=e.line>a.lastLine()?"":"\n",a.replaceRange(b,d,e),a.indentLine(d.line,"smart"),d.ch=null):(b=a.getRange(d,e),/^\s*$/.test(b)||(b=/\s+$/.exec(b))&&(e=O(e,0,-b[0].length)),a.replaceRange("",d,e));P.enterInsertMode(a,{},a.state.vim);a.setCursor(d)},"delete":function(a,b,c,d,e){b.linewise&&e.line>a.lastLine()&&d.line>a.firstLine()&&(d.line--,
d.ch=v(a,d.line));q.registerController.pushText(b.registerName,"delete",a.getRange(d,e),b.linewise);a.replaceRange("",d,e);b.linewise?a.setCursor(L.moveToFirstNonWhiteSpaceCharacter(a)):a.setCursor(d)},indent:function(a,b,c,d,e){var f=d.line;e=e.line;c=c.visualMode?b.repeat:1;for(b.linewise&&e--;f<=e;f++)for(var g=0;g<c;g++)a.indentLine(f,b.indentRight);a.setCursor(d);a.setCursor(L.moveToFirstNonWhiteSpaceCharacter(a))},swapcase:function(a,b,c,d,e,f){c=a.getRange(d,e);for(var g="",h=0;h<c.length;h++)var k=
c.charAt(h),g=g+(M(k)?k.toLowerCase():k.toUpperCase());a.replaceRange(g,d,e);b.shouldMoveCursor||a.setCursor(f)},yank:function(a,b,c,d,e,f){q.registerController.pushText(b.registerName,"yank",a.getRange(d,e),b.linewise);a.setCursor(f)}},P={jumpListWalk:function(a,b,c){c.visualMode||(c=b.repeat,b=(b=(b=q.jumpList.move(a,b.forward?c:-c))?b.find():void 0)?b:a.getCursor(),a.setCursor(b))},scroll:function(a,b,c){if(!c.visualMode){var d=b.repeat||1;c=a.defaultTextHeight();var e=a.getScrollInfo().top,d=
c*d,e=b.forward?e+d:e-d,d=A(a.getCursor()),f=a.charCoords(d,"local");b.forward?e>f.top?(d.line+=(e-f.top)/c,d.line=Math.ceil(d.line),a.setCursor(d),f=a.charCoords(d,"local"),a.scrollTo(null,f.top)):a.scrollTo(null,e):(b=e+a.getScrollInfo().clientHeight,b<f.bottom?(d.line-=(f.bottom-b)/c,d.line=Math.floor(d.line),a.setCursor(d),f=a.charCoords(d,"local"),a.scrollTo(null,f.bottom-a.getScrollInfo().clientHeight)):a.scrollTo(null,e))}},scrollToCursor:function(a,b){var c=a.getCursor().line,d=a.charCoords(n(c,
0),"local"),c=a.getScrollInfo().clientHeight,e=d.top,d=d.bottom-e;switch(b.position){case "center":e=e-c/2+d;break;case "bottom":e=e-c+1.4*d;break;case "top":e+=0.4*d}a.scrollTo(null,e)},replayMacro:function(a,b){var c=b.selectedCharacter,d=b.repeat,e=q.macroModeState;"@"==c&&(c=e.latestRegister);var f,g,h=q.registerController.getRegister(c).toString(),c=e.macroKeyBuffer;e.isMacroPlaying||(e.macroKeyBuffer.length=0);do{f=/<\w+-.+?>|<\w+>|./.exec(h);if(null===f)break;g=f[0];h=h.substring(f.index+g.length);
c.push(g)}while(h);for(;d--;){f=a;g=e;h=c;g.isMacroPlaying=!0;for(var k=0,l=h.length;k<l;k++)m.Vim.handleKey(f,h[k]);g.isMacroPlaying=!1}},exitMacroRecordMode:function(){var a=q.macroModeState;a.toggle();var b=a.latestRegister,a=a.macroKeyBuffer.join("");q.registerController.setRegisterText(b,a)},enterMacroRecordMode:function(a,b){var c=q.macroModeState;c.toggle(a,b.selectedCharacter);c.isMacroPlaying||(c.macroKeyBuffer.length=0)},enterInsertMode:function(a,b,c){a.getOption("readOnly")||(c.insertMode=
!0,c.insertModeRepeat=b&&b.repeat||1,c=b?b.insertAt:null,"eol"==c?(c=a.getCursor(),c=n(c.line,v(a,c.line)),a.setCursor(c)):"charAfter"==c?a.setCursor(O(a.getCursor(),0,1)):"firstNonBlank"==c&&a.setCursor(L.moveToFirstNonWhiteSpaceCharacter(a)),a.setOption("keyMap","vim-insert"),a.setOption("disableInput",!1),b&&b.replace?(a.toggleOverwrite(!0),a.setOption("keyMap","vim-replace"),m.signal(a,"vim-mode-change",{mode:"replace"})):(a.setOption("keyMap","vim-insert"),m.signal(a,"vim-mode-change",{mode:"insert"})),
q.macroModeState.inReplay||(a.on("change",xa),a.on("cursorActivity",ya),m.on(a.getInputField(),"keydown",za)))},toggleVisualMode:function(a,b,c){var d=b.repeat,e=a.getCursor();c.visualMode?(e=a.getCursor("anchor"),d=a.getCursor("head"),!c.visualLine&&b.linewise?(c.visualLine=!0,e.ch=t(e,d)?0:v(a,e.line),d.ch=t(e,d)?v(a,d.line):0,a.setSelection(e,d),m.signal(a,"vim-mode-change",{mode:"visual",subMode:"linewise"})):c.visualLine&&!b.linewise?(c.visualLine=!1,m.signal(a,"vim-mode-change",{mode:"visual"})):
E(a)):(a.on("mousedown",E),c.visualMode=!0,c.visualLine=!!b.linewise,c.visualLine?(e.ch=0,d=G(a,n(e.line+d-1,v(a,e.line)),!0)):d=G(a,n(e.line,e.ch+d),!0),b.repeatIsExplicit||c.visualLine?a.setSelection(e,d):(a.setCursor(d),a.setSelection(d,e)),m.signal(a,"vim-mode-change",{mode:"visual",subMode:c.visualLine?"linewise":""}));N(a,c,"<",t(e,d)?e:d);N(a,c,">",t(e,d)?d:e)},joinLines:function(a,b,c){var d,e;c.visualMode?(d=a.getCursor("anchor"),e=a.getCursor("head"),e.ch=v(a,e.line)-1):(b=Math.max(b.repeat,
2),d=a.getCursor(),e=G(a,n(d.line+b-1,Infinity)));var f=0;a.operation(function(){for(var b=d.line;b<e.line;b++){f=v(a,d.line);var c=n(d.line+1,v(a,d.line+1)),k=a.getRange(d,c),k=k.replace(/\n\s*/g," ");a.replaceRange(k,d,c)}b=n(d.line,f);a.setCursor(b)})},newLineAndEnterInsertMode:function(a,b,c){c.insertMode=!0;var d=A(a.getCursor());d.line!==a.firstLine()||b.after?(d.line=b.after?d.line:d.line-1,d.ch=v(a,d.line),a.setCursor(d),(m.commands.newlineAndIndentContinueComment||m.commands.newlineAndIndent)(a)):
(a.replaceRange("\n",n(a.firstLine(),0)),a.setCursor(a.firstLine(),0));this.enterInsertMode(a,{repeat:b.repeat},c)},paste:function(a,b){var c=A(a.getCursor()),d=q.registerController.getRegister(b.registerName);if(d.text){for(var e="",f=0;f<b.repeat;f++)e+=d.text;(d=d.linewise)?b.after?(e="\n"+e.slice(0,e.length-1),c.ch=v(a,c.line)):c.ch=0:c.ch+=b.after?1:0;a.replaceRange(e,c);d&&b.after?e=n(c.line+1,y(a.getLine(c.line+1))):d&&!b.after?e=n(c.line,y(a.getLine(c.line))):!d&&b.after?(c=a.indexFromPos(c),
e=a.posFromIndex(c+e.length-1)):(c=a.indexFromPos(c),e=a.posFromIndex(c+e.length));a.setCursor(e)}},undo:function(a,b){a.operation(function(){pa(a,m.commands.undo,b.repeat)();a.setCursor(a.getCursor("anchor"))})},redo:function(a,b){pa(a,m.commands.redo,b.repeat)()},setRegister:function(a,b,c){c.inputState.registerName=b.selectedCharacter},setMark:function(a,b,c){N(a,c,b.selectedCharacter,a.getCursor())},replace:function(a,b,c){var d=b.selectedCharacter,e=a.getCursor(),f;c.visualMode?(e=a.getCursor("start"),
f=a.getCursor("end"),f=a.clipPos(n(f.line,f.ch+1))):(f=a.getLine(e.line),b=e.ch+b.repeat,b>f.length&&(b=f.length),f=n(e.line,b));"\n"==d?(c.visualMode||a.replaceRange("",e,f),(m.commands.newlineAndIndentContinueComment||m.commands.newlineAndIndent)(a)):(b=a.getRange(e,f),b=b.replace(/[^\n]/g,d),a.replaceRange(b,e,f),c.visualMode?(a.setCursor(e),E(a)):a.setCursor(O(f,0,-1)))},incrementNumberToken:function(a,b){for(var c=a.getCursor(),d=a.getLine(c.line),e=/-?\d+/g,f,g,h,k;null!==(f=e.exec(d))&&!(k=
f[0],g=f.index,h=g+k.length,c.ch<h););!b.backtrack&&h<=c.ch||!k||(d=b.increase?1:-1,d=parseInt(k)+d*b.repeat,k=n(c.line,g),h=n(c.line,h),d=d.toString(),a.replaceRange(d,k,h),a.setCursor(n(c.line,g+d.length-1)))},repeatLastEdit:function(a,b,c){if(c.lastEditInputState){var d=b.repeat;d&&b.repeatIsExplicit?c.lastEditInputState.repeatOverride=d:d=c.lastEditInputState.repeatOverride||d;Aa(a,c,d,!1)}}},Ua={"(":"bracket",")":"bracket","{":"bracket","}":"bracket","[":"section","]":"section","*":"comment",
"/":"comment",m:"method",M:"method","#":"preprocess"},Ea={bracket:{isComplete:function(a){if(a.nextCh===a.symb){if(a.depth++,1<=a.depth)return!0}else a.nextCh===a.reverseSymb&&a.depth--;return!1}},section:{init:function(a){a.curMoveThrough=!0;a.symb=(a.forward?"]":"[")===a.symb?"{":"}"},isComplete:function(a){return 0===a.index&&a.nextCh===a.symb}},comment:{isComplete:function(a){var b="*"===a.lastCh&&"/"===a.nextCh;a.lastCh=a.nextCh;return b}},method:{init:function(a){a.symb="m"===a.symb?"{":"}";
a.reverseSymb="{"===a.symb?"}":"{"},isComplete:function(a){return a.nextCh===a.symb?!0:!1}},preprocess:{init:function(a){a.index=0},isComplete:function(a){if("#"===a.nextCh){var b=a.lineText.match(/#(\w+)/)[1];if("endif"===b){if(a.forward&&0===a.depth)return!0;a.depth++}else if("if"===b){if(!a.forward&&0===a.depth)return!0;a.depth--}if("else"===b&&0===a.depth)return!0}return!1}}};sa.prototype={getQuery:function(){return q.query},setQuery:function(a){q.query=a},getOverlay:function(){return this.searchOverlay},
setOverlay:function(a){this.searchOverlay=a},isReversed:function(){return q.isReversed},setReversed:function(a){q.isReversed=a}};var Sa="(Javascript regexp)",Fa=[{name:"map"},{name:"nmap",shortName:"nm"},{name:"vmap",shortName:"vm"},{name:"saveI",shortName:"w!",type:"builtIn"},{name:"save",shortName:"w",type:"builtIn"},{name:"closeI",shortName:"q!",type:"builtIn"},{name:"close",shortName:"q",type:"builtIn"},{name:"saveAndCloseI",shortName:"wq!",type:"builtIn"},{name:"saveAndClose",shortName:"wq",
type:"builtIn"},{name:"undo",shortName:"u"},{name:"redo",shortName:"red"},{name:"sort",shortName:"sor"},{name:"substitute",shortName:"s"},{name:"nohlsearch",shortName:"noh"},{name:"delmarks",shortName:"delm"}];Z.ExCommandDispatcher=function(){this.buildCommandMap_()};Z.ExCommandDispatcher.prototype={processCommand:function(a,b){a.state.vim.visualMode&&E(a);var c=new m.StringStream(b),d={};d.input=b;try{this.parseInput_(a,c,d)}catch(e){u(a,e);return}var f;if(d.commandName){var g=this.matchCommand_(d.commandName);
if(g){f=g.name;this.parseCommandArgs_(c,d,g);if("exToKey"==g.type){for(c=0;c<g.toKeys.length;c++)m.Vim.handleKey(a,g.toKeys[c]);return}if("exToEx"==g.type){this.processCommand(a,g.toInput);return}}}else void 0!==d.line&&(f="move");if(f)try{Da[f](a,d)}catch(h){throw u(a,h),h;}else u(a,'Not an editor command ":'+b+'"')},parseInput_:function(a,b,c){b.eatWhile(":");b.eat("%")?(c.line=a.firstLine(),c.lineEnd=a.lastLine()):(c.line=this.parseLineSpec_(a,b),void 0!==c.line&&b.eat(",")&&(c.lineEnd=this.parseLineSpec_(a,
b)));a=b.match(/^(\w+)/);c.commandName=a?a[1]:b.match(/.*/)[0];return c},parseLineSpec_:function(a,b){var c=b.match(/^(\d+)/);if(c)return parseInt(c[1],10)-1;switch(b.next()){case ".":return a.getCursor().line;case "$":return a.lastLine();case "'":if((c=a.state.vim.marks[b.next()])&&c.find())return c.find().line;throw Error("Mark not set");default:b.backUp(1)}},parseCommandArgs_:function(a,b,c){a.eol()||(b.argString=a.match(/.*/)[0],a=c.argDelimiter||/\s+/,a=ca(b.argString).split(a),a.length&&a[0]&&
(b.args=a))},matchCommand_:function(a){for(var b=a.length;0<b;b--){var c=a.substring(0,b);if(this.commandMap_[c]&&(c=this.commandMap_[c],0===c.shortName.indexOf(a)))return c}return null},buildCommandMap_:function(){this.commandMap_={};for(var a=0;a<Fa.length;a++){var b=Fa[a];this.commandMap_[b.shortName||b.name]=b}},map:function(a,b,c){if(":"!=a&&":"==a.charAt(0)){if(c)throw Error("Mode not supported for ex mappings");c=a.substring(1);":"!=b&&":"==b.charAt(0)?this.commandMap_[c]={name:c,type:"exToEx",
toInput:b.substring(1)}:this.commandMap_[c]={name:c,type:"exToKey",toKeys:V(b)}}else b=":"!=b&&":"==b.charAt(0)?{keys:V(a),type:"keyToEx",exArgs:{input:b.substring(1)}}:{keys:V(a),type:"keyToKey",toKeys:V(b)},c&&(b.context=c),ja.unshift(b)}};var Da={map:function(a,b,c){var d=b.args;!d||2>d.length?a&&u(a,"Invalid mapping: "+b.input):K.map(d[0],d[1],c)},nmap:function(a,b){this.map(a,b,"normal")},vmap:function(a,b){this.map(a,b,"visual")},move:function(a,b){J.processCommand(a,a.state.vim,{type:"motion",
motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0},repeatOverride:b.line+1})},sort:function(a,b){function c(a,b){if(d){var c;c=a;a=b;b=c}e&&(a=a.toLowerCase(),b=b.toLowerCase());c=g&&q.exec(a);var f=g&&q.exec(b);if(!c)return a<b?-1:1;c=parseInt((c[1]+c[2]).toLowerCase(),t);f=parseInt((f[1]+f[2]).toLowerCase(),t);return c-f}var d,e,f,g,h=function(){if(b.argString){var a=new m.StringStream(b.argString);a.eat("!")&&(d=!0);if(!a.eol()){if(!a.eatSpace())return"Invalid arguments";
var c=a.match(/[a-z]+/);if(c){c=c[0];e=-1!=c.indexOf("i");f=-1!=c.indexOf("u");var h=-1!=c.indexOf("d")&&1,k=-1!=c.indexOf("x")&&1,c=-1!=c.indexOf("o")&&1;if(1<h+k+c)return"Invalid arguments";g=h&&"decimal"||k&&"hex"||c&&"octal"}a.eatSpace()&&a.match(/\/.*\//)&&"patterns not supported"}}}();if(h)u(a,h+": "+b.argString);else{var h=b.line||a.firstLine(),k=b.lineEnd||b.line||a.lastLine();if(h!=k){var h=n(h,0),k=n(k,v(a,k)),l=a.getRange(h,k).split("\n"),q="decimal"==g?/(-?)([\d]+)/:"hex"==g?/(-?)(?:0x)?([0-9a-f]+)/i:
"octal"==g?/([0-7]+)/:null,t="decimal"==g?10:"hex"==g?16:"octal"==g?8:null,p=[],s=[];if(g)for(var r=0;r<l.length;r++)q.exec(l[r])?p.push(l[r]):s.push(l[r]);else s=l;p.sort(c);s.sort(c);l=d?p.concat(s):s.concat(p);if(f)for(var p=l,w,l=[],r=0;r<p.length;r++)p[r]!=w&&l.push(p[r]),w=p[r];a.replaceRange(l.join("\n"),h,k)}}},substitute:function(a,b){if(!a.getSearchCursor)throw Error("Search feature not available. Requires searchcursor.js or any other getSearchCursor implementation.");var c=b.argString,
d=ta(c);if(0!==d[0])u(a,"Substitutions should be of the form :s/pattern/replace/");else{var e=c.substring(d[0]+1,d[1]),f="",g,h,k=!1;d[1]&&(f=c.substring(d[1]+1,d[2]),f=ua(f,["\\","/"]));d[2]&&(h=c.substring(d[2]+1).split(" "),g=h[0],h=parseInt(h[1]));g&&(-1!=g.indexOf("c")&&(k=!0,g.replace("c","")),e=e+"/"+g);if(e)try{U(a,e,!0,!0)}catch(l){u(a,"Invalid regex: "+e);return}e=x(a).getQuery();g=void 0!==b.line?b.line:a.getCursor().line;c=b.lineEnd||g;h&&(g=c,c=g+h-1);h=G(a,n(g,0));h=a.getSearchCursor(e,
h);La(a,k,g,c,h,e,f)}},redo:m.commands.redo,undo:m.commands.undo,save:function(a,b){this.write(a,b)},saveAndClose:function(a,b){this.write(a,b);this.close(a,b)},close:function(a,b){if(m.commands.close){var c=-1!=b.commandName.indexOf("w");m.commands.close(a,"!"==b.argString||c,!c)}else a.close("!"==b.argString)},write:function(a){m.commands.save?m.commands.save(a):a.save()},nohlsearch:function(a){fa(a)},delmarks:function(a,b){if(b.argString&&ca(b.argString))for(var c=a.state.vim,d=new m.StringStream(ca(b.argString));!d.eol();){d.eatSpace();
var e=d.pos;if(!d.match(/[a-zA-Z]/,!1)){u(a,"Invalid argument: "+b.argString.substring(e));break}var f=d.next();if(d.match("-",!0)){if(!d.match(/[a-zA-Z]/,!1)){u(a,"Invalid argument: "+b.argString.substring(e));break}var g=d.next();if(/^[a-z]$/.test(f)&&/^[a-z]$/.test(g)||M(f)&&M(g)){f=f.charCodeAt(0);g=g.charCodeAt(0);if(f>=g){u(a,"Invalid argument: "+b.argString.substring(e));break}for(e=0;e<=g-f;e++){var h=String.fromCharCode(f+e);delete c.marks[h]}}else{u(a,"Invalid argument: "+f+"-");break}}else delete c.marks[f]}else u(a,
"Argument required")}},K=new Z.ExCommandDispatcher;m.keyMap.vim=function(){function a(a){return function(b){m.Vim.handleKey(b,a)}}function b(b,e){for(var f=0;f<b.length;f++){var g=b[f];e||1!=g.length||(g="'"+g+"'");var h=e,k=b[f];M(k)&&"Ctrl"==h&&(k=k.toLowerCase());h&&(k=h.charAt(0)+"-"+k);k=(h={Enter:"CR",Backspace:"BS",Delete:"Del"}[k])?h:k;k=1<k.length?"<"+k+">":k;c[e?e+"-"+g:g]=a(k)}}var c={nofallthrough:!0,style:"fat-cursor"};b(X);b(ia);b(X,"Ctrl");b(Ba);b(Ba,"Ctrl");b(Y);b(Y,"Ctrl");b(Ca);
b(Ca,"Ctrl");return c}();m.keyMap["vim-insert"]={Esc:W,"Ctrl-[":W,"Ctrl-C":W,"Ctrl-N":"autocomplete","Ctrl-P":"autocomplete",Enter:function(a){(m.commands.newlineAndIndentContinueComment||m.commands.newlineAndIndent)(a)},fallthrough:["default"]};m.keyMap["vim-replace"]={Backspace:"goCharLeft",fallthrough:["vim-insert"]};na();return Ra};m.Vim=Z()});
