mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-27 02:20:28 +00:00
200e854814
* Update codemirror.js * Update xml-fold.js * Update javascript.js * Update markdown.js * Update readme.tid * add tiddlywiki theme to codemirror demo * set tiddlywiki theme for codemirror demo * correct naming of meta to tw-meta * vim keymap updates were missing - now added
4 lines
75 KiB
JavaScript
Executable File
4 lines
75 KiB
JavaScript
Executable File
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||
!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(e){"use strict";var t=[{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",context:"normal"},{keys:"<C-Space>",type:"keyToKey",toKeys:"W"},{keys:"<C-BS>",type:"keyToKey",toKeys:"B",context:"normal"},{keys:"<S-Space>",type:"keyToKey",toKeys:"w"},{keys:"<S-BS>",type:"keyToKey",toKeys:"b",context:"normal"},{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:"<C-[>",type:"keyToKey",toKeys:"<Esc>",context:"insert"},{keys:"<C-c>",type:"keyToKey",toKeys:"<Esc>",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:"<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:"<Ins>",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:"<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:"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<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,linewise:!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:"]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:"]<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"},{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:"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:"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:"<C-w>",type:"operatorMotion",operator:"delete",motion:"moveByWords",motionArgs:{forward:!1,wordEnd:!1},context:"insert"},{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"},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:"I",type:"action",action:"enterInsertMode",isEdit:!0,actionArgs:{insertAt:"firstNonBlank"},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:"<C-v>",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"<C-q>",type:"action",action:"toggleVisualMode",actionArgs:{blockwise:!0}},{keys:"gv",type:"action",action:"reselectLastSelection"},{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",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:"<C-r>",type:"action",action:"redo"},{keys:"m<character>",type:"action",action:"setMark"},{keys:'"<character>',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<CR>",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:"<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:"<C-t>",type:"action",action:"indent",actionArgs:{indentRight:!0},context:"insert"},{keys:"<C-d>",type:"action",action:"indent",actionArgs:{indentRight:!1},context:"insert"},{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",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"}],r=[{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:"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:"global",shortName:"g"}],n=e.Pos;e.Vim=function(){function o(t,r){var n;this==e.keyMap.vim&&(e.rmClass(t.getWrapperElement(),"cm-fat-cursor"),"contenteditable"==t.getOption("inputStyle")&&null!=document.body.style.caretColor&&(function(e){var t=e.state.fatCursorMarks;if(t)for(var r=0;r<t.length;r++)t[r].clear();e.state.fatCursorMarks=null,e.off("cursorActivity",s)}(t),t.getInputField().style.caretColor="")),r&&r.attach==i||((n=t).setOption("disableInput",!1),n.off("cursorActivity",qe),e.off(n.getInputField(),"paste",h(n)),n.state.vim=null)}function i(t,r){var n,o;this==e.keyMap.vim&&(e.addClass(t.getWrapperElement(),"cm-fat-cursor"),"contenteditable"==t.getOption("inputStyle")&&null!=document.body.style.caretColor&&((n=t).state.fatCursorMarks=a(n),n.on("cursorActivity",s),t.getInputField().style.caretColor="transparent")),r&&r.attach==i||((o=t).setOption("disableInput",!0),o.setOption("showCursorWhenSelecting",!1),e.signal(o,"vim-mode-change",{mode:"normal"}),o.on("cursorActivity",qe),P(o),e.on(o.getInputField(),"paste",h(o)))}function a(e){for(var t=e.listSelections(),r=[],o=0;o<t.length;o++){var i=t[o];if(i.empty())if(i.anchor.ch<e.getLine(i.anchor.line).length)r.push(e.markText(i.anchor,n(i.anchor.line,i.anchor.ch+1),{className:"cm-fat-cursor-mark"}));else{var a=document.createElement("span");a.textContent=" ",a.className="cm-fat-cursor-mark",r.push(e.setBookmark(i.anchor,{widget:a}))}}return r}function s(e){var t=e.state.fatCursorMarks;if(t)for(var r=0;r<t.length;r++)t[r].clear();e.state.fatCursorMarks=a(e)}function l(t,r){if(r){if(this[t])return this[t];var n=function(e){if("'"==e.charAt(0))return e.charAt(1);var t=e.split(/-(?!$)/),r=t[t.length-1];if(1==t.length&&1==t[0].length)return!1;if(2==t.length&&"Shift"==t[0]&&1==r.length)return!1;for(var n=!1,o=0;o<t.length;o++){var i=t[o];i in c?t[o]=c[i]:n=!0,i in u&&(t[o]=u[i])}return!!n&&(x(r)&&(t[t.length-1]=r.toLowerCase()),"<"+t.join("-")+">")}(t);if(!n)return!1;var o=e.Vim.findKey(r,n);return"function"==typeof o&&e.signal(r,"vim-keypress",n),o}}e.defineOption("vimMode",!1,function(t,r,n){r&&"vim"!=t.getOption("keyMap")?t.setOption("keyMap","vim"):!r&&n!=e.Init&&/^vim/.test(t.getOption("keyMap"))&&t.setOption("keyMap","default")});var c={Shift:"S",Ctrl:"C",Alt:"A",Cmd:"D",Mod:"A"},u={Enter:"CR",Backspace:"BS",Delete:"Del",Insert:"Ins"};function h(e){var t=e.state.vim;return t.onPasteFn||(t.onPasteFn=function(){t.insertMode||(e.setCursor(G(e.getCursor(),0,1)),Q.enterInsertMode(e,{},t))}),t.onPasteFn}var p=/[\d]/,f=[e.isWordChar,function(t){return t&&!e.isWordChar(t)&&!/\s/.test(t)}],d=[function(e){return/\S/.test(e)}];function m(e,t){for(var r=[],n=e;n<e+t;n++)r.push(String.fromCharCode(n));return r}var g=m(65,26),v=m(97,26),y=m(48,10),k=[].concat(g,v,y,["<",">"]),C=[].concat(g,v,y,["-",'"',".",":","/"]);function w(e,t){return t>=e.firstLine()&&t<=e.lastLine()}function M(e){return/^[a-z]$/.test(e)}function x(e){return/^[A-Z]$/.test(e)}function S(e){return/^\s*$/.test(e)}function A(e){return-1!=".?!".indexOf(e)}function b(e,t){for(var r=0;r<t.length;r++)if(t[r]==e)return!0;return!1}var L={};function T(e,t,r,n,o){if(void 0===t&&!o)throw Error("defaultValue is required unless callback is provided");if(r||(r="string"),L[e]={type:r,defaultValue:t,callback:o},n)for(var i=0;i<n.length;i++)L[n[i]]=L[e];t&&R(e,t)}function R(e,t,r,n){var o=L[e],i=(n=n||{}).scope;if(!o)return new Error("Unknown option: "+e);if("boolean"==o.type){if(t&&!0!==t)return new Error("Invalid argument: "+e+"="+t);!1!==t&&(t=!0)}o.callback?("local"!==i&&o.callback(t,void 0),"global"!==i&&r&&o.callback(t,r)):("local"!==i&&(o.value="boolean"==o.type?!!t:t),"global"!==i&&r&&(r.state.vim.options[e]={value:t}))}function E(e,t,r){var n=L[e],o=(r=r||{}).scope;if(!n)return new Error("Unknown option: "+e);if(n.callback){var i=t&&n.callback(void 0,t);return"global"!==o&&void 0!==i?i:"local"!==o?n.callback():void 0}return((i="global"!==o&&t&&t.state.vim.options[e])||"local"!==o&&n||{}).value}T("filetype",void 0,"string",["ft"],function(e,t){if(void 0!==t){if(void 0===e)return"null"==(r=t.getOption("mode"))?"":r;var r=""==e?"null":e;t.setOption("mode",r)}});var O,B,I=function(){var e=100,t=-1,r=0,n=0,o=new Array(e);return{cachedCursor:void 0,add:function(i,a,s){var l=o[t%e];function c(r){var n=++t%e,a=o[n];a&&a.clear(),o[n]=i.setBookmark(r)}if(l){var u=l.find();u&&!te(u,a)&&c(a)}else c(a);c(s),r=t,(n=t-e+1)<0&&(n=0)},move:function(i,a){(t+=a)>r?t=r:t<n&&(t=n);var s=o[(e+t)%e];if(s&&!s.find()){var l,c=a>0?1:-1,u=i.getCursor();do{if((s=o[(e+(t+=c))%e])&&(l=s.find())&&!te(u,l))break}while(t<r&&t>n)}return s}}},K=function(e){return e?{changes:e.changes,expectCursorActivityForChange:e.expectCursorActivityForChange}:{changes:[],expectCursorActivityForChange:!1}};function N(){this.latestRegister=void 0,this.isPlaying=!1,this.isRecording=!1,this.replaySearchQueries=[],this.onRecordingDone=void 0,this.lastInsertModeChanges=K()}function P(e){return e.state.vim||(e.state.vim={inputState:new _,lastEditInputState:void 0,lastEditActionCommand:void 0,lastHPos:-1,lastHSPos:-1,lastMotion:null,marks:{},fakeCursor:null,insertMode:!1,insertModeRepeat:void 0,visualMode:!1,visualLine:!1,visualBlock:!1,lastSelection:null,lastPastedText:null,sel:{},options:{}}),e.state.vim}function j(){for(var e in O={searchQuery:null,searchIsReversed:!1,lastSubstituteReplacePart:void 0,jumpList:I(),macroModeState:new N,lastCharacterSearch:{increment:0,forward:!0,selectedCharacter:""},registerController:new V({}),searchHistoryController:new D,exCommandHistoryController:new D},L){var t=L[e];t.value=t.defaultValue}}N.prototype={exitMacroRecordMode:function(){var e=O.macroModeState;e.onRecordingDone&&e.onRecordingDone(),e.onRecordingDone=void 0,e.isRecording=!1},enterMacroRecordMode:function(e,t){var r=O.registerController.getRegister(t);r&&(r.clear(),this.latestRegister=t,e.openDialog&&(this.onRecordingDone=e.openDialog("(recording)["+t+"]",null,{bottom:!0})),this.isRecording=!0)}};var H={buildKeyMap:function(){},getRegisterController:function(){return O.registerController},resetVimGlobalState_:j,getVimGlobalState_:function(){return O},maybeInitVimState_:P,suppressErrorLogging:!1,InsertModeKey:ze,map:function(e,t,r){Ve.map(e,t,r)},unmap:function(e,t){Ve.unmap(e,t)},setOption:R,getOption:E,defineOption:T,defineEx:function(e,t,r){if(t){if(0!==e.indexOf(t))throw new Error('(Vim.defineEx) "'+t+'" is not a prefix of "'+e+'", command not registered')}else t=e;We[e]=r,Ve.commandMap_[t]={name:e,shortName:t,type:"api"}},handleKey:function(e,t,r){var n=this.findKey(e,t,r);if("function"==typeof n)return n()},findKey:function(r,n,o){var i,a=P(r);function s(){var e=O.macroModeState;if(e.isRecording){if("q"==n)return e.exitMacroRecordMode(),F(r),!0;"mapping"!=o&&function(e,t){if(!e.isPlaying){var r=e.latestRegister,n=O.registerController.getRegister(r);n&&n.pushText(t)}}(e,n)}}function l(){if("<Esc>"==n)return F(r),a.visualMode?fe(r):a.insertMode&&De(r),!0}return!1===(i=a.insertMode?function(){if(l())return!0;for(var e=a.inputState.keyBuffer=a.inputState.keyBuffer+n,o=1==n.length,i=U.matchCommand(e,t,a.inputState,"insert");e.length>1&&"full"!=i.type;){e=a.inputState.keyBuffer=e.slice(1);var s=U.matchCommand(e,t,a.inputState,"insert");"none"!=s.type&&(i=s)}if("none"==i.type)return F(r),!1;if("partial"==i.type)return B&&window.clearTimeout(B),B=window.setTimeout(function(){a.insertMode&&a.inputState.keyBuffer&&F(r)},E("insertModeEscKeysTimeout")),!o;if(B&&window.clearTimeout(B),o){for(var c=r.listSelections(),u=0;u<c.length;u++){var h=c[u].head;r.replaceRange("",G(h,0,-(e.length-1)),h,"+input")}O.macroModeState.lastInsertModeChanges.changes.pop()}return F(r),i.command}():function(){if(s()||l())return!0;var e=a.inputState.keyBuffer=a.inputState.keyBuffer+n;if(/^[1-9]\d*$/.test(e))return!0;if(!(o=/^(\d*)(.*)$/.exec(e)))return F(r),!1;var o,i=a.visualMode?"visual":"normal",c=U.matchCommand(o[2]||o[1],t,a.inputState,i);return"none"==c.type?(F(r),!1):"partial"==c.type||(a.inputState.keyBuffer="",(o=/^(\d*)(.*)$/.exec(e))[1]&&"0"!=o[1]&&a.inputState.pushRepeatDigit(o[1]),c.command)}())?a.insertMode||1!==n.length?void 0:function(){return!0}:!0===i?function(){return!0}:function(){return r.operation(function(){r.curOp.isVimOp=!0;try{"keyToKey"==i.type?function(t){for(var o;t;)o=/<\w+-.+?>|<\w+>|./.exec(t),n=o[0],t=t.substring(o.index+n.length),e.Vim.handleKey(r,n,"mapping")}(i.toKeys):U.processCommand(r,a,i)}catch(t){throw r.state.vim=void 0,P(r),e.Vim.suppressErrorLogging||console.log(t),t}return!0})}},handleEx:function(e,t){Ve.processCommand(e,t)},defineMotion:function(e,t){J[e]=t},defineAction:function(e,t){Q[e]=t},defineOperator:function(e,t){q[e]=t},mapCommand:function(e,t,r,n,o){var i={keys:e,type:t};for(var a in i[t]=r,i[t+"Args"]=n,o)i[a]=o[a];Ue(i)},_mapCommand:Ue,defineRegister:function(e,t){var r=O.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,C.push(e)},exitVisualMode:fe,exitInsertMode:De};function _(){this.prefixRepeat=[],this.motionRepeat=[],this.operator=null,this.operatorArgs=null,this.motion=null,this.motionArgs=null,this.keyBuffer=[],this.registerName=null}function F(t,r){t.state.vim.inputState=new _,e.signal(t,"vim-command-done",r)}function W(e,t,r){this.clear(),this.keyBuffer=[e||""],this.insertModeChanges=[],this.searchQueries=[],this.linewise=!!t,this.blockwise=!!r}function V(e){this.registers=e,this.unnamedRegister=e['"']=new W,e["."]=new W,e[":"]=new W,e["/"]=new W}function D(){this.historyBuffer=[],this.iterator=0,this.initialPrefix=null}_.prototype.pushRepeatDigit=function(e){this.operator?this.motionRepeat=this.motionRepeat.concat(e):this.prefixRepeat=this.prefixRepeat.concat(e)},_.prototype.getRepeat=function(){var e=0;return(this.prefixRepeat.length>0||this.motionRepeat.length>0)&&(e=1,this.prefixRepeat.length>0&&(e*=parseInt(this.prefixRepeat.join(""),10)),this.motionRepeat.length>0&&(e*=parseInt(this.motionRepeat.join(""),10))),e},W.prototype={setText:function(e,t,r){this.keyBuffer=[e||""],this.linewise=!!t,this.blockwise=!!r},pushText:function(e,t){t&&(this.linewise||this.keyBuffer.push("\n"),this.linewise=!0),this.keyBuffer.push(e)},pushInsertModeChanges:function(e){this.insertModeChanges.push(K(e))},pushSearchQuery:function(e){this.searchQueries.push(e)},clear:function(){this.keyBuffer=[],this.insertModeChanges=[],this.searchQueries=[],this.linewise=!1},toString:function(){return this.keyBuffer.join("")}},V.prototype={pushText:function(e,t,r,n,o){n&&"\n"!==r.charAt(r.length-1)&&(r+="\n");var i=this.isValidRegister(e)?this.getRegister(e):null;if(i)x(e)?i.pushText(r,n):i.setText(r,n,o),this.unnamedRegister.setText(i.toString(),n);else{switch(t){case"yank":this.registers[0]=new W(r,n,o);break;case"delete":case"change":-1==r.indexOf("\n")?this.registers["-"]=new W(r,n):(this.shiftNumericRegisters_(),this.registers[1]=new W(r,n))}this.unnamedRegister.setText(r,n,o)}},getRegister:function(e){return this.isValidRegister(e)?(e=e.toLowerCase(),this.registers[e]||(this.registers[e]=new W),this.registers[e]):this.unnamedRegister},isValidRegister:function(e){return e&&b(e,C)},shiftNumericRegisters_:function(){for(var e=9;e>=2;e--)this.registers[e]=this.getRegister(""+(e-1))}},D.prototype={nextMatch:function(e,t){var r=this.historyBuffer,n=t?-1:1;null===this.initialPrefix&&(this.initialPrefix=e);for(var o=this.iterator+n;t?o>=0:o<r.length;o+=n)for(var i=r[o],a=0;a<=i.length;a++)if(this.initialPrefix==i.substring(0,a))return this.iterator=o,i;return o>=r.length?(this.iterator=r.length,this.initialPrefix):o<0?e:void 0},pushInput:function(e){var t=this.historyBuffer.indexOf(e);t>-1&&this.historyBuffer.splice(t,1),e.length&&this.historyBuffer.push(e)},reset:function(){this.initialPrefix=null,this.iterator=this.historyBuffer.length}};var U={matchCommand:function(e,t,r,n){var o,i=function(e,t,r,n){for(var o,i=[],a=[],s=0;s<t.length;s++){var l=t[s];"insert"==r&&"insert"!=l.context||l.context&&l.context!=r||n.operator&&"action"==l.type||!(o=X(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(!i.full&&!i.partial)return{type:"none"};if(!i.full&&i.partial)return{type:"partial"};for(var a=0;a<i.full.length;a++){var s=i.full[a];o||(o=s)}if("<character>"==o.keys.slice(-11)){var l=function(e){var t=/^.*(<[^>]+>)$/.exec(e),r=t?t[1]:e.slice(-1);if(r.length>1)switch(r){case"<CR>":r="\n";break;case"<Space>":r=" ";break;default:r=""}return r}(e);if(!l)return{type:"none"};r.selectedCharacter=l}return{type:"full",command:o}},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=Z(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);F(e)}n.operator=r.operator,n.operatorArgs=Z(r.operatorArgs),t.visualMode&&this.evalInput(e,t)},processOperatorMotion:function(e,t,r){var n=t.visualMode,o=Z(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=Z(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,F(e),t.lastMotion=null,r.isEdit&&this.recordLastEdit(t,n,r),Q[r.action](e,a,t)},processSearch:function(t,r,n){if(t.getSearchCursor){var o=n.searchArgs.forward,i=n.searchArgs.wholeWordOnly;Ae(t).setReversed(!o);var a=o?"/":"?",s=Ae(t).getQuery(),l=t.getScrollInfo();switch(n.searchArgs.querySrc){case"prompt":var c=O.macroModeState;c.isPlaying?f(p=c.replaySearchQueries.shift(),!0,!1):Ie(t,{onClose:function(e){t.scrollTo(l.left,l.top),f(e,!0,!0);var r=O.macroModeState;r.isRecording&&function(e,t){if(!e.isPlaying){var r=e.latestRegister,n=O.registerController.getRegister(r);n&&n.pushSearchQuery&&n.pushSearchQuery(t)}}(r,e)},prefix:a,desc:Be,onKeyUp:function(r,n,i){var a,s,c,u=e.keyName(r);"Up"==u||"Down"==u?(a="Up"==u,s=r.target?r.target.selectionEnd:0,i(n=O.searchHistoryController.nextMatch(n,a)||""),s&&r.target&&(r.target.selectionEnd=r.target.selectionStart=Math.min(s,r.target.value.length))):"Left"!=u&&"Right"!=u&&"Ctrl"!=u&&"Alt"!=u&&"Shift"!=u&&O.searchHistoryController.reset();try{c=Ke(t,n,!0,!0)}catch(r){}c?t.scrollIntoView(Pe(t,!o,c),30):(je(t),t.scrollTo(l.left,l.top))},onKeyDown:function(r,n,o){var i=e.keyName(r);"Esc"==i||"Ctrl-C"==i||"Ctrl-["==i||"Backspace"==i&&""==n?(O.searchHistoryController.pushInput(n),O.searchHistoryController.reset(),Ke(t,s),je(t),t.scrollTo(l.left,l.top),e.e_stop(r),F(t),o(),t.focus()):"Up"==i||"Down"==i?e.e_stop(r):"Ctrl-U"==i&&(e.e_stop(r),o(""))}});break;case"wordUnderCursor":var u=me(t,!1,0,!1,!0),h=!0;if(u||(u=me(t,!1,0,!1,!1),h=!1),!u)return;var p=t.getLine(u.start.line).substring(u.start.ch,u.end.ch);p=h&&i?"\\b"+p+"\\b":p.replace(/([.?*+$\[\]\/\\(){}|\-])/g,"\\$1"),O.jumpList.cachedCursor=t.getCursor(),t.setCursor(u.start),f(p,!0,!1)}}function f(e,o,i){O.searchHistoryController.pushInput(e),O.searchHistoryController.reset();try{Ke(t,e,o,i)}catch(r){return Oe(t,"Invalid regex: "+e),void F(t)}U.processMotion(t,r,{type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:n.searchArgs.toJumplist}})}},processEx:function(t,r,n){function o(e){O.exCommandHistoryController.pushInput(e),O.exCommandHistoryController.reset(),Ve.processCommand(t,e)}function i(r,n,o){var i,a,s=e.keyName(r);("Esc"==s||"Ctrl-C"==s||"Ctrl-["==s||"Backspace"==s&&""==n)&&(O.exCommandHistoryController.pushInput(n),O.exCommandHistoryController.reset(),e.e_stop(r),F(t),o(),t.focus()),"Up"==s||"Down"==s?(e.e_stop(r),i="Up"==s,a=r.target?r.target.selectionEnd:0,o(n=O.exCommandHistoryController.nextMatch(n,i)||""),a&&r.target&&(r.target.selectionEnd=r.target.selectionStart=Math.min(a,r.target.value.length))):"Ctrl-U"==s?(e.e_stop(r),o("")):"Left"!=s&&"Right"!=s&&"Ctrl"!=s&&"Alt"!=s&&"Shift"!=s&&O.exCommandHistoryController.reset()}"keyToEx"==n.type?Ve.processCommand(t,n.exArgs.input):r.visualMode?Ie(t,{onClose:o,prefix:":",value:"'<,'>",onKeyDown:i,selectValueOnOpen:!1}):Ie(t,{onClose:o,prefix:":",onKeyDown:i})},evalInput:function(e,t){var r,o,i,a,s=t.inputState,l=s.motion,c=s.motionArgs||{},u=s.operator,h=s.operatorArgs||{},p=s.registerName,f=t.sel,d=ee(t.visualMode?z(e,f.head):e.getCursor("head")),m=ee(t.visualMode?z(e,f.anchor):e.getCursor("anchor")),g=ee(d),v=ee(m);if(u&&this.recordLastEdit(t,s),(i=void 0!==s.repeatOverride?s.repeatOverride:s.getRepeat())>0&&c.explicitRepeat?c.repeatIsExplicit=!0:(c.noRepeat||!c.explicitRepeat&&0===i)&&(i=1,c.repeatIsExplicit=!1),s.selectedCharacter&&(c.selectedCharacter=h.selectedCharacter=s.selectedCharacter),c.repeat=i,F(e),l){var y=J[l](e,d,c,t);if(t.lastMotion=J[l],!y)return;if(c.toJumplist){var k=O.jumpList,C=k.cachedCursor;C?(ge(e,C,y),delete k.cachedCursor):ge(e,d,y)}y instanceof Array?(o=y[0],r=y[1]):r=y,r||(r=ee(d)),t.visualMode?(t.visualBlock&&r.ch===1/0||(r=z(e,r,t.visualBlock)),o&&(o=z(e,o,!0)),o=o||v,f.anchor=o,f.head=r,he(e),Me(e,t,"<",re(o,r)?o:r),Me(e,t,">",re(o,r)?r:o)):u||(r=z(e,r),e.setCursor(r.line,r.ch))}if(u){if(h.lastSel){o=v;var w=h.lastSel,M=Math.abs(w.head.line-w.anchor.line),x=Math.abs(w.head.ch-w.anchor.ch);r=w.visualLine?n(v.line+M,v.ch):w.visualBlock?n(v.line+M,v.ch+x):w.head.line==w.anchor.line?n(v.line,v.ch+x):n(v.line+M,v.ch),t.visualMode=!0,t.visualLine=w.visualLine,t.visualBlock=w.visualBlock,f=t.sel={anchor:o,head:r},he(e)}else t.visualMode&&(h.lastSel={anchor:ee(f.anchor),head:ee(f.head),visualBlock:t.visualBlock,visualLine:t.visualLine});var A,b,L,T,R;if(t.visualMode){if(A=ne(f.head,f.anchor),b=oe(f.head,f.anchor),L=t.visualLine||h.linewise,R=pe(e,{anchor:A,head:b},T=t.visualBlock?"block":L?"line":"char"),L){var E=R.ranges;if("block"==T)for(var B=0;B<E.length;B++)E[B].head.ch=ae(e,E[B].head.line);else"line"==T&&(E[0].head=n(E[0].head.line+1,0))}}else{if(A=ee(o||v),re(b=ee(r||g),A)){var I=A;A=b,b=I}(L=c.linewise||h.linewise)?(a=b,A.ch=0,a.ch=0,a.line++):c.forward&&function(e,t,r){var n=e.getRange(t,r);if(/\n\s*$/.test(n)){var o=n.split("\n");o.pop();for(var i=o.pop();o.length>0&&i&&S(i);i=o.pop())r.line--,r.ch=0;i?(r.line--,r.ch=ae(e,r.line)):r.ch=0}}(e,A,b),R=pe(e,{anchor:A,head:b},T="char",!c.inclusive||L)}e.setSelections(R.ranges,R.primary),t.lastMotion=null,h.repeat=i,h.registerName=p,h.linewise=L;var K=q[u](e,h,R.ranges,v,r);t.visualMode&&fe(e,null!=K),K&&e.setCursor(K)}},recordLastEdit:function(e,t,r){var n=O.macroModeState;n.isPlaying||(e.lastEditInputState=t,e.lastEditActionCommand=r,n.lastInsertModeChanges.changes=[],n.lastInsertModeChanges.expectCursorActivityForChange=!1)}},J={moveToTopLine:function(e,t,r){var o=He(e).top+r.repeat-1;return n(o,de(e.getLine(o)))},moveToMiddleLine:function(e){var t=He(e),r=Math.floor(.5*(t.top+t.bottom));return n(r,de(e.getLine(r)))},moveToBottomLine:function(e,t,r){var o=He(e).bottom-r.repeat+1;return n(o,de(e.getLine(o)))},expandToLine:function(e,t,r){return n(t.line+r.repeat-1,1/0)},findNext:function(e,t,r){var n=Ae(e),o=n.getQuery();if(o){var i=!r.forward;return i=n.isReversed()?!i:i,Ne(e,o),Pe(e,i,o,r.repeat)}},goToMark:function(e,t,r,n){var o=_e(e,n,r.selectedCharacter);return o?r.linewise?{line:o.line,ch:de(e.getLine(o.line))}:o:null},moveToOtherHighlightedEnd:function(e,t,r,o){if(o.visualBlock&&r.sameLine){var i=o.sel;return[z(e,n(i.anchor.line,i.head.ch)),z(e,n(i.head.line,i.anchor.ch))]}return[o.sel.head,o.sel.anchor]},jumpToMark:function(e,t,r,o){for(var i=t,a=0;a<r.repeat;a++){var s=i;for(var l in o.marks)if(M(l)){var c=o.marks[l].find();if(!((r.forward?re(c,s):re(s,c))||r.linewise&&c.line==s.line)){var u=te(s,i),h=r.forward?ie(s,c,i):ie(i,c,s);(u||h)&&(i=c)}}}return r.linewise&&(i=n(i.line,de(e.getLine(i.line)))),i},moveByCharacters:function(e,t,r){var o=t,i=r.repeat,a=r.forward?o.ch+i:o.ch-i;return n(o.line,a)},moveByLines:function(e,t,r,o){var i=t,a=i.ch;switch(o.lastMotion){case this.moveByLines:case this.moveByDisplayLines:case this.moveByScroll:case this.moveToColumn:case this.moveToEol:a=o.lastHPos;break;default:o.lastHPos=a}var s=r.repeat+(r.repeatOffset||0),l=r.forward?i.line+s:i.line-s,c=e.firstLine(),u=e.lastLine();return l<c&&i.line==c?this.moveToStartOfLine(e,t,r,o):l>u&&i.line==u?this.moveToEol(e,t,r,o):(r.toFirstChar&&(a=de(e.getLine(l)),o.lastHPos=a),o.lastHSPos=e.charCoords(n(l,a),"div").left,n(l,a))},moveByDisplayLines:function(e,t,r,o){var i=t;switch(o.lastMotion){case this.moveByDisplayLines:case this.moveByScroll:case this.moveByLines:case this.moveToColumn:case this.moveToEol:break;default:o.lastHSPos=e.charCoords(i,"div").left}var a=r.repeat;if((l=e.findPosV(i,r.forward?a:-a,"line",o.lastHSPos)).hitSide)if(r.forward)var s={top:e.charCoords(l,"div").top+8,left:o.lastHSPos},l=e.coordsChar(s,"div");else{var c=e.charCoords(n(e.firstLine(),0),"div");c.left=o.lastHSPos,l=e.coordsChar(c,"div")}return o.lastHPos=l.ch,l},moveByPage:function(e,t,r){var n=t,o=r.repeat;return e.findPosV(n,r.forward?o:-o,"page")},moveByParagraph:function(e,t,r){var n=r.forward?1:-1;return xe(e,t,r.repeat,n)},moveBySentence:function(e,t,r){var o=r.forward?1:-1;return function(e,t,r,o){function i(e,t){if(t.pos+t.dir<0||t.pos+t.dir>=t.line.length){if(t.ln+=t.dir,!w(e,t.ln))return t.line=null,t.ln=null,void(t.pos=null);t.line=e.getLine(t.ln),t.pos=t.dir>0?0:t.line.length-1}else t.pos+=t.dir}function a(e,t,r,n){var o=e.getLine(t),a=""===o,s={line:o,ln:t,pos:r,dir:n},l={ln:s.ln,pos:s.pos},c=""===s.line;for(i(e,s);null!==s.line;){if(l.ln=s.ln,l.pos=s.pos,""===s.line&&!c)return{ln:s.ln,pos:s.pos};if(a&&""!==s.line&&!S(s.line[s.pos]))return{ln:s.ln,pos:s.pos};!A(s.line[s.pos])||a||s.pos!==s.line.length-1&&!S(s.line[s.pos+1])||(a=!0),i(e,s)}var o=e.getLine(l.ln);l.pos=0;for(var u=o.length-1;u>=0;--u)if(!S(o[u])){l.pos=u;break}return l}function s(e,t,r,n){var o=e.getLine(t),a={line:o,ln:t,pos:r,dir:n},s={ln:a.ln,pos:null},l=""===a.line;for(i(e,a);null!==a.line;){if(""===a.line&&!l)return null!==s.pos?s:{ln:a.ln,pos:a.pos};if(A(a.line[a.pos])&&null!==s.pos&&(a.ln!==s.ln||a.pos+1!==s.pos))return s;""===a.line||S(a.line[a.pos])||(l=!1,s={ln:a.ln,pos:a.pos}),i(e,a)}var o=e.getLine(s.ln);s.pos=0;for(var c=0;c<o.length;++c)if(!S(o[c])){s.pos=c;break}return s}for(var l={ln:t.line,pos:t.ch};r>0;)l=o<0?s(e,l.ln,l.pos,o):a(e,l.ln,l.pos,o),r--;return n(l.ln,l.pos)}(e,t,r.repeat,o)},moveByScroll:function(e,t,r,n){var o=e.getScrollInfo(),i=null,a=r.repeat;a||(a=o.clientHeight/(2*e.defaultTextHeight()));var s=e.charCoords(t,"local");if(r.repeat=a,!(i=J.moveByDisplayLines(e,t,r,n)))return null;var l=e.charCoords(i,"local");return e.scrollTo(null,o.top+l.top-s.top),i},moveByWords:function(e,t,r){return function(e,t,r,o,i,a){var s=ee(t),l=[];(o&&!i||!o&&i)&&r++;for(var c=!(o&&i),u=0;u<r;u++){var h=Ce(e,t,o,a,c);if(!h){var p=ae(e,e.lastLine());l.push(o?{line:e.lastLine(),from:p,to:p}:{line:0,from:0,to:0});break}l.push(h),t=n(h.line,o?h.to-1:h.from)}var f=l.length!=r,d=l[0],m=l.pop();return o&&!i?(f||d.from==s.ch&&d.line==s.line||(m=l.pop()),n(m.line,m.from)):o&&i?n(m.line,m.to-1):!o&&i?(f||d.to==s.ch&&d.line==s.line||(m=l.pop()),n(m.line,m.to)):n(m.line,m.from)}(e,t,r.repeat,!!r.forward,!!r.wordEnd,!!r.bigWord)},moveTillCharacter:function(e,t,r){var n=we(e,r.repeat,r.forward,r.selectedCharacter),o=r.forward?-1:1;return ve(o,r),n?(n.ch+=o,n):null},moveToCharacter:function(e,t,r){var n=r.repeat;return ve(0,r),we(e,n,r.forward,r.selectedCharacter)||t},moveToSymbol:function(e,t,r){return function(e,t,r,o){var i=ee(e.getCursor()),a=r?1:-1,s=r?e.lineCount():-1,l=i.ch,c=i.line,u=e.getLine(c),h={lineText:u,nextCh:u.charAt(l),lastCh:null,index:l,symb:o,reverseSymb:(r?{")":"(","}":"{"}:{"(":")","{":"}"})[o],forward:r,depth:0,curMoveThrough:!1},p=ye[o];if(!p)return i;var f=ke[p].init,d=ke[p].isComplete;for(f&&f(h);c!==s&&t;){if(h.index+=a,h.nextCh=h.lineText.charAt(h.index),!h.nextCh){if(c+=a,h.lineText=e.getLine(c)||"",a>0)h.index=0;else{var m=h.lineText.length;h.index=m>0?m-1:0}h.nextCh=h.lineText.charAt(h.index)}d(h)&&(i.line=c,i.ch=h.index,t--)}return h.nextCh||h.curMoveThrough?n(c,h.index):i}(e,r.repeat,r.forward,r.selectedCharacter)||t},moveToColumn:function(e,t,r,o){var i,a,s,l=r.repeat;return o.lastHPos=l-1,o.lastHSPos=e.charCoords(t,"div").left,a=l,s=(i=e).getCursor().line,z(i,n(s,a-1))},moveToEol:function(e,t,r,o){var i=t;o.lastHPos=1/0;var a=n(i.line+r.repeat-1,1/0),s=e.clipPos(a);return s.ch--,o.lastHSPos=e.charCoords(s,"div").left,a},moveToFirstNonWhiteSpaceCharacter:function(e,t){var r=t;return n(r.line,de(e.getLine(r.line)))},moveToMatchedSymbol:function(e,t){for(var r,o=t,i=o.line,a=o.ch,s=e.getLine(i);a<s.length;a++)if((r=s.charAt(a))&&-1!="()[]{}".indexOf(r)){var l=e.getTokenTypeAt(n(i,a+1));if("string"!==l&&"comment"!==l)break}return a<s.length?e.findMatchingBracket(n(i,a)).to:o},moveToStartOfLine:function(e,t){return n(t.line,0)},moveToLineOrEdgeOfDocument:function(e,t,r){var o=r.forward?e.lastLine():e.firstLine();return r.repeatIsExplicit&&(o=r.repeat-e.getOption("firstLineNumber")),n(o,de(e.getLine(o)))},textObjectManipulation:function(e,t,r,o){var i=r.selectedCharacter;"b"==i?i="(":"B"==i&&(i="{");var a,s,l,c,u,h,p,f,d=!r.textObjectInner;if({"(":")",")":"(","{":"}","}":"{","[":"]","]":"["}[i])a=function(e,t,r,o){var i,a,s=t,l={"(":/[()]/,")":/[()]/,"[":/[[\]]/,"]":/[[\]]/,"{":/[{}]/,"}":/[{}]/}[r],c={"(":"(",")":"(","[":"[","]":"[","{":"{","}":"{"}[r],u=e.getLine(s.line).charAt(s.ch)===c?1:0;if(i=e.scanForBracket(n(s.line,s.ch+u),-1,void 0,{bracketRegex:l}),a=e.scanForBracket(n(s.line,s.ch+u),1,void 0,{bracketRegex:l}),!i||!a)return{start:s,end:s};if(i=i.pos,a=a.pos,i.line==a.line&&i.ch>a.ch||i.line>a.line){var h=i;i=a,a=h}return o?a.ch+=1:i.ch+=1,{start:i,end:a}}(e,t,i,d);else if({"'":!0,'"':!0}[i])a=function(e,t,r,o){var i,a,s,l,c=ee(t),u=e.getLine(c.line).split(""),h=u.indexOf(r);if(c.ch<h?c.ch=h:h<c.ch&&u[c.ch]==r&&(a=c.ch,--c.ch),u[c.ch]!=r||a)for(s=c.ch;s>-1&&!i;s--)u[s]==r&&(i=s+1);else i=c.ch+1;if(i&&!a)for(s=i,l=u.length;s<l&&!a;s++)u[s]==r&&(a=s);return i&&a?(o&&(--i,++a),{start:n(c.line,i),end:n(c.line,a)}):{start:c,end:c}}(e,t,i,d);else if("W"===i)a=me(e,d,0,!0);else if("w"===i)a=me(e,d,0,!1);else{if("p"!==i)return null;if(a=xe(e,t,r.repeat,0,d),r.linewise=!0,o.visualMode)o.visualLine||(o.visualLine=!0);else{var m=o.inputState.operatorArgs;m&&(m.linewise=!0),a.end.line--}}return e.state.vim.visualMode?(s=e,l=a.start,c=a.end,h=s.state.vim.sel,p=h.head,f=h.anchor,re(c,l)&&(u=c,c=l,l=u),re(p,f)?(p=ne(l,p),f=oe(f,c)):(f=ne(l,f),-1==(p=G(p=oe(p,c),0,-1)).ch&&p.line!=s.firstLine()&&(p=n(p.line-1,ae(s,p.line-1)))),[f,p]):[a.start,a.end]},repeatLastCharacterSearch:function(e,t,r){var n=O.lastCharacterSearch,o=r.repeat,i=r.forward===n.forward,a=(n.increment?1:0)*(i?-1:1);e.moveH(-a,"char"),r.inclusive=!!i;var s=we(e,o,i,n.selectedCharacter);return s?(s.ch+=a,s):(e.moveH(a,"char"),t)}};function $(e,t){for(var r=[],n=0;n<t;n++)r.push(e);return r}var q={change:function(t,r,o){var i,a,s=t.state.vim;if(O.macroModeState.lastInsertModeChanges.inVisualBlock=s.visualBlock,s.visualMode){a=t.getSelection();var l=$("",o.length);t.replaceSelections(l),i=ne(o[0].head,o[0].anchor)}else{var c=o[0].anchor,u=o[0].head;a=t.getRange(c,u);var h=s.lastEditInputState||{};if("moveByWords"==h.motion&&!S(a)){var p=/\s+$/.exec(a);p&&h.motionArgs&&h.motionArgs.forward&&(u=G(u,0,-p[0].length),a=a.slice(0,-p[0].length))}var f=new n(c.line-1,Number.MAX_VALUE),d=t.firstLine()==t.lastLine();u.line>t.lastLine()&&r.linewise&&!d?t.replaceRange("",f,u):t.replaceRange("",c,u),r.linewise&&(d||(t.setCursor(f),e.commands.newlineAndIndent(t)),c.ch=Number.MAX_VALUE),i=c}O.registerController.pushText(r.registerName,"change",a,r.linewise,o.length>1),Q.enterInsertMode(t,{head:i},t.state.vim)},delete:function(e,t,r){var o,i,a=e.state.vim;if(a.visualBlock){i=e.getSelection();var s=$("",r.length);e.replaceSelections(s),o=r[0].anchor}else{var l=r[0].anchor,c=r[0].head;t.linewise&&c.line!=e.firstLine()&&l.line==e.lastLine()&&l.line==c.line-1&&(l.line==e.firstLine()?l.ch=0:l=n(l.line-1,ae(e,l.line-1))),i=e.getRange(l,c),e.replaceRange("",l,c),o=l,t.linewise&&(o=J.moveToFirstNonWhiteSpaceCharacter(e,l))}return O.registerController.pushText(t.registerName,"delete",i,t.linewise,a.visualBlock),z(e,o,a.insertMode)},indent:function(e,t,r){var n=e.state.vim,o=r[0].anchor.line,i=n.visualBlock?r[r.length-1].anchor.line:r[0].head.line,a=n.visualMode?t.repeat:1;t.linewise&&i--;for(var s=o;s<=i;s++)for(var l=0;l<a;l++)e.indentLine(s,t.indentRight);return J.moveToFirstNonWhiteSpaceCharacter(e,r[0].anchor)},changeCase:function(e,t,r,n,o){for(var i=e.getSelections(),a=[],s=t.toLower,l=0;l<i.length;l++){var c=i[l],u="";if(!0===s)u=c.toLowerCase();else if(!1===s)u=c.toUpperCase();else for(var h=0;h<c.length;h++){var p=c.charAt(h);u+=x(p)?p.toLowerCase():p.toUpperCase()}a.push(u)}return e.replaceSelections(a),t.shouldMoveCursor?o:!e.state.vim.visualMode&&t.linewise&&r[0].anchor.line+1==r[0].head.line?J.moveToFirstNonWhiteSpaceCharacter(e,n):t.linewise?n:ne(r[0].anchor,r[0].head)},yank:function(e,t,r,n){var o=e.state.vim,i=e.getSelection(),a=o.visualMode?ne(o.sel.anchor,o.sel.head,r[0].head,r[0].anchor):n;return O.registerController.pushText(t.registerName,"yank",i,t.linewise,o.visualBlock),a}};var Q={jumpListWalk:function(e,t,r){if(!r.visualMode){var n=t.repeat,o=t.forward,i=O.jumpList.move(e,o?n:-n),a=i?i.find():void 0;a=a||e.getCursor(),e.setCursor(a)}},scroll:function(e,t,r){if(!r.visualMode){var n=t.repeat||1,o=e.defaultTextHeight(),i=e.getScrollInfo().top,a=o*n,s=t.forward?i+a:i-a,l=ee(e.getCursor()),c=e.charCoords(l,"local");if(t.forward)s>c.top?(l.line+=(s-c.top)/o,l.line=Math.ceil(l.line),e.setCursor(l),c=e.charCoords(l,"local"),e.scrollTo(null,c.top)):e.scrollTo(null,s);else{var u=s+e.getScrollInfo().clientHeight;u<c.bottom?(l.line-=(c.bottom-u)/o,l.line=Math.floor(l.line),e.setCursor(l),c=e.charCoords(l,"local"),e.scrollTo(null,c.bottom-e.getScrollInfo().clientHeight)):e.scrollTo(null,s)}}},scrollToCursor:function(e,t){var r=e.getCursor().line,o=e.charCoords(n(r,0),"local"),i=e.getScrollInfo().clientHeight,a=o.top,s=o.bottom-a;switch(t.position){case"center":a=a-i/2+s;break;case"bottom":a=a-i+s}e.scrollTo(null,a)},replayMacro:function(e,t,r){var n=t.selectedCharacter,o=t.repeat,i=O.macroModeState;for("@"==n&&(n=i.latestRegister);o--;)Je(e,r,i,n)},enterMacroRecordMode:function(e,t){var r=O.macroModeState,n=t.selectedCharacter;O.registerController.isValidRegister(n)&&r.enterMacroRecordMode(e,n)},toggleOverwrite:function(t){t.state.overwrite?(t.toggleOverwrite(!1),t.setOption("keyMap","vim-insert"),e.signal(t,"vim-mode-change",{mode:"insert"})):(t.toggleOverwrite(!0),t.setOption("keyMap","vim-replace"),e.signal(t,"vim-mode-change",{mode:"replace"}))},enterInsertMode:function(t,r,o){if(!t.getOption("readOnly")){o.insertMode=!0,o.insertModeRepeat=r&&r.repeat||1;var i=r?r.insertAt:null,a=o.sel,s=r.head||t.getCursor("head"),l=t.listSelections().length;if("eol"==i)s=n(s.line,ae(t,s.line));else if("charAfter"==i)s=G(s,0,1);else if("firstNonBlank"==i)s=J.moveToFirstNonWhiteSpaceCharacter(t,s);else if("startOfSelectedArea"==i)o.visualBlock?(s=n(Math.min(a.head.line,a.anchor.line),Math.min(a.head.ch,a.anchor.ch)),l=Math.abs(a.head.line-a.anchor.line)+1):s=a.head.line<a.anchor.line?a.head:n(a.anchor.line,0);else if("endOfSelectedArea"==i)o.visualBlock?(s=n(Math.min(a.head.line,a.anchor.line),Math.max(a.head.ch+1,a.anchor.ch)),l=Math.abs(a.head.line-a.anchor.line)+1):s=a.head.line>=a.anchor.line?G(a.head,0,1):n(a.anchor.line,0);else if("inplace"==i&&o.visualMode)return;t.setOption("disableInput",!1),r&&r.replace?(t.toggleOverwrite(!0),t.setOption("keyMap","vim-replace"),e.signal(t,"vim-mode-change",{mode:"replace"})):(t.toggleOverwrite(!1),t.setOption("keyMap","vim-insert"),e.signal(t,"vim-mode-change",{mode:"insert"})),O.macroModeState.isPlaying||(t.on("change",$e),e.on(t.getInputField(),"keydown",Ze)),o.visualMode&&fe(t),ce(t,s,l)}},toggleVisualMode:function(t,r,o){var i,a=r.repeat,s=t.getCursor();o.visualMode?o.visualLine^r.linewise||o.visualBlock^r.blockwise?(o.visualLine=!!r.linewise,o.visualBlock=!!r.blockwise,e.signal(t,"vim-mode-change",{mode:"visual",subMode:o.visualLine?"linewise":o.visualBlock?"blockwise":""}),he(t)):fe(t):(o.visualMode=!0,o.visualLine=!!r.linewise,o.visualBlock=!!r.blockwise,i=z(t,n(s.line,s.ch+a-1),!0),o.sel={anchor:s,head:i},e.signal(t,"vim-mode-change",{mode:"visual",subMode:o.visualLine?"linewise":o.visualBlock?"blockwise":""}),he(t),Me(t,o,"<",ne(s,i)),Me(t,o,">",oe(s,i)))},reselectLastSelection:function(t,r,n){var o=n.lastSelection;if(n.visualMode&&ue(t,n),o){var i=o.anchorMark.find(),a=o.headMark.find();if(!i||!a)return;n.sel={anchor:i,head:a},n.visualMode=!0,n.visualLine=o.visualLine,n.visualBlock=o.visualBlock,he(t),Me(t,n,"<",ne(i,a)),Me(t,n,">",oe(i,a)),e.signal(t,"vim-mode-change",{mode:"visual",subMode:n.visualLine?"linewise":n.visualBlock?"blockwise":""})}},joinLines:function(e,t,r){var o,i;if(r.visualMode){if(o=e.getCursor("anchor"),re(i=e.getCursor("head"),o)){var a=i;i=o,o=a}i.ch=ae(e,i.line)-1}else{var s=Math.max(t.repeat,2);o=e.getCursor(),i=z(e,n(o.line+s-1,1/0))}for(var l=0,c=o.line;c<i.line;c++){l=ae(e,o.line),a=n(o.line+1,ae(e,o.line+1));var u=e.getRange(o,a);u=u.replace(/\n\s*/g," "),e.replaceRange(u,o,a)}var h=n(o.line,l);r.visualMode&&fe(e,!1),e.setCursor(h)},newLineAndEnterInsertMode:function(t,r,o){o.insertMode=!0;var i=ee(t.getCursor());i.line!==t.firstLine()||r.after?(i.line=r.after?i.line:i.line-1,i.ch=ae(t,i.line),t.setCursor(i),(e.commands.newlineAndIndentContinueComment||e.commands.newlineAndIndent)(t)):(t.replaceRange("\n",n(t.firstLine(),0)),t.setCursor(t.firstLine(),0)),this.enterInsertMode(t,{repeat:r.repeat},o)},paste:function(e,t,r){var o,i,a,s,l,c=ee(e.getCursor()),u=O.registerController.getRegister(t.registerName);if(y=u.toString()){if(t.matchIndent){var h=e.getOption("tabSize"),p=function(e){var t=e.split("\t").length-1,r=e.split(" ").length-1;return t*h+1*r},f=e.getLine(e.getCursor().line),d=p(f.match(/^\s*/)[0]),m=y.replace(/\n$/,""),g=y!==m,v=p(y.match(/^\s*/)[0]),y=m.replace(/^\s*/gm,function(t){var r=d+(p(t)-v);if(r<0)return"";if(e.getOption("indentWithTabs")){var n=Math.floor(r/h);return Array(n+1).join("\t")}return Array(r+1).join(" ")});y+=g?"\n":""}t.repeat>1&&(y=Array(t.repeat+1).join(y));var k,C,w,M,x,S,A,b,L,T,R=u.linewise,E=u.blockwise;if(R)r.visualMode?y=r.visualLine?y.slice(0,-1):"\n"+y.slice(0,y.length-1)+"\n":t.after?(y="\n"+y.slice(0,y.length-1),c.ch=ae(e,c.line)):c.ch=0;else{if(E){y=y.split("\n");for(var B=0;B<y.length;B++)y[B]=""==y[B]?" ":y[B]}c.ch+=t.after?1:0}if(r.visualMode){var I;r.lastPastedText=y;var K=(w=e,x=(M=r).lastSelection,M.visualMode?(S=w.listSelections(),A=S[0],b=S[S.length-1],L=re(A.anchor,A.head)?A.anchor:A.head,T=re(b.anchor,b.head)?b.head:b.anchor,[L,T]):function(){var e=w.getCursor(),t=w.getCursor(),r=x.visualBlock;if(r){var o=r.width,i=r.height;t=n(e.line+i,e.ch+o);for(var a=[],s=e.line;s<t.line;s++){var l=n(s,e.ch),c=n(s,t.ch),u={anchor:l,head:c};a.push(u)}w.setSelections(a)}else{var h=x.anchorMark.find(),p=x.headMark.find(),f=p.line-h.line,d=p.ch-h.ch;t={line:t.line+f,ch:f?t.ch:d+t.ch},x.visualLine&&(e=n(e.line,0),t=n(t.line,ae(w,t.line))),w.setSelection(e,t)}return[e,t]}()),N=K[0],P=K[1],j=e.getSelection(),H=e.listSelections(),_=new Array(H.length).join("1").split("1");r.lastSelection&&(I=r.lastSelection.headMark.find()),O.registerController.unnamedRegister.setText(j),E?(e.replaceSelections(_),P=n(N.line+y.length-1,N.ch),e.setCursor(N),le(e,P),e.replaceSelections(y),k=N):r.visualBlock?(e.replaceSelections(_),e.setCursor(N),e.replaceRange(y,N,N),k=N):(e.replaceRange(y,N,P),k=e.posFromIndex(e.indexFromPos(N)+y.length-1)),I&&(r.lastSelection.headMark=e.setBookmark(I)),R&&(k.ch=0)}else if(E){for(e.setCursor(c),B=0;B<y.length;B++){var F=c.line+B;F>e.lastLine()&&e.replaceRange("\n",n(F,0)),ae(e,F)<c.ch&&(o=e,i=F,a=c.ch,void 0,void 0,s=ae(o,i),l=new Array(a-s+1).join(" "),o.setCursor(n(i,s)),o.replaceRange(l,o.getCursor()))}e.setCursor(c),le(e,n(c.line+y.length-1,c.ch)),e.replaceSelections(y),k=c}else e.replaceRange(y,c),R&&t.after?k=n(c.line+1,de(e.getLine(c.line+1))):R&&!t.after?k=n(c.line,de(e.getLine(c.line))):!R&&t.after?(C=e.indexFromPos(c),k=e.posFromIndex(C+y.length-1)):(C=e.indexFromPos(c),k=e.posFromIndex(C+y.length));r.visualMode&&fe(e,!1),e.setCursor(k)}},undo:function(t,r){t.operation(function(){Y(t,e.commands.undo,r.repeat)(),t.setCursor(t.getCursor("anchor"))})},redo:function(t,r){Y(t,e.commands.redo,r.repeat)()},setRegister:function(e,t,r){r.inputState.registerName=t.selectedCharacter},setMark:function(e,t,r){Me(e,r,t.selectedCharacter,e.getCursor())},replace:function(t,r,o){var i,a,s=r.selectedCharacter,l=t.getCursor(),c=t.listSelections();if(o.visualMode)l=t.getCursor("start"),a=t.getCursor("end");else{var u=t.getLine(l.line);(i=l.ch+r.repeat)>u.length&&(i=u.length),a=n(l.line,i)}if("\n"==s)o.visualMode||t.replaceRange("",l,a),(e.commands.newlineAndIndentContinueComment||e.commands.newlineAndIndent)(t);else{var h=t.getRange(l,a);if(h=h.replace(/[^\n]/g,s),o.visualBlock){var p=new Array(t.getOption("tabSize")+1).join(" ");h=(h=t.getSelection()).replace(/\t/g,p).replace(/[^\n]/g,s).split("\n"),t.replaceSelections(h)}else t.replaceRange(h,l,a);o.visualMode?(l=re(c[0].anchor,c[0].head)?c[0].anchor:c[0].head,t.setCursor(l),fe(t,!1)):t.setCursor(G(a,0,-1))}},incrementNumberToken:function(e,t){for(var r,o,i,a,s=e.getCursor(),l=e.getLine(s.line),c=/(-?)(?:(0x)([\da-f]+)|(0b|0|)(\d+))/gi;null!==(r=c.exec(l))&&(i=(o=r.index)+r[0].length,!(s.ch<i)););if((t.backtrack||!(i<=s.ch))&&r){var u=r[2]||r[4],h=r[3]||r[5],p=t.increase?1:-1,f={"0b":2,0:8,"":10,"0x":16}[u.toLowerCase()];a=(parseInt(r[1]+h,f)+p*t.repeat).toString(f);var d=u?new Array(h.length-a.length+1+r[1].length).join("0"):"";a="-"===a.charAt(0)?"-"+u+d+a.substr(1):u+d+a;var m=n(s.line,o),g=n(s.line,i);e.replaceRange(a,m,g),e.setCursor(n(s.line,o+a.length-1))}},repeatLastEdit:function(e,t,r){if(r.lastEditInputState){var n=t.repeat;n&&t.repeatIsExplicit?r.lastEditInputState.repeatOverride=n:n=r.lastEditInputState.repeatOverride||n,Ge(e,r,n,!1)}},indent:function(e,t){e.indentLine(e.getCursor().line,t.indentRight)},exitInsertMode:De};function z(e,t,r){var o=Math.min(Math.max(e.firstLine(),t.line),e.lastLine()),i=ae(e,o)-1;i=r?i+1:i;var a=Math.min(Math.max(0,t.ch),i);return n(o,a)}function Z(e){var t={};for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}function G(e,t,r){return"object"==typeof t&&(r=t.ch,t=t.line),n(e.line+t,e.ch+r)}function X(e,t){if("<character>"==t.slice(-11)){var r=t.length-11,n=e.slice(0,r),o=t.slice(0,r);return n==o&&e.length>r?"full":0==o.indexOf(n)&&"partial"}return e==t?"full":0==t.indexOf(e)&&"partial"}function Y(e,t,r){return function(){for(var n=0;n<r;n++)t(e)}}function ee(e){return n(e.line,e.ch)}function te(e,t){return e.ch==t.ch&&e.line==t.line}function re(e,t){return e.line<t.line||e.line==t.line&&e.ch<t.ch}function ne(e,t){return arguments.length>2&&(t=ne.apply(void 0,Array.prototype.slice.call(arguments,1))),re(e,t)?e:t}function oe(e,t){return arguments.length>2&&(t=oe.apply(void 0,Array.prototype.slice.call(arguments,1))),re(e,t)?t:e}function ie(e,t,r){var n=re(e,t),o=re(t,r);return n&&o}function ae(e,t){return e.getLine(t).length}function se(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function le(e,t){var r=[],o=e.listSelections(),i=ee(e.clipPos(t)),a=!te(t,i),s=function(e,t,r){for(var n=0;n<e.length;n++){var o="head"!=r&&te(e[n].anchor,t),i="anchor"!=r&&te(e[n].head,t);if(o||i)return n}return-1}(o,e.getCursor("head")),l=te(o[s].head,o[s].anchor),c=o.length-1,u=c-s>s?c:0,h=o[u].anchor,p=Math.min(h.line,i.line),f=Math.max(h.line,i.line),d=h.ch,m=i.ch,g=o[u].head.ch-d,v=m-d;g>0&&v<=0?(d++,a||m--):g<0&&v>=0?(d--,l||m++):g<0&&-1==v&&(d--,m++);for(var y=p;y<=f;y++){var k={anchor:new n(y,d),head:new n(y,m)};r.push(k)}return e.setSelections(r),t.ch=m,h.ch=d,h}function ce(e,t,r){for(var n=[],o=0;o<r;o++){var i=G(t,o,0);n.push({anchor:i,head:i})}e.setSelections(n,0)}function ue(e,t){var r=t.sel.anchor,n=t.sel.head;t.lastPastedText&&(n=e.posFromIndex(e.indexFromPos(r)+t.lastPastedText.length),t.lastPastedText=null),t.lastSelection={anchorMark:e.setBookmark(r),headMark:e.setBookmark(n),anchor:ee(r),head:ee(n),visualMode:t.visualMode,visualLine:t.visualLine,visualBlock:t.visualBlock}}function he(e,t,r){var n=e.state.vim,o=pe(e,t=t||n.sel,r=r||n.visualLine?"line":n.visualBlock?"block":"char");e.setSelections(o.ranges,o.primary),Qe(e)}function pe(e,t,r,o){var i=ee(t.head),a=ee(t.anchor);if("char"==r){var s=o||re(t.head,t.anchor)?0:1,l=re(t.head,t.anchor)?1:0;return i=G(t.head,0,s),{ranges:[{anchor:a=G(t.anchor,0,l),head:i}],primary:0}}if("line"==r){if(re(t.head,t.anchor))i.ch=0,a.ch=ae(e,a.line);else{a.ch=0;var c=e.lastLine();i.line>c&&(i.line=c),i.ch=ae(e,i.line)}return{ranges:[{anchor:a,head:i}],primary:0}}if("block"==r){for(var u=Math.min(a.line,i.line),h=Math.min(a.ch,i.ch),p=Math.max(a.line,i.line),f=Math.max(a.ch,i.ch)+1,d=p-u+1,m=i.line==u?0:d-1,g=[],v=0;v<d;v++)g.push({anchor:n(u+v,h),head:n(u+v,f)});return{ranges:g,primary:m}}}function fe(t,r){var n=t.state.vim;!1!==r&&t.setCursor(z(t,n.sel.head)),ue(t,n),n.visualMode=!1,n.visualLine=!1,n.visualBlock=!1,e.signal(t,"vim-mode-change",{mode:"normal"}),n.fakeCursor&&n.fakeCursor.clear()}function de(e){if(!e)return 0;var t=e.search(/\S/);return-1==t?e.length:t}function me(e,t,r,o,i){for(var a,s,l=(s=(a=e).getCursor("head"),1==a.getSelection().length&&(s=ne(s,a.getCursor("anchor"))),s),c=e.getLine(l.line),u=l.ch,h=i?f[0]:d[0];!h(c.charAt(u));)if(++u>=c.length)return null;o?h=d[0]:(h=f[0])(c.charAt(u))||(h=f[1]);for(var p=u,m=u;h(c.charAt(p))&&p<c.length;)p++;for(;h(c.charAt(m))&&m>=0;)m--;if(m++,t){for(var g=p;/\s/.test(c.charAt(p))&&p<c.length;)p++;if(g==p){for(var v=m;/\s/.test(c.charAt(m-1))&&m>0;)m--;m||(m=v)}}return{start:n(l.line,m),end:n(l.line,p)}}function ge(e,t,r){te(t,r)||O.jumpList.add(e,t,r)}function ve(e,t){O.lastCharacterSearch.increment=e,O.lastCharacterSearch.forward=t.forward,O.lastCharacterSearch.selectedCharacter=t.selectedCharacter}var ye={"(":"bracket",")":"bracket","{":"bracket","}":"bracket","[":"section","]":"section","*":"comment","/":"comment",m:"method",M:"method","#":"preprocess"},ke={bracket:{isComplete:function(e){if(e.nextCh===e.symb){if(e.depth++,e.depth>=1)return!0}else e.nextCh===e.reverseSymb&&e.depth--;return!1}},section:{init:function(e){e.curMoveThrough=!0,e.symb=(e.forward?"]":"[")===e.symb?"{":"}"},isComplete:function(e){return 0===e.index&&e.nextCh===e.symb}},comment:{isComplete:function(e){var t="*"===e.lastCh&&"/"===e.nextCh;return e.lastCh=e.nextCh,t}},method:{init:function(e){e.symb="m"===e.symb?"{":"}",e.reverseSymb="{"===e.symb?"}":"{"},isComplete:function(e){return e.nextCh===e.symb}},preprocess:{init:function(e){e.index=0},isComplete:function(e){if("#"===e.nextCh){var t=e.lineText.match(/#(\w+)/)[1];if("endif"===t){if(e.forward&&0===e.depth)return!0;e.depth++}else if("if"===t){if(!e.forward&&0===e.depth)return!0;e.depth--}if("else"===t&&0===e.depth)return!0}return!1}}};function Ce(e,t,r,n,o){var i=t.line,a=t.ch,s=e.getLine(i),l=r?1:-1,c=n?d:f;if(o&&""==s){if(i+=l,s=e.getLine(i),!w(e,i))return null;a=r?0:s.length}for(;;){if(o&&""==s)return{from:0,to:0,line:i};for(var u=l>0?s.length:-1,h=u,p=u;a!=u;){for(var m=!1,g=0;g<c.length&&!m;++g)if(c[g](s.charAt(a))){for(h=a;a!=u&&c[g](s.charAt(a));)a+=l;if(m=h!=(p=a),h==t.ch&&i==t.line&&p==h+l)continue;return{from:Math.min(h,p+1),to:Math.max(h,p),line:i}}m||(a+=l)}if(!w(e,i+=l))return null;s=e.getLine(i),a=l>0?0:s.length}}function we(e,t,r,o){for(var i,a=e.getCursor(),s=a.ch,l=0;l<t;l++){if(-1==(c=s,u=e.getLine(a.line),h=o,p=!0,f=void 0,r?-1==(f=u.indexOf(h,c+1))||p||(f-=1):-1==(f=u.lastIndexOf(h,c-1))||p||(f+=1),i=f))return null;s=i}var c,u,h,p,f;return n(e.getCursor().line,i)}function Me(e,t,r,n){b(r,k)&&(t.marks[r]&&t.marks[r].clear(),t.marks[r]=e.setBookmark(n))}function xe(e,t,r,o,i){var a,s=t.line,l=e.firstLine(),c=e.lastLine(),u=s;function h(t){return!e.getLine(t)}function p(e,t,r){return r?h(e)!=h(e+t):!h(e)&&h(e+t)}if(o){for(;l<=u&&u<=c&&r>0;)p(u,o)&&r--,u+=o;return new n(u,0)}var f=e.state.vim;if(f.visualLine&&p(s,1,!0)){var d=f.sel.anchor;p(d.line,-1,!0)&&(i&&d.line==s||(s+=1))}var m=h(s);for(u=s;u<=c&&r;u++)p(u,1,!0)&&(i&&h(u)==m||r--);for(a=new n(u,0),u>c&&!m?m=!0:i=!1,u=s;u>l&&(i&&h(u)!=m&&u!=s||!p(u,-1,!0));u--);return{start:new n(u,0),end:a}}function Se(){}function Ae(e){var t=e.state.vim;return t.searchState_||(t.searchState_=new Se)}function be(e,t){var r=Le(e,t)||[];if(!r.length)return[];var n=[];if(0===r[0]){for(var o=0;o<r.length;o++)"number"==typeof r[o]&&n.push(e.substring(r[o]+1,r[o+1]));return n}}function Le(e,t){t||(t="/");for(var r=!1,n=[],o=0;o<e.length;o++){var i=e.charAt(o);r||i!=t||n.push(o),r=!r&&"\\"==i}return n}T("pcre",!0,"boolean"),Se.prototype={getQuery:function(){return O.query},setQuery:function(e){O.query=e},getOverlay:function(){return this.searchOverlay},setOverlay:function(e){this.searchOverlay=e},isReversed:function(){return O.isReversed},setReversed:function(e){O.isReversed=e},getScrollbarAnnotate:function(){return this.annotate},setScrollbarAnnotate:function(e){this.annotate=e}};var Te={"\\n":"\n","\\r":"\r","\\t":"\t"};var Re={"\\/":"/","\\\\":"\\","\\n":"\n","\\r":"\r","\\t":"\t"};function Ee(e,t,r){if(O.registerController.getRegister("/").setText(e),e instanceof RegExp)return e;var n,o,i=Le(e,"/");return i.length?(n=e.substring(0,i[0]),o=-1!=e.substring(i[0]).indexOf("i")):n=e,n?(E("pcre")||(n=function(e){for(var t=!1,r=[],n=-1;n<e.length;n++){var o=e.charAt(n)||"",i=e.charAt(n+1)||"",a=i&&-1!="|(){".indexOf(i);t?("\\"===o&&a||r.push(o),t=!1):"\\"===o?(t=!0,i&&-1!="}".indexOf(i)&&(a=!0),a&&"\\"!==i||r.push(o)):(r.push(o),a&&"\\"!==i&&r.push("\\"))}return r.join("")}(n)),r&&(t=/^[^A-Z]*$/.test(n)),new RegExp(n,t||o?"i":void 0)):null}function Oe(e,t){e.openNotification?e.openNotification('<span style="color: red">'+t+"</span>",{bottom:!0,duration:5e3}):alert(t)}var Be="(Javascript regexp)";function Ie(e,t){var r,n,o,i,a,s,l,c,u=(t.prefix||"")+" "+(t.desc||""),h=(r=t.prefix,n=t.desc,o='<span style="font-family: monospace; white-space: pre">'+(r||"")+'<input type="text"></span>',n&&(o+=' <span style="color: #888">'+n+"</span>"),o);i=e,a=h,s=u,l=t.onClose,c=t,i.openDialog?i.openDialog(a,l,{bottom:!0,value:c.value,onKeyDown:c.onKeyDown,onKeyUp:c.onKeyUp,selectValueOnOpen:!1}):l(prompt(s,""))}function Ke(e,t,r,n){if(t){var o=Ae(e),i=Ee(t,!!r,!!n);if(i)return Ne(e,i),function(e,t){if(e instanceof RegExp&&t instanceof RegExp){for(var r=["global","multiline","ignoreCase","source"],n=0;n<r.length;n++){var o=r[n];if(e[o]!==t[o])return!1}return!0}return!1}(i,o.getQuery())?i:(o.setQuery(i),i)}}function Ne(e,t){var r=Ae(e),n=r.getOverlay();n&&t==n.query||(n&&e.removeOverlay(n),n=function(e){if("^"==e.source.charAt(0))var t=!0;return{token:function(r){if(!t||r.sol()){var n=r.match(e,!1);if(n)return 0==n[0].length?(r.next(),"searching"):r.sol()||(r.backUp(1),e.exec(r.next()+n[0]))?(r.match(e),"searching"):(r.next(),null);for(;!r.eol()&&(r.next(),!r.match(e,!1)););}else r.skipToEnd()},query:e}}(t),e.addOverlay(n),e.showMatchesOnScrollbar&&(r.getScrollbarAnnotate()&&r.getScrollbarAnnotate().clear(),r.setScrollbarAnnotate(e.showMatchesOnScrollbar(t))),r.setOverlay(n))}function Pe(e,t,r,o){return void 0===o&&(o=1),e.operation(function(){for(var i=e.getCursor(),a=e.getSearchCursor(r,i),s=0;s<o;s++){var l=a.find(t);if(0==s&&l&&te(a.from(),i)&&(l=a.find(t)),!l&&!(a=e.getSearchCursor(r,t?n(e.lastLine()):n(e.firstLine(),0))).find(t))return}return a.from()})}function je(e){var t=Ae(e);e.removeOverlay(Ae(e).getOverlay()),t.setOverlay(null),t.getScrollbarAnnotate()&&(t.getScrollbarAnnotate().clear(),t.setScrollbarAnnotate(null))}function He(e){var t=e.getScrollInfo(),r=e.coordsChar({left:0,top:6+t.top},"local"),n=t.clientHeight-10+t.top,o=e.coordsChar({left:0,top:n},"local");return{top:r.line,bottom:o.line}}function _e(e,t,r){if("'"==r){var n=e.doc.history.done,o=n[n.length-2];return o&&o.ranges&&o.ranges[0].head}if("."==r){if(0==e.doc.history.lastModTime)return;var i=e.doc.history.done.filter(function(e){if(void 0!==e.changes)return e});return i.reverse(),i[0].changes[0].to}var a=t.marks[r];return a&&a.find()}var Fe=function(){this.buildCommandMap_()};Fe.prototype={processCommand:function(e,t,r){var n=this;e.operation(function(){e.curOp.isVimOp=!0,n._processCommand(e,t,r)})},_processCommand:function(t,r,n){var o=t.state.vim,i=O.registerController.getRegister(":"),a=i.toString();o.visualMode&&fe(t);var s=new e.StringStream(r);i.setText(r);var l,c,u=n||{};u.input=r;try{this.parseInput_(t,s,u)}catch(e){throw Oe(t,e),e}if(u.commandName){if(l=this.matchCommand_(u.commandName)){if(c=l.name,l.excludeFromCommandHistory&&i.setText(a),this.parseCommandArgs_(s,u,l),"exToKey"==l.type){for(var h=0;h<l.toKeys.length;h++)e.Vim.handleKey(t,l.toKeys[h],"mapping");return}if("exToEx"==l.type)return void this.processCommand(t,l.toInput)}}else void 0!==u.line&&(c="move");if(c)try{We[c](t,u),l&&l.possiblyAsync||!u.callback||u.callback()}catch(e){throw Oe(t,e),e}else Oe(t,'Not an editor command ":'+r+'"')},parseInput_:function(e,t,r){t.eatWhile(":"),t.eat("%")?(r.line=e.firstLine(),r.lineEnd=e.lastLine()):(r.line=this.parseLineSpec_(e,t),void 0!==r.line&&t.eat(",")&&(r.lineEnd=this.parseLineSpec_(e,t)));var n=t.match(/^(\w+)/);return r.commandName=n?n[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"'":var n=t.next(),o=_e(e,e.state.vim,n);if(!o)throw new Error("Mark not set");return this.parseLineSpecOffset_(t,o.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+)/);if(r){var n=parseInt(r[2],10);"-"==r[1]?t-=n:t+=n}return t},parseCommandArgs_:function(e,t,r){if(!e.eol()){t.argString=e.match(/.*/)[0];var n=r.argDelimiter||/\s+/,o=se(t.argString).split(n);o.length&&o[0]&&(t.args=o)}},matchCommand_:function(e){for(var t=e.length;t>0;t--){var r=e.substring(0,t);if(this.commandMap_[r]){var n=this.commandMap_[r];if(0===n.name.indexOf(e))return n}}return null},buildCommandMap_:function(){this.commandMap_={};for(var e=0;e<r.length;e++){var t=r[e],n=t.shortName||t.name;this.commandMap_[n]=t}},map:function(e,r,n){if(":"!=e&&":"==e.charAt(0)){if(n)throw Error("Mode not supported for ex mappings");var o=e.substring(1);":"!=r&&":"==r.charAt(0)?this.commandMap_[o]={name:o,type:"exToEx",toInput:r.substring(1),user:!0}:this.commandMap_[o]={name:o,type:"exToKey",toKeys:r,user:!0}}else if(":"!=r&&":"==r.charAt(0)){var i={keys:e,type:"keyToEx",exArgs:{input:r.substring(1)}};n&&(i.context=n),t.unshift(i)}else i={keys:e,type:"keyToKey",toKeys:r},n&&(i.context=n),t.unshift(i)},unmap:function(e,r){if(":"!=e&&":"==e.charAt(0)){if(r)throw Error("Mode not supported for ex mappings");var n=e.substring(1);if(this.commandMap_[n]&&this.commandMap_[n].user)return void delete this.commandMap_[n]}else for(var o=e,i=0;i<t.length;i++)if(o==t[i].keys&&t[i].context===r)return void t.splice(i,1);throw Error("No such mapping.")}};var We={colorscheme:function(e,t){!t.args||t.args.length<1?Oe(e,e.getOption("theme")):e.setOption("theme",t.args[0])},map:function(e,t,r){var n=t.args;!n||n.length<2?e&&Oe(e,"Invalid mapping: "+t.input):Ve.map(n[0],n[1],r)},imap:function(e,t){this.map(e,t,"insert")},nmap:function(e,t){this.map(e,t,"normal")},vmap:function(e,t){this.map(e,t,"visual")},unmap:function(e,t,r){var n=t.args;!n||n.length<1?e&&Oe(e,"No such mapping: "+t.input):Ve.unmap(n[0],r)},move:function(e,t){U.processCommand(e,e.state.vim,{type:"motion",motion:"moveToLineOrEdgeOfDocument",motionArgs:{forward:!1,explicitRepeat:!0,linewise:!0},repeatOverride:t.line+1})},set:function(e,t){var r=t.args,n=t.setCfg||{};if(!r||r.length<1)e&&Oe(e,"Invalid mapping: "+t.input);else{var o=r[0].split("="),i=o[0],a=o[1],s=!1;if("?"==i.charAt(i.length-1)){if(a)throw Error("Trailing characters: "+t.argString);i=i.substring(0,i.length-1),s=!0}void 0===a&&"no"==i.substring(0,2)&&(i=i.substring(2),a=!1);var l=L[i]&&"boolean"==L[i].type;if(l&&null==a&&(a=!0),!l&&void 0===a||s){var c=E(i,e,n);c instanceof Error?Oe(e,c.message):Oe(e,!0===c||!1===c?" "+(c?"":"no")+i:" "+i+"="+c)}else{var u=R(i,a,e,n);u instanceof Error&&Oe(e,u.message)}}},setlocal:function(e,t){t.setCfg={scope:"local"},this.set(e,t)},setglobal:function(e,t){t.setCfg={scope:"global"},this.set(e,t)},registers:function(e,t){var r=t.args,n=O.registerController.registers,o="----------Registers----------<br><br>";if(r){r=r.join("");for(var i=0;i<r.length;i++)a=r.charAt(i),O.registerController.isValidRegister(a)&&(o+='"'+a+" "+(n[a]||new W).toString()+"<br>")}else for(var a in n){var s=n[a].toString();s.length&&(o+='"'+a+" "+s+"<br>")}Oe(e,o)},sort:function(t,r){var o,i,a,s,l,c=function(){if(r.argString){var t=new e.StringStream(r.argString);if(t.eat("!")&&(o=!0),t.eol())return;if(!t.eatSpace())return"Invalid arguments";var n=t.match(/([dinuox]+)?\s*(\/.+\/)?\s*/);if(!n&&!t.eol())return"Invalid arguments";if(n[1]){i=-1!=n[1].indexOf("i"),a=-1!=n[1].indexOf("u");var c=-1!=n[1].indexOf("d")||-1!=n[1].indexOf("n")&&1,u=-1!=n[1].indexOf("x")&&1,h=-1!=n[1].indexOf("o")&&1;if(c+u+h>1)return"Invalid arguments";s=(c?"decimal":u&&"hex")||h&&"octal"}n[2]&&(l=new RegExp(n[2].substr(1,n[2].length-2),i?"i":""))}}();if(c)Oe(t,c+": "+r.argString);else{var u=r.line||t.firstLine(),h=r.lineEnd||r.line||t.lastLine();if(u!=h){var p=n(u,0),f=n(h,ae(t,h)),d=t.getRange(p,f).split("\n"),m=l||("decimal"==s?/(-?)([\d]+)/:"hex"==s?/(-?)(?:0x)?([0-9a-f]+)/i:"octal"==s?/([0-7]+)/:null),g="decimal"==s?10:"hex"==s?16:"octal"==s?8:null,v=[],y=[];if(s||l)for(var k=0;k<d.length;k++){var C=l?d[k].match(l):null;C&&""!=C[0]?v.push(C):!l&&m.exec(d[k])?v.push(d[k]):y.push(d[k])}else y=d;if(v.sort(l?function(e,t){var r;return o&&(r=e,e=t,t=r),i&&(e[0]=e[0].toLowerCase(),t[0]=t[0].toLowerCase()),e[0]<t[0]?-1:1}:x),l)for(k=0;k<v.length;k++)v[k]=v[k].input;else s||y.sort(x);if(d=o?v.concat(y):y.concat(v),a){var w,M=d;for(d=[],k=0;k<M.length;k++)M[k]!=w&&d.push(M[k]),w=M[k]}t.replaceRange(d.join("\n"),p,f)}}function x(e,t){var r;o&&(r=e,e=t,t=r),i&&(e=e.toLowerCase(),t=t.toLowerCase());var n=s&&m.exec(e),a=s&&m.exec(t);return n?(n=parseInt((n[1]+n[2]).toLowerCase(),g))-(a=parseInt((a[1]+a[2]).toLowerCase(),g)):e<t?-1:1}},global:function(e,t){var r=t.argString;if(r){var n,o=void 0!==t.line?t.line:e.firstLine(),i=t.lineEnd||t.line||e.lastLine(),a=be(r,"/"),s=r;if(a.length&&(s=a[0],n=a.slice(1,a.length).join("/")),s)try{Ke(e,s,!0,!0)}catch(t){return void Oe(e,"Invalid regex: "+s)}for(var l=Ae(e).getQuery(),c=[],u="",h=o;h<=i;h++)l.test(e.getLine(h))&&(c.push(h+1),u+=e.getLine(h)+"<br>");if(n){var p=0,f=function(){if(p<c.length){var t=c[p]+n;Ve.processCommand(e,t,{callback:f})}p++};f()}else Oe(e,u)}else Oe(e,"Regular Expression missing from global")},substitute:function(t,r){if(!t.getSearchCursor)throw new Error("Search feature not available. Requires searchcursor.js or any other getSearchCursor implementation.");var o,i,a,s,l=r.argString,c=l?be(l,l[0]):[],u="",h=!1,f=!1;if(c.length)o=c[0],u=c[1],o&&"$"===o[o.length-1]&&(o=o.slice(0,o.length-1)+"\\n",u=u?u+"\n":"\n"),void 0!==u&&(u=E("pcre")?function(t){for(var r=new e.StringStream(t),n=[];!r.eol();){for(;r.peek()&&"\\"!=r.peek();)n.push(r.next());var o=!1;for(var i in Re)if(r.match(i,!0)){o=!0,n.push(Re[i]);break}o||n.push(r.next())}return n.join("")}(u):function(e){for(var t,r=!1,n=[],o=-1;o<e.length;o++){var i=e.charAt(o)||"",a=e.charAt(o+1)||"";Te[i+a]?(n.push(Te[i+a]),o++):r?(n.push(i),r=!1):"\\"===i?(r=!0,t=a,p.test(t)||"$"===a?n.push("$"):"/"!==a&&"\\"!==a&&n.push("\\")):("$"===i&&n.push("$"),n.push(i),"/"===a&&n.push("\\"))}return n.join("")}(u),O.lastSubstituteReplacePart=u),i=c[2]?c[2].split(" "):[];else if(l&&l.length)return void Oe(t,"Substitutions should be of the form :s/pattern/replace/");if(i&&(a=i[0],s=parseInt(i[1]),a&&(-1!=a.indexOf("c")&&(h=!0,a.replace("c","")),-1!=a.indexOf("g")&&(f=!0,a.replace("g","")),o=o.replace(/\//g,"\\/")+"/"+a)),o)try{Ke(t,o,!0,!0)}catch(e){return void Oe(t,"Invalid regex: "+o)}if(void 0!==(u=u||O.lastSubstituteReplacePart)){var d=Ae(t).getQuery(),m=void 0!==r.line?r.line:t.getCursor().line,g=r.lineEnd||m;m==t.firstLine()&&g==t.lastLine()&&(g=1/0),s&&(g=(m=g)+s-1);var v=z(t,n(m,0)),y=t.getSearchCursor(d,v);!function(t,r,n,o,i,a,s,l,c){t.state.vim.exMode=!0;var u=!1,h=a.from();function p(){t.operation(function(){for(;!u;)f(),d();m()})}function f(){var e=t.getRange(a.from(),a.to()),r=e.replace(s,l);a.replace(r)}function d(){for(;a.findNext()&&(e=a.from(),r=o,s=i,"number"!=typeof e&&(e=e.line),r instanceof Array?b(e,r):s?e>=r&&e<=s:e==r);)if(n||!h||a.from().line!=h.line)return t.scrollIntoView(a.from(),30),t.setSelection(a.from(),a.to()),h=a.from(),void(u=!1);var e,r,s;u=!0}function m(e){if(e&&e(),t.focus(),h){t.setCursor(h);var r=t.state.vim;r.exMode=!1,r.lastHPos=r.lastHSPos=h.ch}c&&c()}if(d(),!u)return r?void Ie(t,{prefix:"replace with <strong>"+l+"</strong> (y/n/a/q/l)",onKeyDown:function(r,n,o){switch(e.e_stop(r),e.keyName(r)){case"Y":f(),d();break;case"N":d();break;case"A":var i=c;c=void 0,t.operation(p),c=i;break;case"L":f();case"Q":case"Esc":case"Ctrl-C":case"Ctrl-[":m(o)}return u&&m(o),!0}}):(p(),void(c&&c()));Oe(t,"No matches for "+s.source)}(t,h,f,m,g,y,d,u,r.callback)}else Oe(t,"No previous substitute regular expression")},redo:e.commands.redo,undo:e.commands.undo,write:function(t){e.commands.save?e.commands.save(t):t.save&&t.save()},nohlsearch:function(e){je(e)},yank:function(e){var t=ee(e.getCursor()).line,r=e.getLine(t);O.registerController.pushText("0","yank",r,!0,!0)},delmarks:function(t,r){if(r.argString&&se(r.argString))for(var n=t.state.vim,o=new e.StringStream(se(r.argString));!o.eol();){o.eatSpace();var i=o.pos;if(!o.match(/[a-zA-Z]/,!1))return void Oe(t,"Invalid argument: "+r.argString.substring(i));var a=o.next();if(o.match("-",!0)){if(!o.match(/[a-zA-Z]/,!1))return void Oe(t,"Invalid argument: "+r.argString.substring(i));var s=a,l=o.next();if(!(M(s)&&M(l)||x(s)&&x(l)))return void Oe(t,"Invalid argument: "+s+"-");var c=s.charCodeAt(0),u=l.charCodeAt(0);if(c>=u)return void Oe(t,"Invalid argument: "+r.argString.substring(i));for(var h=0;h<=u-c;h++){var p=String.fromCharCode(c+h);delete n.marks[p]}}else delete n.marks[a]}else Oe(t,"Argument required")}},Ve=new Fe;function De(t){var r=t.state.vim,n=O.macroModeState,o=O.registerController.getRegister("."),i=n.isPlaying,a=n.lastInsertModeChanges,s=[];if(!i){for(var l=a.inVisualBlock&&r.lastSelection?r.lastSelection.visualBlock.height:1,c=a.changes,u=(s=[],0);u<c.length;)s.push(c[u]),c[u]instanceof ze?u++:u+=l;a.changes=s,t.off("change",$e),e.off(t.getInputField(),"keydown",Ze)}!i&&r.insertModeRepeat>1&&(Ge(t,r,r.insertModeRepeat-1,!0),r.lastEditInputState.repeatOverride=r.insertModeRepeat),delete r.insertModeRepeat,r.insertMode=!1,t.setCursor(t.getCursor().line,t.getCursor().ch-1),t.setOption("keyMap","vim"),t.setOption("disableInput",!0),t.toggleOverwrite(!1),o.setText(a.changes.join("")),e.signal(t,"vim-mode-change",{mode:"normal"}),n.isRecording&&function(e){if(!e.isPlaying){var t=e.latestRegister,r=O.registerController.getRegister(t);r&&r.pushInsertModeChanges&&r.pushInsertModeChanges(e.lastInsertModeChanges)}}(n)}function Ue(e){t.unshift(e)}function Je(t,r,n,o){var i=O.registerController.getRegister(o);if(":"==o)return i.keyBuffer[0]&&Ve.processCommand(t,i.keyBuffer[0]),void(n.isPlaying=!1);var a=i.keyBuffer,s=0;n.isPlaying=!0,n.replaySearchQueries=i.searchQueries.slice(0);for(var l=0;l<a.length;l++)for(var c,u,h=a[l];h;)if(u=(c=/<\w+-.+?>|<\w+>|./.exec(h))[0],h=h.substring(c.index+u.length),e.Vim.handleKey(t,u,"macro"),r.insertMode){var p=i.insertModeChanges[s++].changes;O.macroModeState.lastInsertModeChanges.changes=p,Xe(t,p,1),De(t)}n.isPlaying=!1}function $e(e,t){var r=O.macroModeState,n=r.lastInsertModeChanges;if(!r.isPlaying)for(;t;){if(n.expectCursorActivityForChange=!0,"+input"==t.origin||"paste"==t.origin||void 0===t.origin){var o=t.text.join("\n");n.maybeReset&&(n.changes=[],n.maybeReset=!1),e.state.overwrite&&!/\n/.test(o)?n.changes.push([o]):n.changes.push(o)}t=t.next}}function qe(t){var r=t.state.vim;if(r.insertMode){var n=O.macroModeState;if(n.isPlaying)return;var o=n.lastInsertModeChanges;o.expectCursorActivityForChange?o.expectCursorActivityForChange=!1:o.maybeReset=!0}else t.curOp.isVimOp||function(t,r){var n=t.getCursor("anchor"),o=t.getCursor("head");if(r.visualMode&&!t.somethingSelected()?fe(t,!1):r.visualMode||r.insertMode||!t.somethingSelected()||(r.visualMode=!0,r.visualLine=!1,e.signal(t,"vim-mode-change",{mode:"visual"})),r.visualMode){var i=re(o,n)?0:-1,a=re(o,n)?-1:0;o=G(o,0,i),n=G(n,0,a),r.sel={anchor:n,head:o},Me(t,r,"<",ne(o,n)),Me(t,r,">",oe(o,n))}else r.insertMode||(r.lastHPos=t.getCursor().ch)}(t,r);r.visualMode&&Qe(t)}function Qe(e){var t=e.state.vim,r=z(e,ee(t.sel.head)),n=G(r,0,1);t.fakeCursor&&t.fakeCursor.clear(),t.fakeCursor=e.markText(r,n,{className:"cm-animate-fat-cursor"})}function ze(e){this.keyName=e}function Ze(t){var r=O.macroModeState.lastInsertModeChanges,n=e.keyName(t);n&&(-1==n.indexOf("Delete")&&-1==n.indexOf("Backspace")||e.lookupKey(n,"vim-insert",function(){return r.maybeReset&&(r.changes=[],r.maybeReset=!1),r.changes.push(new ze(n)),!0}))}function Ge(e,t,r,n){var o=O.macroModeState;o.isPlaying=!0;var i=!!t.lastEditActionCommand,a=t.inputState;function s(){i?U.processAction(e,t,t.lastEditActionCommand):U.evalInput(e,t)}function l(r){if(o.lastInsertModeChanges.changes.length>0){r=t.lastEditActionCommand?r:1;var n=o.lastInsertModeChanges;Xe(e,n.changes,r)}}if(t.inputState=t.lastEditInputState,i&&t.lastEditActionCommand.interlaceInsertRepeat)for(var c=0;c<r;c++)s(),l(1);else n||s(),l(r);t.inputState=a,t.insertMode&&!n&&De(e),o.isPlaying=!1}function Xe(t,r,n){function o(r){return"string"==typeof r?e.commands[r](t):r(t),!0}var i,a,s=t.getCursor("head"),l=O.macroModeState.lastInsertModeChanges.inVisualBlock;if(l){var c=t.state.vim.lastSelection,u=(i=c.anchor,{line:(a=c.head).line-i.line,ch:a.line-i.line});ce(t,s,u.line+1),n=t.listSelections().length,t.setCursor(s)}for(var h=0;h<n;h++){l&&t.setCursor(G(s,h,0));for(var p=0;p<r.length;p++){var f=r[p];if(f instanceof ze)e.lookupKey(f.keyName,"vim-insert",o);else if("string"==typeof f){var d=t.getCursor();t.replaceRange(f,d,d)}else{var m=t.getCursor(),g=G(m,0,f[0].length);t.replaceRange(f[0],m,g)}}}l&&t.setCursor(G(s,0,1))}return e.keyMap.vim={attach:i,detach:o,call:l},T("insertModeEscKeysTimeout",200,"number"),e.keyMap["vim-insert"]={fallthrough:["default"],attach:i,detach:o,call:l},e.keyMap["vim-replace"]={Backspace:"goCharLeft",fallthrough:["vim-insert"],attach:i,detach:o,call:l},j(),H}()});
|