!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../lib/codemirror"),require("../addon/search/searchcursor"),require("../addon/dialog/dialog"),require("../addon/edit/matchbrackets.js")):"function"==typeof define&&define.amd?define(["../lib/codemirror","../addon/search/searchcursor","../addon/dialog/dialog","../addon/edit/matchbrackets"],e):e(CodeMirror)}(function(ze){"use strict";var Xe=[{keys:"",type:"keyToKey",toKeys:"h"},{keys:"",type:"keyToKey",toKeys:"l"},{keys:"",type:"keyToKey",toKeys:"k"},{keys:"",type:"keyToKey",toKeys:"j"},{keys:"",type:"keyToKey",toKeys:"l"},{keys:"",type:"keyToKey",toKeys:"h",context:"normal"},{keys:"",type:"keyToKey",toKeys:"x",context:"normal"},{keys:"",type:"keyToKey",toKeys:"W"},{keys:"",type:"keyToKey",toKeys:"B",context:"normal"},{keys:"",type:"keyToKey",toKeys:"w"},{keys:"",type:"keyToKey",toKeys:"b",context:"normal"},{keys:"",type:"keyToKey",toKeys:"j"},{keys:"",type:"keyToKey",toKeys:"k"},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:"",context:"insert"},{keys:"",type:"keyToKey",toKeys:"",context:"insert"},{keys:"s",type:"keyToKey",toKeys:"cl",context:"normal"},{keys:"s",type:"keyToKey",toKeys:"c",context:"visual"},{keys:"S",type:"keyToKey",toKeys:"cc",context:"normal"},{keys:"S",type:"keyToKey",toKeys:"VdO",context:"visual"},{keys:"",type:"keyToKey",toKeys:"0"},{keys:"",type:"keyToKey",toKeys:"$"},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:""},{keys:"",type:"keyToKey",toKeys:"j^",context:"normal"},{keys:"",type:"action",action:"toggleOverwrite",context:"insert"},{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:"gj",type:"motion",motion:"moveByDisplayLines",motionArgs:{forward:!0}},{keys:"gk",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:"ge",type:"motion",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!0,inclusive:!0}},{keys:"gE",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:"(",type:"motion",motion:"moveBySentence",motionArgs:{forward:!1}},{keys:")",type:"motion",motion:"moveBySentence",motionArgs:{forward:!0}},{keys:"",type:"motion",motion:"moveByPage",motionArgs:{forward:!0}},{keys:"",type:"motion",motion:"moveByPage",motionArgs:{forward:!1}},{keys:"",type:"motion",motion:"moveByScroll",motionArgs:{forward:!0,explicitRepeat:!0}},{keys:"",type:"motion",motion:"moveByScroll",motionArgs:{forward:!1,explicitRepeat:!0}},{keys:"gg",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",type:"motion",motion:"moveToCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:"F",type:"motion",motion:"moveToCharacter",motionArgs:{forward:!1}},{keys:"t",type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!0,inclusive:!0}},{keys:"T",type:"motion",motion:"moveTillCharacter",motionArgs:{forward:!1}},{keys:";",type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!0}},{keys:",",type:"motion",motion:"repeatLastCharacterSearch",motionArgs:{forward:!1}},{keys:"'",type:"motion",motion:"goToMark",motionArgs:{toJumplist:!0,linewise:!0}},{keys:"`",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:"]p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!0,isEdit:!0,matchIndent:!0}},{keys:"[p",type:"action",action:"paste",isEdit:!0,actionArgs:{after:!1,isEdit:!0,matchIndent:!0}},{keys:"]",type:"motion",motion:"moveToSymbol",motionArgs:{forward:!0,toJumplist:!0}},{keys:"[",type:"motion",motion:"moveToSymbol",motionArgs:{forward:!1,toJumplist:!0}},{keys:"|",type:"motion",motion:"moveToColumn"},{keys:"o",type:"motion",motion:"moveToOtherHighlightedEnd",context:"visual"},{keys:"O",type:"motion",motion:"moveToOtherHighlightedEnd",motionArgs:{sameLine:!0},context:"visual"},{keys:"d",type:"operator",operator:"delete"},{keys:"y",type:"operator",operator:"yank"},{keys:"c",type:"operator",operator:"change"},{keys:"=",type:"operator",operator:"indentAuto"},{keys:">",type:"operator",operator:"indent",operatorArgs:{indentRight:!0}},{keys:"<",type:"operator",operator:"indent",operatorArgs:{indentRight:!1}},{keys:"g~",type:"operator",operator:"changeCase"},{keys:"gu",type:"operator",operator:"changeCase",operatorArgs:{toLower:!0},isEdit:!0},{keys:"gU",type:"operator",operator:"changeCase",operatorArgs:{toLower:!1},isEdit:!0},{keys:"n",type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:!0}},{keys:"N",type:"motion",motion:"findNext",motionArgs:{forward:!1,toJumplist:!0}},{keys:"gn",type:"motion",motion:"findAndSelectNextInclusive",motionArgs:{forward:!0}},{keys:"gN",type:"motion",motion:"findAndSelectNextInclusive",motionArgs:{forward:!1}},{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},context:"normal"},{keys:"D",type:"operator",operator:"delete",operatorArgs:{linewise:!0},context:"visual"},{keys:"Y",type:"operatorMotion",operator:"yank",motion:"expandToLine",motionArgs:{linewise:!0},context:"normal"},{keys:"Y",type:"operator",operator:"yank",operatorArgs:{linewise:!0},context:"visual"},{keys:"C",type:"operatorMotion",operator:"change",motion:"moveToEol",motionArgs:{inclusive:!0},context:"normal"},{keys:"C",type:"operator",operator:"change",operatorArgs:{linewise:!0},context:"visual"},{keys:"~",type:"operatorMotion",operator:"changeCase",motion:"moveByCharacters",motionArgs:{forward:!0},operatorArgs:{shouldMoveCursor:!0},context:"normal"},{keys:"~",type:"operator",operator:"changeCase",context:"visual"},{keys:"",type:"operatorMotion",operator:"delete",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1},context:"insert"},{keys:"",type:"idle",context:"normal"},{keys:"",type:"action",action:"jumpListWalk",actionArgs:{forward:!0}},{keys:"",type:"action",action:"jumpListWalk",actionArgs:{forward:!1}},{keys:"",type:"action",action:"scroll",actionArgs:{forward:!0,linewise:!0}},{keys:"",type:"action",action:"scroll",actionArgs:{forward:!1,linewise:!0}},{keys:"a",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"charAfter"},context:"normal"},{keys:"A",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"eol"},context:"normal"},{keys:"A",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"endOfSelectedArea"},context:"visual"},{keys:"i",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"inplace"},context:"normal"},{keys:"gi",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"lastEdit"},context:"normal"},{keys:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"firstNonBlank"},context:"normal"},{keys:"gI",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"bol"},context:"normal"},{keys:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"startOfSelectedArea"},context:"visual"},{keys:"o",type:"action",action:"newLineAndEnterInsertMode",isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!0},context:"normal"},{keys:"O",type:"action",action:"newLineAndEnterInsertMode",isEdit:!0,interlaceInsertRepeat:!0,actionArgs:{after:!1},context:"normal"},{keys:"v",type:"action",action:"toggleVisualMode"},{keys:"V",type:"action",action:"toggleVisualMode",actionArgs:{linewise:!0}},{keys:"",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"gv",type:"action",action:"reselectLastSelection"},{keys:"J",type:"action",action:"joinLines",isEdit:!0},{keys:"gJ",type:"action",action:"joinLines",actionArgs:{keepSpaces:!0},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",type:"action",action:"replace",isEdit:!0},{keys:"@",type:"action",action:"replayMacro"},{keys:"q",type:"action",action:"enterMacroRecordMode"},{keys:"R",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{replace:!0},context:"normal"},{keys:"R",type:"operator",operator:"change",operatorArgs:{linewise:!0,fullLine:!0},context:"visual",exitVisualBlock:!0},{keys:"u",type:"action",action:"undo",context:"normal"},{keys:"u",type:"operator",operator:"changeCase",operatorArgs:{toLower:!0},context:"visual",isEdit:!0},{keys:"U",type:"operator",operator:"changeCase",operatorArgs:{toLower:!1},context:"visual",isEdit:!0},{keys:"",type:"action",action:"redo"},{keys:"m",type:"action",action:"setMark"},{keys:'"',type:"action",action:"setRegister"},{keys:"zz",type:"action",action:"scrollToCursor",actionArgs:{position:"center"}},{keys:"z.",type:"action",action:"scrollToCursor",actionArgs:{position:"center"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"zt",type:"action",action:"scrollToCursor",actionArgs:{position:"top"}},{keys:"z",type:"action",action:"scrollToCursor",actionArgs:{position:"top"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:"z-",type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"}},{keys:"zb",type:"action",action:"scrollToCursor",actionArgs:{position:"bottom"},motion:"moveToFirstNonWhiteSpaceCharacter"},{keys:".",type:"action",action:"repeatLastEdit"},{keys:"",type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!0,backtrack:!1}},{keys:"",type:"action",action:"incrementNumberToken",isEdit:!0,actionArgs:{increase:!1,backtrack:!1}},{keys:"",type:"action",action:"indent",actionArgs:{indentRight:!0},context:"insert"},{keys:"",type:"action",action:"indent",actionArgs:{indentRight:!1},context:"insert"},{keys:"a",type:"motion",motion:"textObjectManipulation"},{keys:"i",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",wholeWordOnly:!0,toJumplist:!0}},{keys:"#",type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor",wholeWordOnly:!0,toJumplist:!0}},{keys:"g*",type:"search",searchArgs:{forward:!0,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:"g#",type:"search",searchArgs:{forward:!1,querySrc:"wordUnderCursor",toJumplist:!0}},{keys:":",type:"ex"}],Ze=Xe.length,Ge=[{name:"colorscheme",shortName:"colo"},{name:"map"},{name:"imap",shortName:"im"},{name:"nmap",shortName:"nm"},{name:"vmap",shortName:"vm"},{name:"unmap"},{name:"write",shortName:"w"},{name:"undo",shortName:"u"},{name:"redo",shortName:"red"},{name:"set",shortName:"se"},{name:"setlocal",shortName:"setl"},{name:"setglobal",shortName:"setg"},{name:"sort",shortName:"sor"},{name:"substitute",shortName:"s",possiblyAsync:!0},{name:"nohlsearch",shortName:"noh"},{name:"yank",shortName:"y"},{name:"delmarks",shortName:"delm"},{name:"registers",shortName:"reg",excludeFromCommandHistory:!0},{name:"vglobal",shortName:"v"},{name:"global",shortName:"g"}],Ye=ze.Pos;ze.Vim=function(){function e(e,t){var r;this==ze.keyMap.vim&&(ze.rmClass(e.getWrapperElement(),"cm-fat-cursor"),"contenteditable"==e.getOption("inputStyle")&&null!=document.body.style.caretColor&&(a(r=e),r.off("cursorActivity",o),r.state.fatCursorMarks=null,e.getInputField().style.caretColor="")),t&&t.attach==n||((e=e).setOption("disableInput",!1),e.off("cursorActivity",De),ze.off(e.getInputField(),"paste",l(e)),e.state.vim=null)}function n(e,t){var r;this==ze.keyMap.vim&&(ze.addClass(e.getWrapperElement(),"cm-fat-cursor"),"contenteditable"==e.getOption("inputStyle")&&null!=document.body.style.caretColor&&((r=e).state.fatCursorMarks=[],o(r),r.on("cursorActivity",o),e.getInputField().style.caretColor="transparent")),t&&t.attach==n||((e=e).setOption("disableInput",!0),e.setOption("showCursorWhenSelecting",!1),ze.signal(e,"vim-mode-change",{mode:"normal"}),e.on("cursorActivity",De),B(e),ze.on(e.getInputField(),"paste",l(e)))}function o(e){if(e.state.fatCursorMarks){a(e);for(var t=e.listSelections(),r=[],n=0;n"}(e);if(!r)return!1;e=ze.Vim.findKey(t,r);return"function"==typeof e&&ze.signal(t,"vim-keypress",r),e}}ze.defineOption("vimMode",!1,function(e,t,r){t&&"vim"!=e.getOption("keyMap")?e.setOption("keyMap","vim"):!t&&r!=ze.Init&&/^vim/.test(e.getOption("keyMap"))&&e.setOption("keyMap","default")});var i={Shift:"S",Ctrl:"C",Alt:"A",Cmd:"D",Mod:"A",CapsLock:""},s={Enter:"CR",Backspace:"BS",Delete:"Del",Insert:"Ins"};function l(e){var t=e.state.vim;return t.onPasteFn||(t.onPasteFn=function(){t.insertMode||(e.setCursor(J(e.getCursor(),0,1)),V.enterInsertMode(e,{},t))}),t.onPasteFn}var c=/[\d]/,m=[ze.isWordChar,function(e){return e&&!ze.isWordChar(e)&&!/\s/.test(e)}],g=[function(e){return/\S/.test(e)}];function r(e,t){for(var r=[],n=e;n"]),d=[].concat(u,h,p,["-",'"',".",":","_","/"]);function v(e,t){return t>=e.firstLine()&&t<=e.lastLine()}function y(e){return/^[a-z]$/.test(e)}function k(e){return/^[A-Z]$/.test(e)}function A(e){return/^\s*$/.test(e)}function C(e){return-1!=".?!".indexOf(e)}function w(e,t){for(var r=0;r"==l&&(K(s),c.visualMode?se(s):c.insertMode&&He(s),1)}return!1===(e=(c.insertMode?function(){if(u())return!0;for(var e=c.inputState.keyBuffer=c.inputState.keyBuffer+l,t=1==l.length,r=H.matchCommand(e,Xe,c.inputState,"insert");1|<\w+>|./.exec(e),l=t[0],e=e.substring(t.index+l.length),ze.Vim.handleKey(s,l,"mapping")}(e.toKeys):H.processCommand(s,c,e)}catch(e){throw s.state.vim=void 0,B(s),ze.Vim.suppressErrorLogging||console.log(e),e}return!0})}},handleEx:function(e,t){_e.processCommand(e,t)},defineMotion:function(e,t){F[e]=t},defineAction:function(e,t){V[e]=t},defineOperator:function(e,t){D[e]=t},mapCommand:function(e,t,r,n,o){var i,a={keys:e,type:t};for(i in a[t]=r,a[t+"Args"]=n,o)a[i]=o[i];Fe(a)},_mapCommand:Fe,defineRegister:function(e,t){var r=T.registerController.registers;if(!e||1!=e.length)throw Error("Register name must be 1 character");if(r[e])throw Error("Register already defined "+e);r[e]=t,d.push(e)},exitVisualMode:se,exitInsertMode:He};function N(){this.prefixRepeat=[],this.motionRepeat=[],this.operator=null,this.operatorArgs=null,this.motion=null,this.motionArgs=null,this.keyBuffer=[],this.registerName=null}function K(e,t){e.state.vim.inputState=new N,ze.signal(e,"vim-command-done",t)}function P(e,t,r){this.clear(),this.keyBuffer=[e||""],this.insertModeChanges=[],this.searchQueries=[],this.linewise=!!t,this.blockwise=!!r}function j(e){this.registers=e,this.unnamedRegister=e['"']=new P,e["."]=new P,e[":"]=new P,e["/"]=new P}function _(){this.historyBuffer=[],this.iterator=0,this.initialPrefix=null}N.prototype.pushRepeatDigit=function(e){this.operator?this.motionRepeat=this.motionRepeat.concat(e):this.prefixRepeat=this.prefixRepeat.concat(e)},N.prototype.getRepeat=function(){var e=0;return(0=r.length?(this.iterator=r.length,this.initialPrefix):o<0?e:void 0},pushInput:function(e){var t=this.historyBuffer.indexOf(e);-1"!=t.slice(-11))return e==t?"full":0==t.indexOf(e)&&"partial";var r=t.length-11,n=e.slice(0,r),t=t.slice(0,r);return n==t&&e.length>r?"full":0==t.indexOf(n)&&"partial"}}(e,l.keys))||("partial"==o&&i.push(l),"full"==o&&a.push(l))}return{partial:i.length&&i,full:a.length&&a}}(e,t,n,r);if(!o.full&&!o.partial)return{type:"none"};if(!o.full&&o.partial)return{type:"partial"};for(var i=0;i"==s.keys.slice(-11)){e=function(e){var t=/^.*(<[^>]+>)$/.exec(e),e=t?t[1]:e.slice(-1);if(1":e="\n";break;case"":e=" ";break;default:e=""}return e}(e);if(!e)return{type:"none"};r.selectedCharacter=e}return{type:"full",command:s}},processCommand:function(e,t,r){switch(t.inputState.repeatOverride=r.repeatOverride,r.type){case"motion":this.processMotion(e,t,r);break;case"operator":this.processOperator(e,t,r);break;case"operatorMotion":this.processOperatorMotion(e,t,r);break;case"action":this.processAction(e,t,r);break;case"search":this.processSearch(e,t,r);break;case"ex":case"keyToEx":this.processEx(e,t,r)}},processMotion:function(e,t,r){t.inputState.motion=r.motion,t.inputState.motionArgs=U(r.motionArgs),this.evalInput(e,t)},processOperator:function(e,t,r){var n=t.inputState;if(n.operator){if(n.operator==r.operator)return n.motion="expandToLine",n.motionArgs={linewise:!0},void this.evalInput(e,t);K(e)}n.operator=r.operator,n.operatorArgs=U(r.operatorArgs),r.exitVisualBlock&&(t.visualBlock=!1,ie(e)),t.visualMode&&this.evalInput(e,t)},processOperatorMotion:function(e,t,r){var n=t.visualMode,o=U(r.operatorMotionArgs);o&&n&&o.visualLine&&(t.visualLine=!0),this.processOperator(e,t,r),n||this.processMotion(e,t,r)},processAction:function(e,t,r){var n=t.inputState,o=n.getRepeat(),i=!!o,a=U(r.actionArgs)||{};n.selectedCharacter&&(a.selectedCharacter=n.selectedCharacter),r.operator&&this.processOperator(e,t,r),r.motion&&this.processMotion(e,t,r),(r.motion||r.operator)&&this.evalInput(e,t),a.repeat=o||1,a.repeatIsExplicit=i,a.registerName=n.registerName,K(e),t.lastMotion=null,r.isEdit&&this.recordLastEdit(t,n,r),V[r.action](e,a,t)},processSearch:function(s,n,o){if(s.getSearchCursor){var l=o.searchArgs.forward,e=o.searchArgs.wholeWordOnly;ke(s).setReversed(!l);var t=l?"/":"?",i=ke(s).getQuery(),c=s.getScrollInfo();switch(o.searchArgs.querySrc){case"prompt":var r=T.macroModeState;r.isPlaying?u(a=r.replaySearchQueries.shift(),!0,!1):Te(s,{onClose:function(e){s.scrollTo(c.left,c.top),u(e,!0,!0);var t=T.macroModeState;t.isRecording&&function(e,t){if(e.isPlaying)return;e=e.latestRegister,e=T.registerController.getRegister(e);e&&e.pushSearchQuery&&e.pushSearchQuery(t)}(t,e)},prefix:t,desc:"(JavaScript regexp)",onKeyUp:function(e,t,r){var n,o,i,a=ze.keyName(e);"Up"==a||"Down"==a?(n="Up"==a,o=e.target?e.target.selectionEnd:0,r(t=T.searchHistoryController.nextMatch(t,n)||""),o&&e.target&&(e.target.selectionEnd=e.target.selectionStart=Math.min(o,e.target.value.length))):"Left"!=a&&"Right"!=a&&"Ctrl"!=a&&"Alt"!=a&&"Shift"!=a&&T.searchHistoryController.reset();try{i=Re(s,t,!0,!0)}catch(e){}i?s.scrollIntoView(Be(s,!l,i),30):(Ie(s),s.scrollTo(c.left,c.top))},onKeyDown:function(e,t,r){var n=ze.keyName(e);"Esc"==n||"Ctrl-C"==n||"Ctrl-["==n||"Backspace"==n&&""==t?(T.searchHistoryController.pushInput(t),T.searchHistoryController.reset(),Re(s,i),Ie(s),s.scrollTo(c.left,c.top),ze.e_stop(e),K(s),r(),s.focus()):"Up"==n||"Down"==n?ze.e_stop(e):"Ctrl-U"==n&&(ze.e_stop(e),r(""))}});break;case"wordUnderCursor":r=ce(s,!1,0,!1,!0),t=!0;if(r||(r=ce(s,!1,0,!1,!1),t=!1),!r)return;var a=s.getLine(r.start.line).substring(r.start.ch,r.end.ch);a=t&&e?"\\b"+a+"\\b":a.replace(/([.?*+$\[\]\/\\(){}|\-])/g,"\\$1"),T.jumpList.cachedCursor=s.getCursor(),s.setCursor(r.start),u(a,!0,!1)}}function u(t,e,r){T.searchHistoryController.pushInput(t),T.searchHistoryController.reset();try{Re(s,t,e,r)}catch(e){return Le(s,"Invalid regex: "+t),void K(s)}H.processMotion(s,n,{type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:o.searchArgs.toJumplist}})}},processEx:function(a,e,t){function r(e){T.exCommandHistoryController.pushInput(e),T.exCommandHistoryController.reset(),_e.processCommand(a,e)}function n(e,t,r){var n,o,i=ze.keyName(e);("Esc"==i||"Ctrl-C"==i||"Ctrl-["==i||"Backspace"==i&&""==t)&&(T.exCommandHistoryController.pushInput(t),T.exCommandHistoryController.reset(),ze.e_stop(e),K(a),r(),a.focus()),"Up"==i||"Down"==i?(ze.e_stop(e),n="Up"==i,o=e.target?e.target.selectionEnd:0,r(t=T.exCommandHistoryController.nextMatch(t,n)||""),o&&e.target&&(e.target.selectionEnd=e.target.selectionStart=Math.min(o,e.target.value.length))):"Ctrl-U"==i?(ze.e_stop(e),r("")):"Left"!=i&&"Right"!=i&&"Ctrl"!=i&&"Alt"!=i&&"Shift"!=i&&T.exCommandHistoryController.reset()}"keyToEx"==t.type?_e.processCommand(a,t.exArgs.input):e.visualMode?Te(a,{onClose:r,prefix:":",value:"'<,'>",onKeyDown:n,selectValueOnOpen:!1}):Te(a,{onClose:r,prefix:":",onKeyDown:n})},evalInput:function(e,t){var r,n,o,i,a,s,l=t.inputState,c=l.motion,u=l.motionArgs||{},h=l.operator,p=l.operatorArgs||{},f=l.registerName,d=t.sel,m=Q(t.visualMode?$(e,d.head):e.getCursor("head")),g=Q(t.visualMode?$(e,d.anchor):e.getCursor("anchor")),v=Q(m),y=Q(g);if(h&&this.recordLastEdit(t,l),0<(g=void 0!==l.repeatOverride?l.repeatOverride:l.getRepeat())&&u.explicitRepeat?u.repeatIsExplicit=!0:(u.noRepeat||!u.explicitRepeat&&0===g)&&(g=1,u.repeatIsExplicit=!1),l.selectedCharacter&&(u.selectedCharacter=p.selectedCharacter=l.selectedCharacter),u.repeat=g,K(e),c){var k,C=F[c](e,m,u,t,l);if(t.lastMotion=F[c],!C)return;u.toJumplist&&((S=(k=T.jumpList).cachedCursor)?(ue(e,S,C),delete k.cachedCursor):ue(e,m,C)),S=(S=C instanceof Array?(r=C[0],C[1]):C)||Q(m),t.visualMode?(t.visualBlock&&S.ch===1/0||(S=$(e,S)),r=(r=r&&$(e,r))||y,d.anchor=r,d.head=S,ie(e),ge(e,t,"<",X(r,S)?r:S),ge(e,t,">",X(r,S)?S:r)):h||(S=$(e,S),e.setCursor(S.line,S.ch))}if(h){if(p.lastSel?(r=y,k=p.lastSel,C=Math.abs(k.head.line-k.anchor.line),m=Math.abs(k.head.ch-k.anchor.ch),S=k.visualLine?Ye(y.line+C,y.ch):k.visualBlock?Ye(y.line+C,y.ch+m):k.head.line==k.anchor.line?Ye(y.line,y.ch+m):Ye(y.line+C,y.ch),t.visualMode=!0,t.visualLine=k.visualLine,t.visualBlock=k.visualBlock,d=t.sel={anchor:r,head:S},ie(e)):t.visualMode&&(p.lastSel={anchor:Q(d.anchor),head:Q(d.head),visualBlock:t.visualBlock,visualLine:t.visualLine}),t.visualMode){if(i=Z(d.head,d.anchor),a=G(d.head,d.anchor),n=t.visualLine||p.linewise,M=ae(e,{anchor:i,head:a},o=t.visualBlock?"block":n?"line":"char"),n){var w=M.ranges;if("block"==o)for(var x=0;xs:a.line=t.line.length){if(t.ln+=t.dir,!v(e,t.ln))return t.line=null,t.ln=null,void(t.pos=null);t.line=e.getLine(t.ln),t.pos=0"===o?/[(){}[\]<>]/:/[(){}[\]]/;return e.findMatchingBracket(Ye(n,o),{bracketRegex:t}).to}return r},moveToStartOfLine:function(e,t){return Ye(t.line,0)},moveToLineOrEdgeOfDocument:function(e,t,r){var n=r.forward?e.lastLine():e.firstLine();return r.repeatIsExplicit&&(n=r.repeat-e.getOption("firstLineNumber")),Ye(n,le(e.getLine(n)))},textObjectManipulation:function(e,t,r,n){var o=r.selectedCharacter;"b"==o?o="(":"B"==o&&(o="{");var i=!r.textObjectInner;if({"(":")",")":"(","{":"}","}":"{","[":"]","]":"[","<":">",">":"<"}[o])a=function(e,t,r,n){var o=t,i={"(":/[()]/,")":/[()]/,"[":/[[\]]/,"]":/[[\]]/,"{":/[{}]/,"}":/[{}]/,"<":/[<>]/,">":/[<>]/}[r],t={"(":"(",")":"(","[":"[","]":"[","{":"{","}":"{","<":"<",">":"<"}[r],r=e.getLine(o.line).charAt(o.ch)===t?1:0;if(t=e.scanForBracket(Ye(o.line,o.ch+r),-1,void 0,{bracketRegex:i}),i=e.scanForBracket(Ye(o.line,o.ch+r),1,void 0,{bracketRegex:i}),!t||!i)return{start:o,end:o};t=t.pos,i=i.pos,(t.line==i.line&&t.ch>i.ch||t.line>i.line)&&(o=t,t=i,i=o);n?i.ch+=1:t.ch+=1;return{start:t,end:i}}(e,t,o,i);else if({"'":!0,'"':!0,"`":!0}[o])a=function(e,t,r,n){var o,i,a,s,t=Q(t),l=e.getLine(t.line).split(""),e=l.indexOf(r);t.che.lastLine()&&t.linewise&&!i?e.replaceRange("",a,l):e.replaceRange("",s,l),t.linewise&&(i||(e.setCursor(a),ze.commands.newlineAndIndent(e)),s.ch=Number.MAX_VALUE),s);T.registerController.pushText(t.registerName,"change",n,t.linewise,1r.top?(i.line+=(o-r.top)/n,i.line=Math.ceil(i.line),e.setCursor(i),r=e.charCoords(i,"local"),e.scrollTo(null,r.top)):e.scrollTo(null,o):(t=o+e.getScrollInfo().clientHeight)|<\w+>|./.exec(u),c=s[0],u=u.substring(s.index+c.length),ze.Vim.handleKey(e,c,"macro"),t.insertMode&&(c=o.insertModeChanges[a++].changes,T.macroModeState.lastInsertModeChanges.changes=c,Qe(e,c,1),He(e));r.isPlaying=!1}(e,r,i,n)},enterMacroRecordMode:function(e,t){var r=T.macroModeState,t=t.selectedCharacter;T.registerController.isValidRegister(t)&&r.enterMacroRecordMode(e,t)},toggleOverwrite:function(e){e.state.overwrite?(e.toggleOverwrite(!1),e.setOption("keyMap","vim-insert"),ze.signal(e,"vim-mode-change",{mode:"insert"})):(e.toggleOverwrite(!0),e.setOption("keyMap","vim-replace"),ze.signal(e,"vim-mode-change",{mode:"replace"}))},enterInsertMode:function(e,t,r){if(!e.getOption("readOnly")){r.insertMode=!0,r.insertModeRepeat=t&&t.repeat||1;var n=t?t.insertAt:null,o=r.sel,i=t.head||e.getCursor("head"),a=e.listSelections().length;if("eol"==n)i=Ye(i.line,ee(e,i.line));else if("bol"==n)i=Ye(i.line,0);else if("charAfter"==n)i=J(i,0,1);else if("firstNonBlank"==n)i=F.moveToFirstNonWhiteSpaceCharacter(e,i);else if("startOfSelectedArea"==n){if(!r.visualMode)return;r.visualBlock?(i=Ye(Math.min(o.head.line,o.anchor.line),Math.min(o.head.ch,o.anchor.ch)),a=Math.abs(o.head.line-o.anchor.line)+1):i=o.head.line=o.anchor.line?J(o.head,0,1):Ye(o.anchor.line,0)}else if("inplace"==n){if(r.visualMode)return}else"lastEdit"==n&&(i=Pe(e)||i);e.setOption("disableInput",!1),t&&t.replace?(e.toggleOverwrite(!0),e.setOption("keyMap","vim-replace"),ze.signal(e,"vim-mode-change",{mode:"replace"})):(e.toggleOverwrite(!1),e.setOption("keyMap","vim-insert"),ze.signal(e,"vim-mode-change",{mode:"insert"})),T.macroModeState.isPlaying||(e.on("change",We),ze.on(e.getInputField(),"keydown",Je)),r.visualMode&&se(e),ne(e,i,a)}},toggleVisualMode:function(e,t,r){var n=t.repeat,o=e.getCursor();r.visualMode?r.visualLine^t.linewise||r.visualBlock^t.blockwise?(r.visualLine=!!t.linewise,r.visualBlock=!!t.blockwise,ze.signal(e,"vim-mode-change",{mode:"visual",subMode:r.visualLine?"linewise":r.visualBlock?"blockwise":""}),ie(e)):se(e):(r.visualMode=!0,r.visualLine=!!t.linewise,r.visualBlock=!!t.blockwise,n=$(e,Ye(o.line,o.ch+n-1)),r.sel={anchor:o,head:n},ze.signal(e,"vim-mode-change",{mode:"visual",subMode:r.visualLine?"linewise":r.visualBlock?"blockwise":""}),ie(e),ge(e,r,"<",Z(o,n)),ge(e,r,">",G(o,n)))},reselectLastSelection:function(e,t,r){var n,o,i=r.lastSelection;r.visualMode&&oe(e,r),i&&(n=i.anchorMark.find(),o=i.headMark.find(),n&&o&&(r.sel={anchor:n,head:o},r.visualMode=!0,r.visualLine=i.visualLine,r.visualBlock=i.visualBlock,ie(e),ge(e,r,"<",Z(n,o)),ge(e,r,">",G(n,o)),ze.signal(e,"vim-mode-change",{mode:"visual",subMode:r.visualLine?"linewise":r.visualBlock?"blockwise":""})))},joinLines:function(e,t,r){var n,o;r.visualMode?(o=e.getCursor("anchor"),X(n=e.getCursor("head"),o)&&(s=n,n=o,o=s),n.ch=ee(e,n.line)-1):(c=Math.max(t.repeat,2),o=e.getCursor(),n=$(e,Ye(o.line+c-1,1/0)));for(var i=0,a=o.line;ar.lastLine()&&r.replaceRange("\n",Ye(M,0)),ee(r,M)o.length&&(n=o.length),Ye(a.line,n));"\n"==i?(r.visualMode||e.replaceRange("",a,t),(ze.commands.newlineAndIndentContinueComment||ze.commands.newlineAndIndent)(e)):(o=(o=e.getRange(a,t)).replace(/[^\n]/g,i),r.visualBlock?(n=new Array(e.getOption("tabSize")+1).join(" "),o=(o=e.getSelection()).replace(/\t/g,n).replace(/[^\n]/g,i).split("\n"),e.replaceSelections(o)):e.replaceRange(o,a,t),r.visualMode?(a=X(s[0].anchor,s[0].head)?s[0].anchor:s[0].head,e.setCursor(a),se(e,!1)):e.setCursor(J(t,0,-1)))},incrementNumberToken:function(e,t){for(var r,n,o,i,a,s,l,c=e.getCursor(),u=e.getLine(c.line),h=/(-?)(?:(0x)([\da-f]+)|(0b|0|)(\d+))/gi;null!==(r=h.exec(u))&&(o=(n=r.index)+r[0].length,!(c.cht&&(o.line=t),o.ch=ee(e,o.line)),{ranges:[{anchor:i,head:o}],primary:0};if("block"==r){for(var s=Math.min(i.line,o.line),l=Math.min(i.ch,o.ch),r=Math.max(i.line,o.line),c=Math.max(i.ch,o.ch)+1,u=r-s+1,o=o.line==s?0:u-1,h=[],p=0;p=s.length)return null;n?c=g[0]:(c=m[0])(s.charAt(l))||(c=m[1]);for(var u=l,h=l;c(s.charAt(u))&&u@~])/);return r.commandName=e?e[1]:t.match(/.*/)[0],r},parseLineSpec_:function(e,t){var r=t.match(/^(\d+)/);if(r)return parseInt(r[1],10)-1;switch(t.next()){case".":return this.parseLineSpecOffset_(t,e.getCursor().line);case"$":return this.parseLineSpecOffset_(t,e.lastLine());case"'":r=t.next(),r=Ke(e,e.state.vim,r);if(!r)throw new Error("Mark not set");return this.parseLineSpecOffset_(t,r.line);case"-":case"+":return t.backUp(1),this.parseLineSpecOffset_(t,e.getCursor().line);default:return void t.backUp(1)}},parseLineSpecOffset_:function(e,t){var r=e.match(/^([+-])?(\d+)/);return r&&(e=parseInt(r[2],10),"-"==r[1]?t-=e:t+=e),t},parseCommandArgs_:function(e,t,r){e.eol()||(t.argString=e.match(/.*/)[0],r=r.argDelimiter||/\s+/,(r=te(t.argString).split(r)).length&&r[0]&&(t.args=r))},matchCommand_:function(e){for(var t=e.length;0",G(n,r))):t.insertMode||(t.lastHPos=e.getCursor().ch)}}(e,t);t.visualMode&&Ve(e)}function Ve(e){var t,r="cm-animate-fat-cursor",n=e.state.vim,o=$(e,Q(n.sel.head)),i=J(o,0,1);$e(n),o.ch==e.getLine(o.line).length?(t=be("span",{class:r}," "),n.fakeCursorBookmark=e.setBookmark(o,{widget:t})):n.fakeCursor=e.markText(o,i,{className:r})}function $e(e){e.fakeCursor&&(e.fakeCursor.clear(),e.fakeCursor=null),e.fakeCursorBookmark&&(e.fakeCursorBookmark.clear(),e.fakeCursorBookmark=null)}function Ue(e){this.keyName=e}function Je(e){var t=T.macroModeState.lastInsertModeChanges,r=ze.keyName(e);r&&(-1==r.indexOf("Delete")&&-1==r.indexOf("Backspace")||ze.lookupKey(r,"vim-insert",function(){return t.maybeReset&&(t.changes=[],t.maybeReset=!1),t.changes.push(new Ue(r)),!0}))}function qe(r,n,e,t){var o=T.macroModeState;o.isPlaying=!0;var i=!!n.lastEditActionCommand,a=n.inputState;function s(){i?H.processAction(r,n,n.lastEditActionCommand):H.evalInput(r,n)}function l(e){var t;0