From fb5d3742796b60297411307a37ee6d0beed43cef Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Fri, 17 Dec 2021 12:34:00 -0500 Subject: [PATCH 1/6] feat: Add vim mode to script editor This adds an option to turn on vim mode using the `monaco-vim` library. --- dist/ext/monaco-vim.js | 7 +++ index.html | 3 +- src/ScriptEditor/ui/Options.ts | 1 + src/ScriptEditor/ui/OptionsModal.tsx | 14 ++++-- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 56 ++++++++++++++++++++++-- src/Settings/Settings.ts | 3 ++ src/index.html | 3 +- 7 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 dist/ext/monaco-vim.js diff --git a/dist/ext/monaco-vim.js b/dist/ext/monaco-vim.js new file mode 100644 index 000000000..57b330e7a --- /dev/null +++ b/dist/ext/monaco-vim.js @@ -0,0 +1,7 @@ +/*! + * monaco-vim + * Version - 0.1.19 + * Author - Brijesh Bittu (http://bitwiser.in/) + * License - MIT + */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("monaco-editor"),require("monaco-editor/esm/vs/editor/common/controller/cursorTypeOperations")):"function"==typeof define&&define.amd?define(["vs/editor/editor.main","vs/editor/common/controller/cursorTypeOperations"],t):"object"==typeof exports?exports.MonacoVim=t(require("monaco-editor"),require("monaco-editor/esm/vs/editor/common/controller/cursorTypeOperations")):e.MonacoVim=t(e.monaco,e[void 0])}(self,(function(e,t){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n(1);function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==s.return||s.return()}finally{if(o)throw i}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){for(var n=0;n=this.string.length},sol:function(){return this.pos==this.lineStart},peek:function(){return this.string.charAt(this.pos)||void 0},next:function(){if(this.post},eatSpace:function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},skipToEnd:function(){this.pos=this.string.length},skipTo:function(e){var t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0},backUp:function(e){this.pos-=e},column:function(){throw"not implemented"},indentation:function(){throw"not implemented"},match:function(e,t,n){if("string"!=typeof e){var r=this.string.slice(this.pos).match(e);return r&&r.index>0?null:(r&&!1!==t&&(this.pos+=r[0].length),r)}var o=function(e){return n?e.toLowerCase():e};if(o(this.string.substr(this.pos,e.length))==o(e))return!1!==t&&(this.pos+=e.length),!0},current:function(){return this.string.slice(this.start,this.pos)},hideFirstChars:function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}}};var C=function(){function e(t,n,r,o){s(this,e),this.cm=t,this.id=n,this.lineNumber=r+1,this.column=o+1,t.marks[this.id]=this}return c(e,[{key:"clear",value:function(){delete this.cm.marks[this.id]}},{key:"find",value:function(){return y(this)}}]),e}();function w(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!0,o=r.KeyCode[e.keyCode];e.key&&(o=e.key,n=!1);var i=o,a=t;switch(e.keyCode){case r.KeyCode.Shift:case r.KeyCode.Meta:case r.KeyCode.Alt:case r.KeyCode.Ctrl:return i;case r.KeyCode.Escape:a=!0,i="Esc"}return o.startsWith("KEY_")?i=o[o.length-1].toLowerCase():o.endsWith("Arrow")?(a=!0,i=o.substr(0,o.length-5)):o.startsWith("US_")&&(i=e.browserEvent.key),a||e.altKey||e.ctrlKey||e.metaKey?(e.altKey&&(i="Alt-".concat(i)),e.ctrlKey&&(i="Ctrl-".concat(i)),e.metaKey&&(i="Meta-".concat(i)),e.shiftKey&&(i="Shift-".concat(i))):i=e.key||e.browserEvent.key,1===i.length&&n&&(i="'".concat(i,"'")),i}var S=function(){function e(t){s(this,e),M.call(this),this.editor=t,this.state={},this.marks={},this.$uid=0,this.disposables=[],this.listeners={},this.curOp={},this.attached=!1,this.statusBar=null,this.addLocalListeners(),this.ctxInsert=this.editor.createContextKey("insertMode",!0)}return c(e,[{key:"attach",value:function(){e.keyMap.vim.attach(this)}},{key:"addLocalListeners",value:function(){this.disposables.push(this.editor.onDidChangeCursorPosition(this.handleCursorChange),this.editor.onDidChangeModelContent(this.handleChange),this.editor.onKeyDown(this.handleKeyDown))}},{key:"handleReplaceMode",value:function(e,t){var n=!1,o=e,i=this.editor.getPosition(),a=new r.Range(i.lineNumber,i.column,i.lineNumber,i.column+1);if(e.startsWith("'"))o=e[1];else if("Enter"===o)o="\n";else{if("Backspace"!==o)return;var s=this.replaceStack.pop();if(!s)return;n=!0,o=s,a=new r.Range(i.lineNumber,i.column,i.lineNumber,i.column-1)}t.preventDefault(),t.stopPropagation(),this.replaceStack||(this.replaceStack=[]),n||this.replaceStack.push(this.editor.getModel().getValueInRange(a)),this.editor.executeEdits("vim",[{text:o,range:a,forceMoveMarkers:!0}]),n&&this.editor.setPosition(a.getStartPosition())}},{key:"setOption",value:function(e,t){this.state[e]=t,"theme"===e&&r.editor.setTheme(t)}},{key:"getConfiguration",value:function(){var e=this.editor,t=h;return"function"==typeof e.getConfiguration?e.getConfiguration():("EditorOption"in r.editor&&(t=r.editor.EditorOption),{readOnly:e.getOption(t.readOnly),viewInfo:{cursorWidth:e.getOption(t.cursorWidth)},fontInfo:e.getOption(t.fontInfo)})}},{key:"getOption",value:function(e){return"readOnly"===e?this.getConfiguration().readOnly:"firstLineNumber"===e?this.firstLine()+1:"indentWithTabs"===e?!this.editor.getModel().getOptions().insertSpaces:"function"==typeof this.editor.getConfiguration?this.editor.getRawConfiguration()[e]:this.editor.getRawOptions()[e]}},{key:"dispatch",value:function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;rt&&(e=t-1),this.editor.getModel().getLineContent(e+1)}},{key:"getAnchorForSelection",value:function(e){return e.isEmpty()?e.getPosition():e.getDirection()===r.SelectionDirection.LTR?e.getStartPosition():e.getEndPosition()}},{key:"getHeadForSelection",value:function(e){return e.isEmpty()?e.getPosition():e.getDirection()===r.SelectionDirection.LTR?e.getEndPosition():e.getStartPosition()}},{key:"getCursor",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(!e)return y(this.editor.getPosition());var t=this.editor.getSelection();return y(t.isEmpty()?t.getPosition():"anchor"===e?this.getAnchorForSelection(t):this.getHeadForSelection(t))}},{key:"getRange",value:function(e,t){var n=k(e),o=k(t);return this.editor.getModel().getValueInRange(r.Range.fromPositions(n,o))}},{key:"getSelection",value:function(){var e=[],t=this.editor;this.state.vim;return t.getSelections().map((function(n){e.push(t.getModel().getValueInRange(n))})),e.join("\n")}},{key:"replaceRange",value:function(e,t,n){var o=k(t),i=n?k(n):o;this.editor.executeEdits("vim",[{text:e,range:r.Range.fromPositions(o,i)}]),this.pushUndoStop()}},{key:"pushUndoStop",value:function(){this.editor.pushUndoStop()}},{key:"setCursor",value:function(e,t){var n=e;"object"!==a(e)&&((n={}).line=e,n.ch=t);var r=this.editor.getModel().validatePosition(k(n));this.editor.setPosition(k(n)),this.editor.revealPosition(r)}},{key:"somethingSelected",value:function(){return!this.editor.getSelection().isEmpty()}},{key:"operation",value:function(e,t){return e()}},{key:"listSelections",value:function(){var e=this,t=this.editor.getSelections();return!t.length||this.inVirtualSelectionMode?[{anchor:this.getCursor("anchor"),head:this.getCursor("head")}]:t.map((function(t){t.getPosition(),t.getStartPosition(),t.getEndPosition();return{anchor:e.clipPos(y(e.getAnchorForSelection(t))),head:e.clipPos(y(e.getHeadForSelection(t)))}}))}},{key:"focus",value:function(){this.editor.focus()}},{key:"setSelections",value:function(e,t){var n=!!this.editor.getSelections().length,o=e.map((function(e,t){var o=e.anchor,i=e.head;return n?r.Selection.fromPositions(k(o),k(i)):r.Selection.fromPositions(k(i),k(o))}));if(t&&o[t]&&o.push(o.splice(t,1)[0]),o.length){var i,a=o[0];i=a.getDirection()===r.SelectionDirection.LTR?a.getEndPosition():a.getStartPosition(),this.editor.setSelections(o),this.editor.revealPosition(i)}}},{key:"setSelection",value:function(e,t){var n=r.Range.fromPositions(k(e),k(t));this.editor.setSelection(n)}},{key:"getSelections",value:function(){var e=this.editor;return e.getSelections().map((function(t){return e.getModel().getValueInRange(t)}))}},{key:"replaceSelections",value:function(e){var t=this.editor;t.getSelections().forEach((function(n,r){t.executeEdits("vim",[{range:n,text:e[r],forceMoveMarkers:!1}])}))}},{key:"toggleOverwrite",value:function(e){e?(this.enterVimMode(),this.replaceMode=!0):(this.leaveVimMode(),this.replaceMode=!1,this.replaceStack=[])}},{key:"charCoords",value:function(e,t){return{top:e.line,left:e.ch}}},{key:"coordsChar",value:function(e,t){}},{key:"clipPos",value:function(e){return y(this.editor.getModel().validatePosition(k(e)))}},{key:"setBookmark",value:function(e,t){var n=new C(this,this.$uid++,e.line,e.ch);return t&&t.insertLeft||(n.$insertRight=!0),this.marks[n.id]=n,n}},{key:"getScrollInfo",value:function(){var e=this.editor,t=i(e.getVisibleRanges(),1)[0];return{left:0,top:t.startLineNumber-1,height:e.getModel().getLineCount(),clientHeight:t.endLineNumber-t.startLineNumber+1}}},{key:"triggerEditorAction",value:function(e){this.editor.trigger("vim",e)}},{key:"dispose",value:function(){this.dispatch("dispose"),this.removeOverlay(),e.keyMap.vim&&e.keyMap.vim.detach(this),this.disposables.forEach((function(e){return e.dispose()}))}},{key:"getInputField",value:function(){}},{key:"getWrapperElement",value:function(){}},{key:"enterVimMode",value:function(){!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.ctxInsert.set(!1);var e=this.getConfiguration();this.initialCursorWidth=e.viewInfo.cursorWidth||0,this.editor.updateOptions({cursorWidth:e.fontInfo.typicalFullwidthCharacterWidth,cursorBlinking:"solid"})}},{key:"leaveVimMode",value:function(){this.ctxInsert.set(!0),this.editor.updateOptions({cursorWidth:this.initialCursorWidth||0,cursorBlinking:"blink"})}},{key:"virtualSelectionMode",value:function(){return this.inVirtualSelectionMode}},{key:"markText",value:function(){return{clear:function(){},find:function(){}}}},{key:"getUserVisibleLines",value:function(){var e=this.editor.getVisibleRanges();if(!e.length)return{top:0,bottom:0};var t={top:1/0,bottom:0};return e.reduce((function(e,t){return t.startLineNumbere.bottom&&(e.bottom=t.endLineNumber),e}),t),t.top-=1,t.bottom-=1,t}},{key:"findPosV",value:function(e,t,n){var r=this.editor,o=t,i=n,a=k(e);if("page"===n){var s=r.getLayoutInfo().height,l=this.getConfiguration().fontInfo.lineHeight;o*=Math.floor(s/l),i="line"}return"line"===i&&(a.lineNumber+=o),y(a)}},{key:"findMatchingBracket",value:function(e){var t=k(e),n=this.editor.getModel().matchBracket(t);return n&&2===n.length?{to:y(n[1].getStartPosition())}:{to:null}}},{key:"findFirstNonWhiteSpaceCharacter",value:function(e){return this.editor.getModel().getLineFirstNonWhitespaceColumn(e+1)-1}},{key:"scrollTo",value:function(e,t){(e||t)&&(e||(t<0&&(t=this.editor.getPosition().lineNumber-t),this.editor.setScrollTop(this.editor.getTopForLineNumber(t+1))))}},{key:"moveCurrentLineTo",value:function(e){var t=this.editor,n=t.getPosition(),o=r.Range.fromPositions(n,n);switch(e){case"top":return void t.revealRangeAtTop(o);case"center":return void t.revealRangeInCenter(o);case"bottom":return void t._revealRange(o,u)}}},{key:"getSearchCursor",value:function(e,t,n){var r=!1,o=!1;e instanceof RegExp&&!e.global&&(r=!e.ignoreCase,e=e.source,o=!0),null==t.ch&&(t.ch=Number.MAX_VALUE);var i=k(t),a=this,s=this.editor,l=null,c=s.getModel(),u=c.findMatches(e,!1,o,r)||[];return{getMatches:function(){return u},findNext:function(){return this.find(!1)},findPrevious:function(){return this.find(!0)},jumpTo:function(e){if(!u||!u.length)return!1;var t=u[e];return l=t.range,a.highlightRanges([l],"currentFindMatch"),a.highlightRanges(u.map((function(e){return e.range})).filter((function(e){return!e.equalsRange(l)}))),l},find:function(t){if(!u||!u.length)return!1;var n;if(t){var s=l?l.getStartPosition():i;if(!(n=c.findPreviousMatch(e,s,o,r))||!n.range.getStartPosition().isBeforeOrEqual(s))return!1}else{var h=l?c.getPositionAt(c.getOffsetAt(l.getStartPosition())+1):i;if(!(n=c.findNextMatch(e,h,o,r))||!h.isBeforeOrEqual(n.range.getStartPosition()))return!1}return l=n.range,a.highlightRanges([l],"currentFindMatch"),a.highlightRanges(u.map((function(e){return e.range})).filter((function(e){return!e.equalsRange(l)}))),l},from:function(){return l&&y(l.getStartPosition())},to:function(){return l&&y(l.getEndPosition())},replace:function(e){l&&(s.executeEdits("vim",[{range:l,text:e,forceMoveMarkers:!0}]),l.setEndPosition(s.getPosition()),s.setPosition(l.getStartPosition()))}}}},{key:"highlightRanges",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"findMatch",n="decoration".concat(t);return this[n]=this.editor.deltaDecorations(this[n]||[],e.map((function(e){return{range:e,options:{stickiness:r.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,zIndex:13,className:t,showIfCollapsed:!0}}}))),this[n]}},{key:"addOverlay",value:function(e,t,n){var r=e.query,o=!1,i=!1;r&&r instanceof RegExp&&!r.global&&(i=!0,o=!r.ignoreCase,r=r.source);var a=this.editor.getModel().findNextMatch(r,this.editor.getPosition(),i,o);a&&a.range&&this.highlightRanges([a.range])}},{key:"removeOverlay",value:function(){var e=this;["currentFindMatch","findMatch"].forEach((function(t){e.editor.deltaDecorations(e["decoration".concat(t)]||[],[])}))}},{key:"scrollIntoView",value:function(e){e&&this.editor.revealPosition(k(e))}},{key:"moveH",value:function(e,t){if("char"===t){var n=this.editor.getPosition();this.editor.setPosition(new r.Position(n.lineNumber,n.column+e))}}},{key:"scanForBracket",value:function(t,n,r,o){for(var i=o.bracketRegex,a=k(t),s=this.editor.getModel(),l=(-1===n?s.findPreviousMatch:s.findNextMatch).bind(s),c=[],u=0;;){if(u>10)return;var h=l(i.source,a,!0,!0,null,!0),f=h.matches[0];if(void 0===h)return;var p=e.matchingBrackets[f];if(p&&">"===p.charAt(1)==n>0)c.push(f);else{if(0===c.length)return{pos:y(h.range.getStartPosition())};c.pop()}a=s.getPositionAt(s.getOffsetAt(h.range.getStartPosition())+n),u+=1}}},{key:"indexFromPos",value:function(e){return this.editor.getModel().getOffsetAt(k(e))}},{key:"posFromIndex",value:function(e){return y(this.editor.getModel().getPositionAt(e))}},{key:"indentLine",value:function(e){var t,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=this.editor;t=i._getViewModel?i._getViewModel().cursorConfig:i._getCursors().context.config;var a=new r.Position(e+1,1),s=r.Selection.fromPositions(a,a);i.executeCommands("editor.action.".concat(n?"indent":"outdent","Lines"),o.TypeOperations[n?"indent":"outdent"](t,this.editor.getModel(),[s]))}},{key:"setStatusBar",value:function(e){this.statusBar=e}},{key:"openDialog",value:function(e,t,n){if(this.statusBar)return this.statusBar.setSec(e,t,n)}},{key:"openNotification",value:function(e){this.statusBar&&this.statusBar.showNotification(e)}}]),e}();S.Pos=m,S.signal=function(e,t,n){e.dispatch(t,n)},S.on=function(){},S.off=function(){},S.addClass=function(){},S.rmClass=function(){},S.defineOption=function(){},S.keyMap={default:function(e){return function(e){return!0}}},S.matchingBrackets={"(":")>",")":"(<","[":"]>","]":"[<","{":"}>","}":"{<","<":">>",">":"<<"},S.isWordChar=function(e){return/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||g.test(e))},S.keyName=w,S.StringStream=v,S.e_stop=function(e){return e.stopPropagation?e.stopPropagation():e.cancelBubble=!0,S.e_preventDefault(e),!1},S.e_preventDefault=function(e){return e.preventDefault?(e.preventDefault(),e.browserEvent&&e.browserEvent.preventDefault()):e.returnValue=!1,!1},S.commands={redo:function(e){e.editor.getModel().redo()},undo:function(e){e.editor.getModel().undo()},newlineAndIndent:function(e){e.triggerEditorAction("editor.action.insertLineAfter")}},S.lookupKey=function e(t,n,r){"string"==typeof n&&(n=S.keyMap[n]);var o="function"==typeof n?n(t):n[t];if(!1===o)return"nothing";if("..."===o)return"multi";if(null!=o&&r(o))return"handled";if(n.fallthrough){if(!Array.isArray(n.fallthrough))return e(t,n.fallthrough,r);for(var i=0;i",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:"keyToKey",toKeys:"j^",context:"visual"},{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:"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"}],L=A.length,E=[{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"}],T=x.Pos;x.Vim=function(){function e(e,n){e.attached=!1,this==x.keyMap.vim&&x.rmClass(e.getWrapperElement(),"cm-fat-cursor"),n&&n.attach==t||function(e){e.setOption("disableInput",!1),e.off("cursorActivity",$e),e.state.vim=null,e.leaveVimMode()}(e)}function t(e,n){this==x.keyMap.vim&&(e.attached=!0),n&&n.attach==t||function(e){e.setOption("disableInput",!0),e.setOption("showCursorWhenSelecting",!1),x.signal(e,"vim-mode-change",{mode:"normal"}),e.on("cursorActivity",$e),P(e),e.enterVimMode()}(e)}function n(e,t){if(t){if(this[e])return this[e];var n=function(e){if("'"==e.charAt(0))return e.charAt(1);if("AltGraph"==e)return!1;var t=e.split(/-(?!$)/),n=t[t.length-1];if(1==t.length&&1==t[0].length)return!1;if(2==t.length&&"Shift"==t[0]&&1==n.length)return!1;for(var i=!1,a=0;a"}(e);if(!n)return!1;var i=x.Vim.findKey(t,n);return"function"==typeof i&&x.signal(t,"vim-keypress",n),i}}x.defineOption("vimMode",!1,(function(e,t,n){t&&"vim"!=e.getOption("keyMap")?e.setOption("keyMap","vim"):!t&&n!=x.Init&&/^vim/.test(e.getOption("keyMap"))&&e.setOption("keyMap","default")}));var r={Shift:"S",Ctrl:"C",Alt:"A",Cmd:"D",Mod:"A"},o={Enter:"CR",Backspace:"BS",Delete:"Del",Insert:"Ins"};var i=/[\d]/,a=[x.isWordChar,function(e){return e&&!x.isWordChar(e)&&!/\s/.test(e)}],s=[function(e){return/\S/.test(e)}];function l(e,t){for(var n=[],r=e;r"]),p=[].concat(c,u,h,["-",'"',".",":","/"]);function d(e,t){return t>=e.firstLine()&&t<=e.lastLine()}function g(e){return/^[a-z]$/.test(e)}function m(e){return/^[A-Z]$/.test(e)}function v(e){return/^\s*$/.test(e)}function y(e){return-1!=".?!".indexOf(e)}function k(e,t){for(var n=0;nt?e=t:e0?1:-1,c=o.getCursor();do{if((a=r[(100+(e+=l))%100])&&(s=a.find())&&!Z(c,s))break}while(en)}return a}}),macroModeState:new B,lastCharacterSearch:{increment:0,forward:!0,selectedCharacter:""},registerController:new _({}),searchHistoryController:new j,exCommandHistoryController:new j},C){var i=C[o];i.value=i.defaultValue}}B.prototype={exitMacroRecordMode:function(){var e=R.macroModeState;e.onRecordingDone&&e.onRecordingDone(),e.onRecordingDone=void 0,e.isRecording=!1},enterMacroRecordMode:function(e,t){var n=R.registerController.getRegister(t);n&&(n.clear(),this.latestRegister=t,e.openDialog&&(this.onRecordingDone=e.openDialog("(recording)["+t+"]",null,{bottom:!0})),this.isRecording=!0)}};var K={buildKeyMap:function(){},getRegisterController:function(){return R.registerController},resetVimGlobalState_:N,getVimGlobalState_:function(){return R},maybeInitVimState_:P,suppressErrorLogging:!1,InsertModeKey:ze,map:function(e,t,n){Fe.map(e,t,n)},unmap:function(e,t){Fe.unmap(e,t)},noremap:function(e,t,n){function r(e){return e?[e]:["normal","insert","visual"]}for(var o=r(n),i=A.length,a=i-L;a"==t)return W(e),o.visualMode?fe(e):o.insertMode&&He(e),!0}return!1===(r=o.insertMode?function(){if(a())return!0;for(var n=o.inputState.keyBuffer=o.inputState.keyBuffer+t,r=1==t.length,i=F.matchCommand(n,A,o.inputState,"insert");n.length>1&&"full"!=i.type;){n=o.inputState.keyBuffer=n.slice(1);var s=F.matchCommand(n,A,o.inputState,"insert");"none"!=s.type&&(i=s)}if("none"==i.type)return W(e),!1;if("partial"==i.type)return O&&window.clearTimeout(O),O=window.setTimeout((function(){o.insertMode&&o.inputState.keyBuffer&&W(e)}),M("insertModeEscKeysTimeout")),!r;if(O&&window.clearTimeout(O),r){for(var l=e.listSelections(),c=0;c|<\w+>|./.exec(n),t=r[0],n=n.substring(r.index+t.length),x.Vim.handleKey(e,t,"mapping")}(r.toKeys):F.processCommand(e,o,r)}catch(t){throw e.state.vim=void 0,P(e),x.Vim.suppressErrorLogging||console.log(t),t}return!0}))}},handleEx:function(e,t){Fe.processCommand(e,t)},defineMotion:function(e,t){H[e]=t},defineAction:function(e,t){J[e]=t},defineOperator:function(e,t){q[e]=t},mapCommand:function(e,t,n,r,o){var i={keys:e,type:t};for(var a in i[t]=n,i[t+"Args"]=r,o)i[a]=o[a];Ue(i)},_mapCommand:Ue,defineRegister:function(e,t){var n=R.registerController.registers;if(!e||1!=e.length)throw Error("Register name must be 1 character");if(n[e])throw Error("Register already defined "+e);n[e]=t,p.push(e)},exitVisualMode:fe,exitInsertMode:He};function V(){this.prefixRepeat=[],this.motionRepeat=[],this.operator=null,this.operatorArgs=null,this.motion=null,this.motionArgs=null,this.keyBuffer=[],this.registerName=null}function W(e,t){e.state.vim.inputState=new V,x.signal(e,"vim-command-done",t)}function D(e,t,n){this.clear(),this.keyBuffer=[e||""],this.insertModeChanges=[],this.searchQueries=[],this.linewise=!!t,this.blockwise=!!n}function _(e){this.registers=e,this.unnamedRegister=e['"']=new D,e["."]=new D,e[":"]=new D,e["/"]=new D}function j(){this.historyBuffer=[],this.iterator=0,this.initialPrefix=null}V.prototype.pushRepeatDigit=function(e){this.operator?this.motionRepeat=this.motionRepeat.concat(e):this.prefixRepeat=this.prefixRepeat.concat(e)},V.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},D.prototype={setText:function(e,t,n){this.keyBuffer=[e||""],this.linewise=!!t,this.blockwise=!!n},pushText:function(e,t){t&&(this.linewise||this.keyBuffer.push("\n"),this.linewise=!0),this.keyBuffer.push(e)},pushInsertModeChanges:function(e){this.insertModeChanges.push(I(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("")}},_.prototype={pushText:function(e,t,n,r,o){r&&"\n"!==n.charAt(n.length-1)&&(n+="\n");var i=this.isValidRegister(e)?this.getRegister(e):null;if(i){m(e)?i.pushText(n,r):i.setText(n,r,o),this.unnamedRegister.setText(i.toString(),r)}else{switch(t){case"yank":this.registers[0]=new D(n,r,o);break;case"delete":case"change":-1==n.indexOf("\n")?this.registers["-"]=new D(n,r):(this.shiftNumericRegisters_(),this.registers[1]=new D(n,r))}this.unnamedRegister.setText(n,r,o)}},getRegister:function(e){return this.isValidRegister(e)?(e=e.toLowerCase(),this.registers[e]||(this.registers[e]=new D),this.registers[e]):this.unnamedRegister},isValidRegister:function(e){return e&&k(e,p)},shiftNumericRegisters_:function(){for(var e=9;e>=2;e--)this.registers[e]=this.getRegister(""+(e-1))}},j.prototype={nextMatch:function(e,t){var n=this.historyBuffer,r=t?-1:1;null===this.initialPrefix&&(this.initialPrefix=e);for(var o=this.iterator+r;t?o>=0:o=n.length?(this.iterator=n.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 F={matchCommand:function(e,t,n,r){var o,i=function(e,t,n,r){for(var o,i=[],a=[],s=0;s"==o.keys.slice(-11)){var l=function(e){var t=/^.*(<[^>]+>)$/.exec(e),n=t?t[1]:e.slice(-1);if(n.length>1)switch(n){case"":n="\n";break;case"":n=" ";break;default:n=""}return n}(e);if(!l)return{type:"none"};n.selectedCharacter=l}return{type:"full",command:o}},processCommand:function(e,t,n){switch(t.inputState.repeatOverride=n.repeatOverride,n.type){case"motion":this.processMotion(e,t,n);break;case"operator":this.processOperator(e,t,n);break;case"operatorMotion":this.processOperatorMotion(e,t,n);break;case"action":this.processAction(e,t,n);break;case"search":this.processSearch(e,t,n);break;case"ex":case"keyToEx":this.processEx(e,t,n)}},processMotion:function(e,t,n){t.inputState.motion=n.motion,t.inputState.motionArgs=Q(n.motionArgs),this.evalInput(e,t)},processOperator:function(e,t,n){var r=t.inputState;if(r.operator){if(r.operator==n.operator)return r.motion="expandToLine",r.motionArgs={linewise:!0},void this.evalInput(e,t);W(e)}r.operator=n.operator,r.operatorArgs=Q(n.operatorArgs),t.visualMode&&this.evalInput(e,t)},processOperatorMotion:function(e,t,n){var r=t.visualMode,o=Q(n.operatorMotionArgs);o&&r&&o.visualLine&&(t.visualLine=!0),this.processOperator(e,t,n),r||this.processMotion(e,t,n)},processAction:function(e,t,n){var r=t.inputState,o=r.getRepeat(),i=!!o,a=Q(n.actionArgs)||{};r.selectedCharacter&&(a.selectedCharacter=r.selectedCharacter),n.operator&&this.processOperator(e,t,n),n.motion&&this.processMotion(e,t,n),(n.motion||n.operator)&&this.evalInput(e,t),a.repeat=o||1,a.repeatIsExplicit=i,a.registerName=r.registerName,W(e),t.lastMotion=null,n.isEdit&&this.recordLastEdit(t,r,n),J[n.action](e,a,t)},processSearch:function(e,t,n){if(e.getSearchCursor){var r=n.searchArgs.forward,o=n.searchArgs.wholeWordOnly;xe(e).setReversed(!r);var i=r?"/":"?",a=xe(e).getQuery(),s=e.getScrollInfo();switch(n.searchArgs.querySrc){case"prompt":var l=R.macroModeState;if(l.isPlaying)f(h=l.replaySearchQueries.shift(),!0,!1);else Be(e,{onClose:function(t){e.scrollTo(s.left,s.top),f(t,!0,!0);var n=R.macroModeState;n.isRecording&&function(e,t){if(e.isPlaying)return;var n=e.latestRegister,r=R.registerController.getRegister(n);r&&r.pushSearchQuery&&r.pushSearchQuery(t)}(n,t)},prefix:i,desc:Ie,onKeyUp:function(t,n,o){var i,a,l,c=x.keyName(t);"Up"==c||"Down"==c?(i="Up"==c,a=t.target?t.target.selectionEnd:0,o(n=R.searchHistoryController.nextMatch(n,i)||""),a&&t.target&&(t.target.selectionEnd=t.target.selectionStart=Math.min(a,t.target.value.length))):"Left"!=c&&"Right"!=c&&"Ctrl"!=c&&"Alt"!=c&&"Shift"!=c&&R.searchHistoryController.reset();try{l=Pe(e,n,!0,!0)}catch(t){}l?e.scrollIntoView(Ke(e,!r,l),30):(Ve(e),e.scrollTo(s.left,s.top))},onKeyDown:function(t,n,r){var o=x.keyName(t);"Esc"==o||"Ctrl-C"==o||"Ctrl-["==o||"Backspace"==o&&""==n?(R.searchHistoryController.pushInput(n),R.searchHistoryController.reset(),Pe(e,a),Ve(e),e.scrollTo(s.left,s.top),x.e_stop(t),W(e),r(),e.focus()):"Up"==o||"Down"==o?x.e_stop(t):"Ctrl-U"==o&&(x.e_stop(t),r(""))}});break;case"wordUnderCursor":var c=pe(e,!1,!0,!1,!0),u=!0;if(c||(c=pe(e,!1,!0,!1,!1),u=!1),!c)return;var h=e.getLine(c.start.line).substring(c.start.ch,c.end.ch);h=u&&o?"\\b"+h+"\\b":h.replace(/([.?*+$\[\]\/\\(){}|\-])/g,"\\$1"),R.jumpList.cachedCursor=e.getCursor(),e.setCursor(c.start),f(h,!0,!1)}}function f(r,o,i){R.searchHistoryController.pushInput(r),R.searchHistoryController.reset();try{Pe(e,r,o,i)}catch(t){return Oe(e,"Invalid regex: "+r),void W(e)}F.processMotion(e,t,{type:"motion",motion:"findNext",motionArgs:{forward:!0,toJumplist:n.searchArgs.toJumplist}})}},processEx:function(e,t,n){function r(t){R.exCommandHistoryController.pushInput(t),R.exCommandHistoryController.reset(),Fe.processCommand(e,t)}function o(t,n,r){var o,i,a=x.keyName(t);("Esc"==a||"Ctrl-C"==a||"Ctrl-["==a||"Backspace"==a&&""==n)&&(R.exCommandHistoryController.pushInput(n),R.exCommandHistoryController.reset(),x.e_stop(t),W(e),r(),e.focus()),"Up"==a||"Down"==a?(x.e_stop(t),o="Up"==a,i=t.target?t.target.selectionEnd:0,r(n=R.exCommandHistoryController.nextMatch(n,o)||""),i&&t.target&&(t.target.selectionEnd=t.target.selectionStart=Math.min(i,t.target.value.length))):"Ctrl-U"==a?(x.e_stop(t),r("")):"Left"!=a&&"Right"!=a&&"Ctrl"!=a&&"Alt"!=a&&"Shift"!=a&&R.exCommandHistoryController.reset()}"keyToEx"==n.type?Fe.processCommand(e,n.exArgs.input):t.visualMode?Be(e,{onClose:r,prefix:":",value:"'<,'>",onKeyDown:o,selectValueOnOpen:!1}):Be(e,{onClose:r,prefix:":",onKeyDown:o})},evalInput:function(e,t){var n,r,o,i=t.inputState,a=i.motion,s=i.motionArgs||{},l=i.operator,c=i.operatorArgs||{},u=i.registerName,h=t.sel,f=Y(t.visualMode?$(e,h.head):e.getCursor("head")),p=Y(t.visualMode?$(e,h.anchor):e.getCursor("anchor")),d=Y(f),g=Y(p);if(l&&this.recordLastEdit(t,i),(o=void 0!==i.repeatOverride?i.repeatOverride:i.getRepeat())>0&&s.explicitRepeat?s.repeatIsExplicit=!0:(s.noRepeat||!s.explicitRepeat&&0===o)&&(o=1,s.repeatIsExplicit=!1),i.selectedCharacter&&(s.selectedCharacter=c.selectedCharacter=i.selectedCharacter),s.repeat=o,W(e),a){var m=H[a](e,f,s,t);if(t.lastMotion=H[a],!m)return;if(s.toJumplist){var y=R.jumpList,k=y.cachedCursor;k?(de(e,k,m),delete y.cachedCursor):de(e,f,m)}m instanceof Array?(r=m[0],n=m[1]):n=m,n||(n=Y(f)),t.visualMode?(t.visualBlock&&n.ch===1/0||(n=$(e,n,t.visualBlock)),r&&(r=$(e,r,!0)),r=r||g,h.anchor=r,h.head=n,ue(e),Ce(e,t,"<",ee(r,n)?r:n),Ce(e,t,">",ee(r,n)?n:r)):l||(n=$(e,n),e.setCursor(n.line,n.ch))}if(l){if(c.lastSel){r=g;var C=c.lastSel,w=Math.abs(C.head.line-C.anchor.line),S=Math.abs(C.head.ch-C.anchor.ch);n=C.visualLine?T(g.line+w,g.ch):C.visualBlock?T(g.line+w,g.ch+S):C.head.line==C.anchor.line?T(g.line,g.ch+S):T(g.line+w,g.ch),t.visualMode=!0,t.visualLine=C.visualLine,t.visualBlock=C.visualBlock,h=t.sel={anchor:r,head:n},ue(e)}else t.visualMode&&(c.lastSel={anchor:Y(h.anchor),head:Y(h.head),visualBlock:t.visualBlock,visualLine:t.visualLine});var M,x,b,A,L;if(t.visualMode){if(M=te(h.head,h.anchor),x=ne(h.head,h.anchor),b=t.visualLine||c.linewise,L=he(e,{anchor:M,head:x},A=t.visualBlock?"block":b?"line":"char"),b){var E=L.ranges;if("block"==A)for(var O=0;O0&&i&&v(i);i=o.pop())n.line--,n.ch=0;i?(n.line--,n.ch=oe(e,n.line)):n.ch=0}}(e,M,x),L=he(e,{anchor:M,head:x},A="char",!s.inclusive||b)}e.setSelections(L.ranges,L.primary),t.lastMotion=null,c.repeat=o,c.registerName=u,c.linewise=b;var B=q[l](e,c,L.ranges,g,n);t.visualMode&&fe(e,null!=B),B&&e.setCursor(B)}},recordLastEdit:function(e,t,n){var r=R.macroModeState;r.isPlaying||(e.lastEditInputState=t,e.lastEditActionCommand=n,r.lastInsertModeChanges.changes=[],r.lastInsertModeChanges.expectCursorActivityForChange=!1)}},H={moveToTopLine:function(e,t,n){var r=We(e).top+n.repeat-1;return T(r,e.findFirstNonWhiteSpaceCharacter(r))},moveToMiddleLine:function(e){var t=We(e),n=Math.floor(.5*(t.top+t.bottom));return T(n,e.findFirstNonWhiteSpaceCharacter(n))},moveToBottomLine:function(e,t,n){var r=We(e).bottom-n.repeat+1;return T(r,e.findFirstNonWhiteSpaceCharacter(r))},expandToLine:function(e,t,n){return T(t.line+n.repeat-1,1/0)},findNext:function(e,t,n){var r=xe(e),o=r.getQuery();if(o){var i=!n.forward;return i=r.isReversed()?!i:i,Ne(e,o),Ke(e,i,o,n.repeat)}},goToMark:function(e,t,n,r){var o=De(e,r,n.selectedCharacter);return o?n.linewise?{line:o.line,ch:e.findFirstNonWhiteSpaceCharacter(o.line)}:o:null},moveToOtherHighlightedEnd:function(e,t,n,r){if(r.visualBlock&&n.sameLine){var o=r.sel;return[$(e,T(o.anchor.line,o.head.ch)),$(e,T(o.head.line,o.anchor.ch))]}return[r.sel.head,r.sel.anchor]},jumpToMark:function(e,t,n,r){for(var o=t,i=0;ic&&o.line==c?this.moveToEol(e,t,n,r):(n.toFirstChar&&(i=e.findFirstNonWhiteSpaceCharacter(s),r.lastHPos=i),r.lastHSPos=e.charCoords(T(s,i),"div").left,T(s,i))},moveByDisplayLines:function(e,t,n,r){var o=t;switch(r.lastMotion){case this.moveByDisplayLines:case this.moveByScroll:case this.moveByLines:case this.moveToColumn:case this.moveToEol:break;default:r.lastHSPos=e.charCoords(o,"div").left}var i=n.repeat;if((s=e.findPosV(o,n.forward?i:-i,"line",r.lastHSPos)).hitSide)if(n.forward)var a={top:e.charCoords(s,"div").top+8,left:r.lastHSPos},s=e.coordsChar(a,"div");else{var l=e.charCoords(T(e.firstLine(),0),"div");l.left=r.lastHSPos,s=e.coordsChar(l,"div")}return r.lastHPos=s.ch,s},moveByPage:function(e,t,n){var r=t,o=n.repeat;return e.findPosV(r,n.forward?o:-o,"page")},moveByParagraph:function(e,t,n){var r=n.forward?1:-1;return Se(e,t,n.repeat,r)},moveBySentence:function(e,t,n){var r=n.forward?1:-1;return function(e,t,n,r){function o(e,t){if(t.pos+t.dir<0||t.pos+t.dir>=t.line.length){if(t.ln+=t.dir,!d(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 i(e,t,n,r){var i=""===(c=e.getLine(t)),a={line:c,ln:t,pos:n,dir:r},s={ln:a.ln,pos:a.pos},l=""===a.line;for(o(e,a);null!==a.line;){if(s.ln=a.ln,s.pos=a.pos,""===a.line&&!l)return{ln:a.ln,pos:a.pos};if(i&&""!==a.line&&!v(a.line[a.pos]))return{ln:a.ln,pos:a.pos};!y(a.line[a.pos])||i||a.pos!==a.line.length-1&&!v(a.line[a.pos+1])||(i=!0),o(e,a)}var c=e.getLine(s.ln);s.pos=0;for(var u=c.length-1;u>=0;--u)if(!v(c[u])){s.pos=u;break}return s}function a(e,t,n,r){var i={line:l=e.getLine(t),ln:t,pos:n,dir:r},a={ln:i.ln,pos:null},s=""===i.line;for(o(e,i);null!==i.line;){if(""===i.line&&!s)return null!==a.pos?a:{ln:i.ln,pos:i.pos};if(y(i.line[i.pos])&&null!==a.pos&&(i.ln!==a.ln||i.pos+1!==a.pos))return a;""===i.line||v(i.line[i.pos])||(s=!1,a={ln:i.ln,pos:i.pos}),o(e,i)}var l=e.getLine(a.ln);a.pos=0;for(var c=0;c0;)s=r<0?a(e,s.ln,s.pos,r):i(e,s.ln,s.pos,r),n--;return T(s.ln,s.pos)}(e,t,n.repeat,r)},moveByScroll:function(e,t,n,r){var o=e.getScrollInfo(),i=null,a=n.repeat;a||(a=Math.floor(o.clientHeight/(2*e.defaultTextHeight())));var s=e.charCoords(t,"local");if(n.repeat=a,!(i=H.moveByDisplayLines(e,t,n,r)))return null;var l=e.charCoords(i,"local");return e.scrollTo(null,o.top+l.top-s.top),i},moveByWords:function(e,t,n){return function(e,t,n,r,o,i){var a=Y(t),s=[];(r&&!o||!r&&o)&&n++;for(var l=!(r&&o),c=0;c0)u.index=0;else{var d=u.lineText.length;u.index=d>0?d-1:0}u.nextCh=u.lineText.charAt(u.index)}p(u)&&(o.line=l,o.ch=u.index,t--)}if(u.nextCh||u.curMoveThrough)return T(l,u.index);return o}(e,n.repeat,n.forward,n.selectedCharacter)||t},moveToColumn:function(e,t,n,r){var o=n.repeat;return r.lastHPos=o-1,r.lastHSPos=e.charCoords(t,"div").left,function(e,t){var n=e.getCursor().line;return $(e,T(n,t-1))}(e,o)},moveToEol:function(e,t,n,r){var o=t;r.lastHPos=1/0;var i=T(o.line+n.repeat-1,1/0),a=e.clipPos(i);return a.ch--,r.lastHSPos=e.charCoords(a,"div").left,i},moveToFirstNonWhiteSpaceCharacter:function(e,t){var n=t;return T(n.line,e.findFirstNonWhiteSpaceCharacter(n.line))},moveToMatchedSymbol:function(e,t){var n=t,r=n.line,o=n.ch;return oi.ch||o.line>i.line){var u=o;o=i,i=u}r?i.ch+=1:o.ch+=1;return{start:o,end:i}}(e,t,o,a);else if({"'":!0,'"':!0}[o])i=function(e,t,n,r){var o,i,a,s,l=Y(t),c=e.getLine(l.line).split(""),u=c.indexOf(n);l.ch-1&&!o;a--)c[a]==n&&(o=a+1);else o=l.ch+1;if(o&&!i)for(a=o,s=c.length;ae.lastLine()&&t.linewise&&!f?e.replaceRange("",h,l):e.replaceRange("",s,l),t.linewise&&(f||(e.setCursor(h),x.commands.newlineAndIndent(e)),s.ch=Number.MAX_VALUE),r=s}R.registerController.pushText(t.registerName,"change",o,t.linewise,n.length>1),J.enterInsertMode(e,{head:r},e.state.vim)},delete:function(e,t,n){var r,o;e.pushUndoStop();var i=e.state.vim;if(i.visualBlock){o=e.getSelection();var a=U("",n.length);e.replaceSelections(a),r=n[0].anchor}else{var s=n[0].anchor,l=n[0].head;t.linewise&&l.line!=e.firstLine()&&s.line==e.lastLine()&&s.line==l.line-1&&(s.line==e.firstLine()?s.ch=0:s=T(s.line-1,oe(e,s.line-1))),o=e.getRange(s,l),e.replaceRange("",s,l),r=s,t.linewise&&(r=H.moveToFirstNonWhiteSpaceCharacter(e,s))}return R.registerController.pushText(t.registerName,"delete",o,t.linewise,i.visualBlock),$(e,r,i.insertMode)},indent:function(e,t,n){var r=e.state.vim,o=n[0].anchor.line,i=r.visualBlock?n[n.length-1].anchor.line:n[0].head.line,a=r.visualMode?t.repeat:1;t.linewise&&i--,e.pushUndoStop();for(var s=o;s<=i;s++)for(var l=0;lc.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=o.anchor.line?z(o.head,0,1):T(o.anchor.line,0);else if("inplace"==r&&n.visualMode)return;e.setOption("disableInput",!1),n.visualMode&&fe(e),t&&t.replace?(e.toggleOverwrite(!0),e.setOption("keyMap","vim-replace"),x.signal(e,"vim-mode-change",{mode:"replace"})):(e.toggleOverwrite(!1),e.setOption("keyMap","vim-insert"),x.signal(e,"vim-mode-change",{mode:"insert"})),R.macroModeState.isPlaying||(e.on("change",Je),x.on(e.getInputField(),"keydown",Ge)),le(e,i,a)}},toggleVisualMode:function(e,t,n){var r,o=t.repeat,i=e.getCursor();n.visualMode?n.visualLine^t.linewise||n.visualBlock^t.blockwise?(n.visualLine=!!t.linewise,n.visualBlock=!!t.blockwise,x.signal(e,"vim-mode-change",{mode:"visual",subMode:n.visualLine?"linewise":n.visualBlock?"blockwise":""}),ue(e)):fe(e):(n.visualMode=!0,n.visualLine=!!t.linewise,n.visualBlock=!!t.blockwise,r=$(e,T(i.line,i.ch+o-1),!0),n.sel={anchor:i,head:r},x.signal(e,"vim-mode-change",{mode:"visual",subMode:n.visualLine?"linewise":n.visualBlock?"blockwise":""}),ue(e),Ce(e,n,"<",te(i,r)),Ce(e,n,">",ne(i,r)))},reselectLastSelection:function(e,t,n){var r=n.lastSelection;if(n.visualMode&&ce(e,n),r){var o=r.anchorMark.find(),i=r.headMark.find();if(!o||!i)return;n.sel={anchor:o,head:i},n.visualMode=!0,n.visualLine=r.visualLine,n.visualBlock=r.visualBlock,ue(e),Ce(e,n,"<",te(o,i)),Ce(e,n,">",ne(o,i)),x.signal(e,"vim-mode-change",{mode:"visual",subMode:n.visualLine?"linewise":n.visualBlock?"blockwise":""})}},joinLines:function(e,t,n){var r,o;if(n.visualMode){if(r=e.getCursor("anchor"),ee(o=e.getCursor("head"),r)){var i=o;o=r,r=i}o.ch=oe(e,o.line)-1}else{var a=Math.max(t.repeat,2);r=e.getCursor(),o=$(e,T(r.line+a-1,1/0))}for(var s=0,l=r.line;l1)f=Array(t.repeat+1).join(f);var p,d,g=o.linewise,m=o.blockwise;if(g)n.visualMode?f=n.visualLine?f.slice(0,-1):"\n"+f.slice(0,f.length-1)+"\n":t.after?(f="\n"+f.slice(0,f.length-1),r.ch=oe(e,r.line)):r.ch=0;else{if(m){f=f.split("\n");for(var v=0;ve.lastLine()&&e.replaceRange("\n",T(b,0)),oe(e,b)l.length&&(r=l.length),o=T(a.line,r)}if("\n"==i)n.visualMode||e.replaceRange("",a,o),(x.commands.newlineAndIndentContinueComment||x.commands.newlineAndIndent)(e);else{var c=e.getRange(a,o);if(c=c.replace(/[^\n]/g,i),n.visualBlock){var u=new Array(e.getOption("tabSize")+1).join(" ");c=(c=e.getSelection()).replace(/\t/g,u).replace(/[^\n]/g,i).split("\n"),e.replaceSelections(c)}else e.replaceRange(c,a,o);n.visualMode?(a=ee(s[0].anchor,s[0].head)?s[0].anchor:s[0].head,e.setCursor(a),fe(e,!1)):e.setCursor(z(o,0,-1))}},incrementNumberToken:function(e,t){for(var n,r,o,i,a=e.getCursor(),s=e.getLine(a.line),l=/(-?)(?:(0x)([\da-f]+)|(0b|0|)(\d+))/gi;null!==(n=l.exec(s))&&(o=(r=n.index)+n[0].length,!(a.ch"==t.slice(-11)){var n=t.length-11,r=e.slice(0,n),o=t.slice(0,n);return r==o&&e.length>n?"full":0==o.indexOf(r)&&"partial"}return e==t?"full":0==t.indexOf(e)&&"partial"}function X(e,t,n){return function(){for(var r=0;r2&&(t=te.apply(void 0,Array.prototype.slice.call(arguments,1))),ee(e,t)?e:t}function ne(e,t){return arguments.length>2&&(t=ne.apply(void 0,Array.prototype.slice.call(arguments,1))),ee(e,t)?t:e}function re(e,t,n){var r=ee(e,t),o=ee(t,n);return r&&o}function oe(e,t){return e.getLine(t).length}function ie(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function ae(e,t,n){var r=oe(e,t),o=new Array(n-r+1).join(" ");e.setCursor(T(t,r)),e.replaceRange(o,e.getCursor())}function se(e,t){var n=[],r=e.listSelections(),o=Y(e.clipPos(t)),i=!Z(t,o),a=function(e,t,n){for(var r=0;ra?l:0,u=r[c].anchor,h=Math.min(u.line,o.line),f=Math.max(u.line,o.line),p=u.ch,d=o.ch,g=r[c].head.ch-p,m=d-p;g>0&&m<=0?(p++,i||d--):g<0&&m>=0?(p--,s||d++):g<0&&-1==m&&(p--,d++);for(var v=h;v<=f;v++){var y={anchor:new T(v,p),head:new T(v,d)};n.push(y)}return e.setSelections(n),t.ch=d,u.ch=p,u}function le(e,t,n){for(var r=[],o=0;ol&&(o.line=l),o.ch=oe(e,o.line)}return{ranges:[{anchor:i,head:o}],primary:0}}if("block"==n){for(var c=Math.min(i.line,o.line),u=Math.min(i.ch,o.ch),h=Math.max(i.line,o.line),f=Math.max(i.ch,o.ch)+1,p=h-c+1,d=o.line==c?0:p-1,g=[],m=0;m=l.length)return null;r?u=s[0]:(u=a[0])(l.charAt(c))||(u=a[1]);for(var h=c,f=c;u(l.charAt(h))&&h=0;)f--;if(f++,t){for(var p=h;/\s/.test(l.charAt(h))&&h0;)f--;f||(f=d)}}return{start:T(i.line,f),end:T(i.line,h)}}function de(e,t,n){Z(t,n)||R.jumpList.add(e,t,n)}function ge(e,t){R.lastCharacterSearch.increment=e,R.lastCharacterSearch.forward=t.forward,R.lastCharacterSearch.selectedCharacter=t.selectedCharacter}var me={"(":"bracket",")":"bracket","{":"bracket","}":"bracket","[":"section","]":"section","*":"comment","/":"comment",m:"method",M:"method","#":"preprocess"},ve={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 ye(e,t,n,r,o){var i=t.line,l=t.ch,c=e.getLine(i),u=n?1:-1,h=r?s:a;if(o&&""==c){if(i+=u,c=e.getLine(i),!d(e,i))return null;l=n?0:c.length}for(;;){if(o&&""==c)return{from:0,to:0,line:i};for(var f=u>0?c.length:-1,p=f,g=f;l!=f;){for(var m=!1,v=0;v0?0:c.length}}function ke(e,t,n,r){for(var o,i=e.getCursor(),a=i.ch,s=0;s0;)h(c,r)&&n--,c+=r;return new T(c,0)}var f=e.state.vim;if(f.visualLine&&h(a,1,!0)){var p=f.sel.anchor;h(p.line,-1,!0)&&(o&&p.line==a||(a+=1))}var d=u(a);for(c=a;c<=l&&n;c++)h(c,1,!0)&&(o&&u(c)==d||n--);for(i=new T(c,0),c>l&&!d?d=!0:o=!1,c=a;c>s&&(o&&u(c)!=d&&c!=a||!h(c,-1,!0));c--);return{start:new T(c,0),end:i}}function Me(){}function xe(e){var t=e.state.vim;return t.searchState_||(t.searchState_=new Me)}function be(e,t,n,r,o){e.openDialog?e.openDialog(t,r,{bottom:!0,value:o.value,onKeyDown:o.onKeyDown,onKeyUp:o.onKeyUp,selectValueOnOpen:!1}):r(prompt(n,""))}function Ae(e,t){var n=Le(e,t)||[];if(!n.length)return[];var r=[];if(0===n[0]){for(var o=0;o'+t+"",{bottom:!0,duration:5e3}):alert(t)}var Ie="(Javascript regexp)";function Be(e,t){var n,r,o,i=(t.prefix||"")+" "+(t.desc||"");be(e,(n=t.prefix,r=t.desc,o=''+(n||"")+'',r&&(o+=' '+r+""),o),i,t.onClose,t)}function Pe(e,t,n,r){if(t){var o=xe(e),i=Re(t,!!n,!!r);if(i)return Ne(e,i),function(e,t){if(e instanceof RegExp&&t instanceof RegExp){for(var n=["global","multiline","ignoreCase","source"],r=0;r0;t--){var n=e.substring(0,t);if(this.commandMap_[n]){var r=this.commandMap_[n];if(0===r.name.indexOf(e))return r}}return null},buildCommandMap_:function(){this.commandMap_={};for(var e=0;e
";if(n){n=n.join("");for(var i=0;i"}}else for(var a in r){var s=r[a].toString();s.length&&(o+='"'+a+" "+s+"
")}Oe(e,o)},sort:function(e,t){var n,r,o,i,a;var s=function(){if(t.argString){var e=new x.StringStream(t.argString);if(e.eat("!")&&(n=!0),e.eol())return;if(!e.eatSpace())return"Invalid arguments";var s=e.match(/([dinuox]+)?\s*(\/.+\/)?\s*/);if(!s&&!e.eol())return"Invalid arguments";if(s[1]){r=-1!=s[1].indexOf("i"),o=-1!=s[1].indexOf("u");var l=-1!=s[1].indexOf("d")||-1!=s[1].indexOf("n")&&1,c=-1!=s[1].indexOf("x")&&1,u=-1!=s[1].indexOf("o")&&1;if(l+c+u>1)return"Invalid arguments";i=(l?"decimal":c&&"hex")||u&&"octal"}s[2]&&(a=new RegExp(s[2].substr(1,s[2].length-2),r?"i":""))}}();if(s)Oe(e,s+": "+t.argString);else{var l=t.line||e.firstLine(),c=t.lineEnd||t.line||e.lastLine();if(l!=c){var u=T(l,0),h=T(c,oe(e,c)),f=e.getRange(u,h).split("\n"),p=a||("decimal"==i?/(-?)([\d]+)/:"hex"==i?/(-?)(?:0x)?([0-9a-f]+)/i:"octal"==i?/([0-7]+)/:null),d="decimal"==i?10:"hex"==i?16:"octal"==i?8:null,g=[],m=[];if(i||a)for(var v=0;v")}if(r){var f=0;!function t(){if(f=s&&a<=l:a==s);)if(n||!u||i.from().line!=u.line)return e.scrollIntoView(i.from(),30),t&&e.setSelection(i.from(),i.to()),u=i.from(),void(c=!1);var a,s,l;c=!0}function d(t){if(t&&t(),e.focus(),u){e.setCursor(u);var n=e.state.vim;n.exMode=!1,n.lastHPos=n.lastHSPos=u.ch}l&&l()}if(p(!0),c)return void Oe(e,"No matches for "+a.source);if(!t)return h(),void(l&&l());Be(e,{prefix:"replace with "+s+" (y/n/a/q/l)",onKeyDown:function(t,n,r){switch(x.e_stop(t),x.keyName(t)){case"y":case"Y":f(),p();break;case"n":case"N":p();break;case"a":case"A":var o=l;l=void 0,e.operation(h),l=o;break;case"l":case"L":f();case"q":case"Q":case"Esc":case"Ctrl-C":case"Ctrl-[":d(r)}return c&&d(r),!0}})}(e,u,h,p,d,m,f,c,t.callback)}else Oe(e,"No previous substitute regular expression")},redo:x.commands.redo,undo:x.commands.undo,write:function(e){x.commands.save?x.commands.save(e):e.save&&e.save()},nohlsearch:function(e){Ve(e)},yank:function(e){var t=Y(e.getCursor()).line,n=e.getLine(t);R.registerController.pushText("0","yank",n,!0,!0)},delmarks:function(e,t){if(t.argString&&ie(t.argString))for(var n=e.state.vim,r=new x.StringStream(ie(t.argString));!r.eol();){r.eatSpace();var o=r.pos;if(!r.match(/[a-zA-Z]/,!1))return void Oe(e,"Invalid argument: "+t.argString.substring(o));var i=r.next();if(r.match("-",!0)){if(!r.match(/[a-zA-Z]/,!1))return void Oe(e,"Invalid argument: "+t.argString.substring(o));var a=i,s=r.next();if(!(g(a)&&g(s)||m(a)&&m(s)))return void Oe(e,"Invalid argument: "+a+"-");var l=a.charCodeAt(0),c=s.charCodeAt(0);if(l>=c)return void Oe(e,"Invalid argument: "+t.argString.substring(o));for(var u=0;u<=c-l;u++){var h=String.fromCharCode(l+u);delete n.marks[h]}}else delete n.marks[i]}else Oe(e,"Argument required")}},Fe=new _e;function He(e){var t=e.state.vim,n=R.macroModeState,r=R.registerController.getRegister("."),o=n.isPlaying,i=n.lastInsertModeChanges,a=[];if(!o){for(var s=i.inVisualBlock&&t.lastSelection?t.lastSelection.visualBlock.height:1,l=i.changes,c=(a=[],0);c1&&(Xe(e,t,t.insertModeRepeat-1,!0),t.lastEditInputState.repeatOverride=t.insertModeRepeat),delete t.insertModeRepeat,t.insertMode=!1,e.setCursor(e.getCursor().line,e.getCursor().ch-1),e.setOption("keyMap","vim"),e.setOption("disableInput",!0),e.toggleOverwrite(!1),r.setText(i.changes.join("")),x.signal(e,"vim-mode-change",{mode:"normal"}),n.isRecording&&function(e){if(e.isPlaying)return;var t=e.latestRegister,n=R.registerController.getRegister(t);n&&n.pushInsertModeChanges&&n.pushInsertModeChanges(e.lastInsertModeChanges)}(n),e.enterVimMode()}function Ue(e){A.unshift(e)}function qe(e,t,n,r){var o=R.registerController.getRegister(r);if(":"==r)return o.keyBuffer[0]&&Fe.processCommand(e,o.keyBuffer[0]),void(n.isPlaying=!1);var i=o.keyBuffer,a=0;n.isPlaying=!0,n.replaySearchQueries=o.searchQueries.slice(0);for(var s=0;s|<\w+>|./.exec(u))[0],u=u.substring(l.index+c.length),x.Vim.handleKey(e,c,"macro"),t.insertMode){var h=o.insertModeChanges[a++].changes;R.macroModeState.lastInsertModeChanges.changes=h,Ye(e,h,1),He(e)}n.isPlaying=!1}function Je(e,t){var n=R.macroModeState,r=n.lastInsertModeChanges;if(!n.isPlaying)for(;t;){if(r.expectCursorActivityForChange=!0,"+input"==t.origin||"paste"==t.origin||void 0===t.origin){var o=t.text.join("\n");r.maybeReset&&(r.changes=[],r.maybeReset=!1),e.state.overwrite&&!/\n/.test(o)?r.changes.push([o]):r.changes.push(o)}t=t.next}}function $e(e){var t=e.state.vim;if(t.insertMode){var n=R.macroModeState;if(n.isPlaying)return;var r=n.lastInsertModeChanges;r.expectCursorActivityForChange?r.expectCursorActivityForChange=!1:r.maybeReset=!0}else e.curOp.isVimOp||function(e,t){var n=e.getCursor("anchor"),r=e.getCursor("head");t.visualMode&&!e.somethingSelected()?fe(e,!1):t.visualMode||t.insertMode||!e.somethingSelected()||(t.visualMode=!0,t.visualLine=!1,x.signal(e,"vim-mode-change",{mode:"visual"}));if(t.visualMode){var o=ee(r,n)?0:-1,i=ee(r,n)?-1:0;r=z(r,0,o),n=z(n,0,i),t.sel={anchor:n,head:r},Ce(e,t,"<",te(r,n)),Ce(e,t,">",ne(r,n))}else t.insertMode||(t.lastHPos=e.getCursor().ch)}(e,t);t.visualMode&&Qe(e)}function Qe(e){var t=e.state.vim,n=$(e,Y(t.sel.head)),r=z(n,0,1);t.fakeCursor&&t.fakeCursor.clear(),t.fakeCursor=e.markText(n,r,{className:"cm-animate-fat-cursor"})}function ze(e){this.keyName=e}function Ge(e){var t=R.macroModeState.lastInsertModeChanges,n=x.keyName(e);n&&(-1==n.indexOf("Delete")&&-1==n.indexOf("Backspace")||x.lookupKey(n,"vim-insert",(function(){return t.maybeReset&&(t.changes=[],t.maybeReset=!1),t.changes.push(new ze(n)),!0})))}function Xe(e,t,n,r){var o=R.macroModeState;o.isPlaying=!0;var i=!!t.lastEditActionCommand,a=t.inputState;function s(){i?F.processAction(e,t,t.lastEditActionCommand):F.evalInput(e,t)}function l(n){if(o.lastInsertModeChanges.changes.length>0){n=t.lastEditActionCommand?n:1;var r=o.lastInsertModeChanges;Ye(e,r.changes,n)}}if(t.inputState=t.lastEditInputState,i&&t.lastEditActionCommand.interlaceInsertRepeat)for(var c=0;c2&&void 0!==arguments[2]?arguments[2]:null;O(this,e),this.closeInput=function(){r.removeInputListeners(),r.input=null,r.setSec(""),r.editor&&r.editor.focus()},this.clear=function(){r.setInnerHtml_(r.node,"")},this.inputKeyUp=function(e){var t=r.input.options;t&&t.onKeyUp&&t.onKeyUp(e,e.target.value,r.closeInput)},this.inputBlur=function(){r.input.options.closeOnBlur&&r.closeInput()},this.inputKeyDown=function(e){var t=r.input,n=t.options,o=t.callback;n&&n.onKeyDown&&n.onKeyDown(e,e.target.value,r.closeInput)||((27===e.keyCode||n&&!1!==n.closeOnEnter&&13==e.keyCode)&&(r.input.node.blur(),e.stopPropagation(),r.closeInput()),13===e.keyCode&&o&&(e.stopPropagation(),e.preventDefault(),o(e.target.value)))},this.node=t,this.modeInfoNode=document.createElement("span"),this.secInfoNode=document.createElement("span"),this.notifNode=document.createElement("span"),this.notifNode.className="vim-notification",this.keyInfoNode=document.createElement("span"),this.keyInfoNode.setAttribute("style","float: right"),this.node.appendChild(this.modeInfoNode),this.node.appendChild(this.secInfoNode),this.node.appendChild(this.notifNode),this.node.appendChild(this.keyInfoNode),this.toggleVisibility(!1),this.editor=n,this.sanitizer=o}var t,n,r;return t=e,(n=[{key:"setMode",value:function(e){"visual"!==e.mode||"linewise"!==e.subMode?this.setText("--".concat(e.mode.toUpperCase(),"--")):this.setText("--VISUAL LINE--")}},{key:"setKeyBuffer",value:function(e){this.keyInfoNode.textContent=e}},{key:"setSec",value:function(e,t,n){if(this.notifNode.textContent="",void 0!==e){this.setInnerHtml_(this.secInfoNode,e);var r=this.secInfoNode.querySelector("input");return r&&(r.focus(),this.input={callback:t,options:n,node:r},n&&(n.selectValueOnOpen&&r.select(),n.value&&(r.value=n.value)),this.addInputListeners()),this.closeInput}}},{key:"setText",value:function(e){this.modeInfoNode.textContent=e}},{key:"toggleVisibility",value:function(e){this.node.style.display=e?"block":"none",this.input&&this.removeInputListeners(),clearInterval(this.notifTimeout)}},{key:"addInputListeners",value:function(){var e=this.input.node;e.addEventListener("keyup",this.inputKeyUp),e.addEventListener("keydown",this.inputKeyDown),e.addEventListener("input",this.inputKeyInput),e.addEventListener("blur",this.inputBlur)}},{key:"removeInputListeners",value:function(){if(this.input&&this.input.node){var e=this.input.node;e.removeEventListener("keyup",this.inputKeyUp),e.removeEventListener("keydown",this.inputKeyDown),e.removeEventListener("input",this.inputKeyInput),e.removeEventListener("blur",this.inputBlur)}}},{key:"showNotification",value:function(e){var t=this,n=document.createElement("span");this.setInnerHtml_(n,e),this.notifNode.textContent=n.textContent,this.notifTimeout=setTimeout((function(){t.notifNode.textContent=""}),5e3)}},{key:"setInnerHtml_",value:function(e,t){if(this.sanitizer){for(;e.children.length;)e.removeChild(e.children[0]);e.appendChild(this.sanitizer(t))}else e.innerHTML=t}}])&&I(t.prototype,n),r&&I(t,r),e}();function P(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:B,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,o=new R(e);if(!t)return o.attach(),o;var i=new n(t,e,r),a="";return o.on("vim-mode-change",(function(e){i.setMode(e)})),o.on("vim-keypress",(function(e){":"===e?a="":a+=e,i.setKeyBuffer(a)})),o.on("vim-command-done",(function(){a="",i.setKeyBuffer(a)})),o.on("dispose",(function(){i.toggleVisibility(!1),i.closeInput(),i.clear()})),i.toggleVisibility(!0),o.setStatusBar(i),o.attach(),o}n.d(t,"initVimMode",(function(){return P})),n.d(t,"VimMode",(function(){return R})),n.d(t,"StatusBar",(function(){return B}))}])})); \ No newline at end of file diff --git a/index.html b/index.html index 1abbdab31..bfc25ad06 100644 --- a/index.html +++ b/index.html @@ -17,12 +17,13 @@ + +