| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758 |
- ace.define("ace/keyboard/vim/registers",["require","exports","module"], function(require, exports, module) {
- "never use strict";
- module.exports = {
- _default: {
- text: "",
- isLine: false
- }
- };
- });
- ace.define("ace/keyboard/vim/maps/util",["require","exports","module","ace/keyboard/vim/registers","ace/lib/dom"], function(require, exports, module) {
- var registers = require("../registers");
- var dom = require("../../../lib/dom");
- dom.importCssString('.insert-mode .ace_cursor{\
- border-left: 2px solid #333333;\
- }\
- .ace_dark.insert-mode .ace_cursor{\
- border-left: 2px solid #eeeeee;\
- }\
- .normal-mode .ace_cursor{\
- border: 0!important;\
- background-color: red;\
- opacity: 0.5;\
- }', 'vimMode');
- module.exports = {
- onVisualMode: false,
- onVisualLineMode: false,
- currentMode: 'normal',
- noMode: function(editor) {
- editor.unsetStyle('insert-mode');
- editor.unsetStyle('normal-mode');
- if (editor.commands.recording)
- editor.commands.toggleRecording(editor);
- editor.setOverwrite(false);
- },
- insertMode: function(editor) {
- this.currentMode = 'insert';
- editor.setStyle('insert-mode');
- editor.unsetStyle('normal-mode');
- editor.setOverwrite(false);
- editor.keyBinding.$data.buffer = "";
- editor.keyBinding.$data.vimState = "insertMode";
- this.onVisualMode = false;
- this.onVisualLineMode = false;
- if(this.onInsertReplaySequence) {
- editor.commands.macro = this.onInsertReplaySequence;
- editor.commands.replay(editor);
- this.onInsertReplaySequence = null;
- this.normalMode(editor);
- } else {
- editor._emit("changeStatus");
- if(!editor.commands.recording)
- editor.commands.toggleRecording(editor);
- }
- },
- normalMode: function(editor) {
- this.currentMode = 'normal';
- editor.unsetStyle('insert-mode');
- editor.setStyle('normal-mode');
- editor.clearSelection();
- var pos;
- if (!editor.getOverwrite()) {
- pos = editor.getCursorPosition();
- if (pos.column > 0)
- editor.navigateLeft();
- }
- editor.setOverwrite(true);
- editor.keyBinding.$data.buffer = "";
- editor.keyBinding.$data.vimState = "start";
- this.onVisualMode = false;
- this.onVisualLineMode = false;
- editor._emit("changeStatus");
- if (editor.commands.recording) {
- editor.commands.toggleRecording(editor);
- return editor.commands.macro;
- }
- else {
- return [];
- }
- },
- visualMode: function(editor, lineMode) {
- if (
- (this.onVisualLineMode && lineMode)
- || (this.onVisualMode && !lineMode)
- ) {
- this.normalMode(editor);
- return;
- }
- editor.setStyle('insert-mode');
- editor.unsetStyle('normal-mode');
- editor._emit("changeStatus");
- if (lineMode) {
- this.onVisualLineMode = true;
- } else {
- this.onVisualMode = true;
- this.onVisualLineMode = false;
- }
- },
- getRightNthChar: function(editor, cursor, ch, n) {
- var line = editor.getSession().getLine(cursor.row);
- var matches = line.substr(cursor.column + 1).split(ch);
- return n < matches.length ? matches.slice(0, n).join(ch).length : null;
- },
- getLeftNthChar: function(editor, cursor, ch, n) {
- var line = editor.getSession().getLine(cursor.row);
- var matches = line.substr(0, cursor.column).split(ch);
- return n < matches.length ? matches.slice(-1 * n).join(ch).length : null;
- },
- toRealChar: function(ch) {
- if (ch.length === 1)
- return ch;
- if (/^shift-./.test(ch))
- return ch[ch.length - 1].toUpperCase();
- else
- return "";
- },
- copyLine: function(editor) {
- var pos = editor.getCursorPosition();
- editor.selection.moveTo(pos.row, pos.column);
- editor.selection.selectLine();
- registers._default.isLine = true;
- registers._default.text = editor.getCopyText().replace(/\n$/, "");
- editor.selection.moveTo(pos.row, pos.column);
- }
- };
- });
- ace.define("ace/keyboard/vim/maps/motions",["require","exports","module","ace/keyboard/vim/maps/util","ace/search","ace/range"], function(require, exports, module) {
- "use strict";
- var util = require("./util");
- var keepScrollPosition = function(editor, fn) {
- var scrollTopRow = editor.renderer.getScrollTopRow();
- var initialRow = editor.getCursorPosition().row;
- var diff = initialRow - scrollTopRow;
- fn && fn.call(editor);
- editor.renderer.scrollToRow(editor.getCursorPosition().row - diff);
- };
- function Motion(m) {
- if (typeof m == "function") {
- var getPos = m;
- m = this;
- } else {
- var getPos = m.getPos;
- }
- m.nav = function(editor, range, count, param) {
- var a = getPos(editor, range, count, param, false);
- if (!a)
- return;
- editor.selection.moveTo(a.row, a.column);
- };
- m.sel = function(editor, range, count, param) {
- var a = getPos(editor, range, count, param, true);
- if (!a)
- return;
- editor.selection.selectTo(a.row, a.column);
- };
- return m;
- }
- var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
- var wordSeparatorRe = /[.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
- var whiteRe = /\s/;
- var StringStream = function(editor, cursor) {
- var sel = editor.selection;
- this.range = sel.getRange();
- cursor = cursor || sel.selectionLead;
- this.row = cursor.row;
- this.col = cursor.column;
- var line = editor.session.getLine(this.row);
- var maxRow = editor.session.getLength();
- this.ch = line[this.col] || '\n';
- this.skippedLines = 0;
- this.next = function() {
- this.ch = line[++this.col] || this.handleNewLine(1);
- return this.ch;
- };
- this.prev = function() {
- this.ch = line[--this.col] || this.handleNewLine(-1);
- return this.ch;
- };
- this.peek = function(dir) {
- var ch = line[this.col + dir];
- if (ch)
- return ch;
- if (dir == -1)
- return '\n';
- if (this.col == line.length - 1)
- return '\n';
- return editor.session.getLine(this.row + 1)[0] || '\n';
- };
- this.handleNewLine = function(dir) {
- if (dir == 1){
- if (this.col == line.length)
- return '\n';
- if (this.row == maxRow - 1)
- return '';
- this.col = 0;
- this.row ++;
- line = editor.session.getLine(this.row);
- this.skippedLines++;
- return line[0] || '\n';
- }
- if (dir == -1) {
- if (this.row === 0)
- return '';
- this.row --;
- line = editor.session.getLine(this.row);
- this.col = line.length;
- this.skippedLines--;
- return '\n';
- }
- };
- this.debug = function() {
- console.log(line.substring(0, this.col)+'|'+this.ch+'\''+this.col+'\''+line.substr(this.col+1));
- };
- };
- var Search = require("../../../search").Search;
- var search = new Search();
- function find(editor, needle, dir) {
- search.$options.needle = needle;
- search.$options.backwards = dir == -1;
- return search.find(editor.session);
- }
- var Range = require("../../../range").Range;
- var LAST_SEARCH_MOTION = {};
- module.exports = {
- "w": new Motion(function(editor) {
- var str = new StringStream(editor);
- if (str.ch && wordSeparatorRe.test(str.ch)) {
- while (str.ch && wordSeparatorRe.test(str.ch))
- str.next();
- } else {
- while (str.ch && !nonWordRe.test(str.ch))
- str.next();
- }
- while (str.ch && whiteRe.test(str.ch) && str.skippedLines < 2)
- str.next();
- str.skippedLines == 2 && str.prev();
- return {column: str.col, row: str.row};
- }),
- "W": new Motion(function(editor) {
- var str = new StringStream(editor);
- while(str.ch && !(whiteRe.test(str.ch) && !whiteRe.test(str.peek(1))) && str.skippedLines < 2)
- str.next();
- if (str.skippedLines == 2)
- str.prev();
- else
- str.next();
- return {column: str.col, row: str.row};
- }),
- "b": new Motion(function(editor) {
- var str = new StringStream(editor);
- str.prev();
- while (str.ch && whiteRe.test(str.ch) && str.skippedLines > -2)
- str.prev();
- if (str.ch && wordSeparatorRe.test(str.ch)) {
- while (str.ch && wordSeparatorRe.test(str.ch))
- str.prev();
- } else {
- while (str.ch && !nonWordRe.test(str.ch))
- str.prev();
- }
- str.ch && str.next();
- return {column: str.col, row: str.row};
- }),
- "B": new Motion(function(editor) {
- var str = new StringStream(editor);
- str.prev();
- while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(-1))) && str.skippedLines > -2)
- str.prev();
- if (str.skippedLines == -2)
- str.next();
- return {column: str.col, row: str.row};
- }),
- "e": new Motion(function(editor) {
- var str = new StringStream(editor);
- str.next();
- while (str.ch && whiteRe.test(str.ch))
- str.next();
- if (str.ch && wordSeparatorRe.test(str.ch)) {
- while (str.ch && wordSeparatorRe.test(str.ch))
- str.next();
- } else {
- while (str.ch && !nonWordRe.test(str.ch))
- str.next();
- }
- str.ch && str.prev();
- return {column: str.col, row: str.row};
- }),
- "E": new Motion(function(editor) {
- var str = new StringStream(editor);
- str.next();
- while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(1))))
- str.next();
- return {column: str.col, row: str.row};
- }),
- "l": {
- nav: function(editor) {
- var pos = editor.getCursorPosition();
- var col = pos.column;
- var lineLen = editor.session.getLine(pos.row).length;
- if (lineLen && col !== lineLen)
- editor.navigateRight();
- },
- sel: function(editor) {
- var pos = editor.getCursorPosition();
- var col = pos.column;
- var lineLen = editor.session.getLine(pos.row).length;
- if (lineLen && col !== lineLen) //In selection mode you can select the newline
- editor.selection.selectRight();
- }
- },
- "h": {
- nav: function(editor) {
- var pos = editor.getCursorPosition();
- if (pos.column > 0)
- editor.navigateLeft();
- },
- sel: function(editor) {
- var pos = editor.getCursorPosition();
- if (pos.column > 0)
- editor.selection.selectLeft();
- }
- },
- "H": {
- nav: function(editor) {
- var row = editor.renderer.getScrollTopRow();
- editor.moveCursorTo(row);
- },
- sel: function(editor) {
- var row = editor.renderer.getScrollTopRow();
- editor.selection.selectTo(row);
- }
- },
- "M": {
- nav: function(editor) {
- var topRow = editor.renderer.getScrollTopRow();
- var bottomRow = editor.renderer.getScrollBottomRow();
- var row = topRow + ((bottomRow - topRow) / 2);
- editor.moveCursorTo(row);
- },
- sel: function(editor) {
- var topRow = editor.renderer.getScrollTopRow();
- var bottomRow = editor.renderer.getScrollBottomRow();
- var row = topRow + ((bottomRow - topRow) / 2);
- editor.selection.selectTo(row);
- }
- },
- "L": {
- nav: function(editor) {
- var row = editor.renderer.getScrollBottomRow();
- editor.moveCursorTo(row);
- },
- sel: function(editor) {
- var row = editor.renderer.getScrollBottomRow();
- editor.selection.selectTo(row);
- }
- },
- "k": {
- nav: function(editor) {
- editor.navigateUp();
- },
- sel: function(editor) {
- editor.selection.selectUp();
- }
- },
- "j": {
- nav: function(editor) {
- editor.navigateDown();
- },
- sel: function(editor) {
- editor.selection.selectDown();
- }
- },
- "i": {
- param: true,
- sel: function(editor, range, count, param) {
- switch (param) {
- case "w":
- editor.selection.selectWord();
- break;
- case "W":
- editor.selection.selectAWord();
- break;
- case "(":
- case "{":
- case "[":
- var cursor = editor.getCursorPosition();
- var end = editor.session.$findClosingBracket(param, cursor, /paren/);
- if (!end)
- return;
- var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/);
- if (!start)
- return;
- start.column ++;
- editor.selection.setSelectionRange(Range.fromPoints(start, end));
- break;
- case "'":
- case '"':
- case "/":
- var end = find(editor, param, 1);
- if (!end)
- return;
- var start = find(editor, param, -1);
- if (!start)
- return;
- editor.selection.setSelectionRange(Range.fromPoints(start.end, end.start));
- break;
- }
- }
- },
- "a": {
- param: true,
- sel: function(editor, range, count, param) {
- switch (param) {
- case "w":
- editor.selection.selectAWord();
- break;
- case "W":
- editor.selection.selectAWord();
- break;
- case ")":
- case "}":
- case "]":
- param = editor.session.$brackets[param];
- case "(":
- case "{":
- case "[":
- var cursor = editor.getCursorPosition();
- var end = editor.session.$findClosingBracket(param, cursor, /paren/);
- if (!end)
- return;
- var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/);
- if (!start)
- return;
- end.column ++;
- editor.selection.setSelectionRange(Range.fromPoints(start, end));
- break;
- case "'":
- case "\"":
- case "/":
- var end = find(editor, param, 1);
- if (!end)
- return;
- var start = find(editor, param, -1);
- if (!start)
- return;
- end.column ++;
- editor.selection.setSelectionRange(Range.fromPoints(start.start, end.end));
- break;
- }
- }
- },
- "f": new Motion({
- param: true,
- handlesCount: true,
- getPos: function(editor, range, count, param, isSel, isRepeat) {
- if (param == "space") param = " ";
- if (!isRepeat)
- LAST_SEARCH_MOTION = {ch: "f", param: param};
- var cursor = editor.getCursorPosition();
- var column = util.getRightNthChar(editor, cursor, param, count || 1);
- if (typeof column === "number") {
- cursor.column += column + (isSel ? 2 : 1);
- return cursor;
- }
- }
- }),
- "F": new Motion({
- param: true,
- handlesCount: true,
- getPos: function(editor, range, count, param, isSel, isRepeat) {
- if (param == "space") param = " ";
- if (!isRepeat)
- LAST_SEARCH_MOTION = {ch: "F", param: param};
- var cursor = editor.getCursorPosition();
- var column = util.getLeftNthChar(editor, cursor, param, count || 1);
- if (typeof column === "number") {
- cursor.column -= column + 1;
- return cursor;
- }
- }
- }),
- "t": new Motion({
- param: true,
- handlesCount: true,
- getPos: function(editor, range, count, param, isSel, isRepeat) {
- if (param == "space") param = " ";
- if (!isRepeat)
- LAST_SEARCH_MOTION = {ch: "t", param: param};
- var cursor = editor.getCursorPosition();
- var column = util.getRightNthChar(editor, cursor, param, count || 1);
- if (isRepeat && column == 0 && !(count > 1))
- var column = util.getRightNthChar(editor, cursor, param, 2);
-
- if (typeof column === "number") {
- cursor.column += column + (isSel ? 1 : 0);
- return cursor;
- }
- }
- }),
- "T": new Motion({
- param: true,
- handlesCount: true,
- getPos: function(editor, range, count, param, isSel, isRepeat) {
- if (param == "space") param = " ";
- if (!isRepeat)
- LAST_SEARCH_MOTION = {ch: "T", param: param};
- var cursor = editor.getCursorPosition();
- var column = util.getLeftNthChar(editor, cursor, param, count || 1);
- if (isRepeat && column == 0 && !(count > 1))
- var column = util.getLeftNthChar(editor, cursor, param, 2);
-
- if (typeof column === "number") {
- cursor.column -= column;
- return cursor;
- }
- }
- }),
- ";": new Motion({
- handlesCount: true,
- getPos: function(editor, range, count, param, isSel) {
- var ch = LAST_SEARCH_MOTION.ch;
- if (!ch)
- return;
- return module.exports[ch].getPos(
- editor, range, count, LAST_SEARCH_MOTION.param, isSel, true
- );
- }
- }),
- ",": new Motion({
- handlesCount: true,
- getPos: function(editor, range, count, param, isSel) {
- var ch = LAST_SEARCH_MOTION.ch;
- if (!ch)
- return;
- var up = ch.toUpperCase();
- ch = ch === up ? ch.toLowerCase() : up;
-
- return module.exports[ch].getPos(
- editor, range, count, LAST_SEARCH_MOTION.param, isSel, true
- );
- }
- }),
- "^": {
- nav: function(editor) {
- editor.navigateLineStart();
- },
- sel: function(editor) {
- editor.selection.selectLineStart();
- }
- },
- "$": {
- handlesCount: true,
- nav: function(editor, range, count, param) {
- if (count > 1) {
- editor.navigateDown(count-1);
- }
- editor.navigateLineEnd();
- },
- sel: function(editor, range, count, param) {
- if (count > 1) {
- editor.selection.moveCursorBy(count-1, 0);
- }
- editor.selection.selectLineEnd();
- }
- },
- "0": new Motion(function(ed) {
- return {row: ed.selection.lead.row, column: 0};
- }),
- "G": {
- nav: function(editor, range, count, param) {
- if (!count && count !== 0) { // Stupid JS
- count = editor.session.getLength();
- }
- editor.gotoLine(count);
- },
- sel: function(editor, range, count, param) {
- if (!count && count !== 0) { // Stupid JS
- count = editor.session.getLength();
- }
- editor.selection.selectTo(count, 0);
- }
- },
- "g": {
- param: true,
- nav: function(editor, range, count, param) {
- switch(param) {
- case "m":
- console.log("Middle line");
- break;
- case "e":
- console.log("End of prev word");
- break;
- case "g":
- editor.gotoLine(count || 0);
- case "u":
- editor.gotoLine(count || 0);
- case "U":
- editor.gotoLine(count || 0);
- }
- },
- sel: function(editor, range, count, param) {
- switch(param) {
- case "m":
- console.log("Middle line");
- break;
- case "e":
- console.log("End of prev word");
- break;
- case "g":
- editor.selection.selectTo(count || 0, 0);
- }
- }
- },
- "o": {
- nav: function(editor, range, count, param) {
- count = count || 1;
- var content = "";
- while (0 < count--)
- content += "\n";
- if (content.length) {
- editor.navigateLineEnd()
- editor.insert(content);
- util.insertMode(editor);
- }
- }
- },
- "O": {
- nav: function(editor, range, count, param) {
- var row = editor.getCursorPosition().row;
- count = count || 1;
- var content = "";
- while (0 < count--)
- content += "\n";
- if (content.length) {
- if(row > 0) {
- editor.navigateUp();
- editor.navigateLineEnd()
- editor.insert(content);
- } else {
- editor.session.insert({row: 0, column: 0}, content);
- editor.navigateUp();
- }
- util.insertMode(editor);
- }
- }
- },
- "%": new Motion(function(editor){
- var brRe = /[\[\]{}()]/g;
- var cursor = editor.getCursorPosition();
- var ch = editor.session.getLine(cursor.row)[cursor.column];
- if (!brRe.test(ch)) {
- var range = find(editor, brRe);
- if (!range)
- return;
- cursor = range.start;
- }
- var match = editor.session.findMatchingBracket({
- row: cursor.row,
- column: cursor.column + 1
- });
- return match;
- }),
- "{": new Motion(function(ed) {
- var session = ed.session;
- var row = session.selection.lead.row;
- while(row > 0 && !/\S/.test(session.getLine(row)))
- row--;
- while(/\S/.test(session.getLine(row)))
- row--;
- return {column: 0, row: row};
- }),
- "}": new Motion(function(ed) {
- var session = ed.session;
- var l = session.getLength();
- var row = session.selection.lead.row;
- while(row < l && !/\S/.test(session.getLine(row)))
- row++;
- while(/\S/.test(session.getLine(row)))
- row++;
- return {column: 0, row: row};
- }),
- "ctrl-d": {
- nav: function(editor, range, count, param) {
- editor.selection.clearSelection();
- keepScrollPosition(editor, editor.gotoPageDown);
- },
- sel: function(editor, range, count, param) {
- keepScrollPosition(editor, editor.selectPageDown);
- }
- },
- "ctrl-u": {
- nav: function(editor, range, count, param) {
- editor.selection.clearSelection();
- keepScrollPosition(editor, editor.gotoPageUp);
- },
- sel: function(editor, range, count, param) {
- keepScrollPosition(editor, editor.selectPageUp);
- }
- },
- "`": new Motion({
- param: true,
- handlesCount: true,
- getPos: function(editor, range, count, param, isSel) {
- var s = editor.session;
- var marker = s.vimMarkers && s.vimMarkers[param];
- if (marker) {
- return marker.getPosition();
- }
- }
- }),
- "'": new Motion({
- param: true,
- handlesCount: true,
- getPos: function(editor, range, count, param, isSel) {
- var s = editor.session;
- var marker = s.vimMarkers && s.vimMarkers[param];
- if (marker) {
- var pos = marker.getPosition();
- var line = editor.session.getLine(pos.row);
- pos.column = line.search(/\S/);
- if (pos.column == -1)
- pos.column = line.length;
- return pos;
- }
- },
- isLine: true
- })
- };
- module.exports.backspace = module.exports.left = module.exports.h;
- module.exports.space = module.exports['return'] = module.exports.right = module.exports.l;
- module.exports.up = module.exports.k;
- module.exports.down = module.exports.j;
- module.exports.pagedown = module.exports["ctrl-d"];
- module.exports.pageup = module.exports["ctrl-u"];
- module.exports.home = module.exports["0"];
- module.exports.end = module.exports["$"];
- });
- ace.define("ace/keyboard/vim/maps/operators",["require","exports","module","ace/keyboard/vim/maps/util","ace/keyboard/vim/registers","ace/range"], function(require, exports, module) {
- "use strict";
- var util = require("./util");
- var registers = require("../registers");
- var Range = require("../../../range").Range;
- module.exports = {
- "d": {
- selFn: function(editor, range, count, param) {
- registers._default.text = editor.getCopyText();
- registers._default.isLine = util.onVisualLineMode;
- if(util.onVisualLineMode)
- editor.removeLines();
- else
- editor.session.remove(range);
- util.normalMode(editor);
- },
- fn: function(editor, range, count, param) {
- count = count || 1;
- switch (param) {
- case "d":
- registers._default.text = "";
- registers._default.isLine = true;
- for (var i = 0; i < count; i++) {
- editor.selection.selectLine();
- registers._default.text += editor.getCopyText();
- var selRange = editor.getSelectionRange();
- if (!selRange.isMultiLine()) {
- var row = selRange.start.row - 1;
- var col = editor.session.getLine(row).length
- selRange.setStart(row, col);
- editor.session.remove(selRange);
- editor.selection.clearSelection();
- break;
- }
- editor.session.remove(selRange);
- editor.selection.clearSelection();
- }
- registers._default.text = registers._default.text.replace(/\n$/, "");
- break;
- default:
- if (range) {
- editor.selection.setSelectionRange(range);
- registers._default.text = editor.getCopyText();
- registers._default.isLine = false;
- editor.session.remove(range);
- editor.selection.clearSelection();
- }
- }
- }
- },
- "c": {
- selFn: function(editor, range, count, param) {
- editor.session.remove(range);
- util.insertMode(editor);
- },
- fn: function(editor, range, count, param) {
- count = count || 1;
- switch (param) {
- case "c":
- editor.$blockScrolling++;
- editor.selection.$moveSelection(function() {
- editor.selection.moveCursorBy(count - 1, 0);
- });
- var rows = editor.$getSelectedRows();
- range = new Range(rows.first, 0, rows.last, Infinity);
- editor.session.remove(range);
- editor.$blockScrolling--;
- util.insertMode(editor);
- break;
- default:
- if (range) {
- editor.session.remove(range);
- util.insertMode(editor);
- }
- }
- }
- },
- "y": {
- selFn: function(editor, range, count, param) {
- registers._default.text = editor.getCopyText();
- registers._default.isLine = util.onVisualLineMode;
- editor.selection.clearSelection();
- util.normalMode(editor);
- },
- fn: function(editor, range, count, param) {
- count = count || 1;
- if (param && param.isLine)
- param = "y";
- switch (param) {
- case "y":
- var pos = editor.getCursorPosition();
- editor.selection.selectLine();
- for (var i = 0; i < count - 1; i++) {
- editor.selection.moveCursorDown();
- }
- registers._default.text = editor.getCopyText().replace(/\n$/, "");
- editor.selection.clearSelection();
- registers._default.isLine = true;
- editor.moveCursorToPosition(pos);
- break;
- default:
- if (range) {
- var pos = editor.getCursorPosition();
- editor.selection.setSelectionRange(range);
- registers._default.text = editor.getCopyText();
- registers._default.isLine = false;
- editor.selection.clearSelection();
- editor.moveCursorTo(pos.row, pos.column);
- }
- }
- }
- },
- ">": {
- selFn: function(editor, range, count, param) {
- count = count || 1;
- for (var i = 0; i < count; i++) {
- editor.indent();
- }
- util.normalMode(editor);
- },
- fn: function(editor, range, count, param) {
- count = parseInt(count || 1, 10);
- switch (param) {
- case ">":
- var pos = editor.getCursorPosition();
- editor.selection.selectLine();
- for (var i = 0; i < count - 1; i++) {
- editor.selection.moveCursorDown();
- }
- editor.indent();
- editor.selection.clearSelection();
- editor.moveCursorToPosition(pos);
- editor.navigateLineEnd();
- editor.navigateLineStart();
- break;
- }
- }
- },
- "<": {
- selFn: function(editor, range, count, param) {
- count = count || 1;
- for (var i = 0; i < count; i++) {
- editor.blockOutdent();
- }
- util.normalMode(editor);
- },
- fn: function(editor, range, count, param) {
- count = count || 1;
- switch (param) {
- case "<":
- var pos = editor.getCursorPosition();
- editor.selection.selectLine();
- for (var i = 0; i < count - 1; i++) {
- editor.selection.moveCursorDown();
- }
- editor.blockOutdent();
- editor.selection.clearSelection();
- editor.moveCursorToPosition(pos);
- editor.navigateLineEnd();
- editor.navigateLineStart();
- break;
- }
- }
- }
- };
- });
- "use strict"
- ace.define("ace/keyboard/vim/maps/aliases",["require","exports","module"], function(require, exports, module) {
- module.exports = {
- "x": {
- operator: {
- ch: "d",
- count: 1
- },
- motion: {
- ch: "l",
- count: 1
- }
- },
- "X": {
- operator: {
- ch: "d",
- count: 1
- },
- motion: {
- ch: "h",
- count: 1
- }
- },
- "D": {
- operator: {
- ch: "d",
- count: 1
- },
- motion: {
- ch: "$",
- count: 1
- }
- },
- "C": {
- operator: {
- ch: "c",
- count: 1
- },
- motion: {
- ch: "$",
- count: 1
- }
- },
- "s": {
- operator: {
- ch: "c",
- count: 1
- },
- motion: {
- ch: "l",
- count: 1
- }
- },
- "S": {
- operator: {
- ch: "c",
- count: 1
- },
- param: "c"
- }
- };
- });
- ace.define("ace/keyboard/vim/commands",["require","exports","module","ace/lib/lang","ace/keyboard/vim/maps/util","ace/keyboard/vim/maps/motions","ace/keyboard/vim/maps/operators","ace/keyboard/vim/maps/aliases","ace/keyboard/vim/registers"], function(require, exports, module) {
- "never use strict";
- var lang = require("../../lib/lang");
- var util = require("./maps/util");
- var motions = require("./maps/motions");
- var operators = require("./maps/operators");
- var alias = require("./maps/aliases");
- var registers = require("./registers");
- var NUMBER = 1;
- var OPERATOR = 2;
- var MOTION = 3;
- var ACTION = 4;
- var HMARGIN = 8; // Minimum amount of line separation between margins;
- var repeat = function repeat(fn, count, args) {
- while (0 < count--)
- fn.apply(this, args);
- };
- var ensureScrollMargin = function(editor) {
- var renderer = editor.renderer;
- var pos = renderer.$cursorLayer.getPixelPosition();
- var top = pos.top;
- var margin = HMARGIN * renderer.layerConfig.lineHeight;
- if (2 * margin > renderer.$size.scrollerHeight)
- margin = renderer.$size.scrollerHeight / 2;
- if (renderer.scrollTop > top - margin) {
- renderer.session.setScrollTop(top - margin);
- }
- if (renderer.scrollTop + renderer.$size.scrollerHeight < top + margin + renderer.lineHeight) {
- renderer.session.setScrollTop(top + margin + renderer.lineHeight - renderer.$size.scrollerHeight);
- }
- };
- var actions = exports.actions = {
- "z": {
- param: true,
- fn: function(editor, range, count, param) {
- switch (param) {
- case "z":
- editor.renderer.alignCursor(null, 0.5);
- break;
- case "t":
- editor.renderer.alignCursor(null, 0);
- break;
- case "b":
- editor.renderer.alignCursor(null, 1);
- break;
- case "c":
- editor.session.onFoldWidgetClick(range.start.row, {domEvent:{target :{}}});
- break;
- case "o":
- editor.session.onFoldWidgetClick(range.start.row, {domEvent:{target :{}}});
- break;
- case "C":
- editor.session.foldAll();
- break;
- case "O":
- editor.session.unfold();
- break;
- }
- }
- },
- "r": {
- param: true,
- fn: function(editor, range, count, param) {
- if (param && param.length) {
- if (param.length > 1)
- param = param == "return" ? "\n" : param == "tab" ? "\t" : param;
- repeat(function() { editor.insert(param); }, count || 1);
- editor.navigateLeft();
- }
- }
- },
- "R": {
- fn: function(editor, range, count, param) {
- util.insertMode(editor);
- editor.setOverwrite(true);
- }
- },
- "~": {
- fn: function(editor, range, count) {
- repeat(function() {
- var range = editor.selection.getRange();
- if (range.isEmpty())
- range.end.column++;
- var text = editor.session.getTextRange(range);
- var toggled = text.toUpperCase();
- if (toggled != text)
- editor.session.replace(range, toggled);
- else if (text.toLowerCase() != text)
- editor.session.replace(range, text.toLowerCase())
- else
- editor.navigateRight();
- }, count || 1);
- }
- },
- "*": {
- fn: function(editor, range, count, param) {
- editor.selection.selectWord();
- editor.findNext();
- ensureScrollMargin(editor);
- var r = editor.selection.getRange();
- editor.selection.setSelectionRange(r, true);
- }
- },
- "#": {
- fn: function(editor, range, count, param) {
- editor.selection.selectWord();
- editor.findPrevious();
- ensureScrollMargin(editor);
- var r = editor.selection.getRange();
- editor.selection.setSelectionRange(r, true);
- }
- },
- "m": {
- param: true,
- fn: function(editor, range, count, param) {
- var s = editor.session;
- var markers = s.vimMarkers || (s.vimMarkers = {});
- var c = editor.getCursorPosition();
- if (!markers[param]) {
- markers[param] = editor.session.doc.createAnchor(c);
- }
- markers[param].setPosition(c.row, c.column, true);
- }
- },
- "n": {
- fn: function(editor, range, count, param) {
- var options = editor.getLastSearchOptions();
- options.backwards = false;
- options.start = null;
- editor.selection.moveCursorRight();
- editor.selection.clearSelection();
- editor.findNext(options);
- ensureScrollMargin(editor);
- var r = editor.selection.getRange();
- r.end.row = r.start.row;
- r.end.column = r.start.column;
- editor.selection.setSelectionRange(r, true);
- }
- },
- "N": {
- fn: function(editor, range, count, param) {
- var options = editor.getLastSearchOptions();
- options.backwards = true;
- options.start = null;
- editor.findPrevious(options);
- ensureScrollMargin(editor);
- var r = editor.selection.getRange();
- r.end.row = r.start.row;
- r.end.column = r.start.column;
- editor.selection.setSelectionRange(r, true);
- }
- },
- "v": {
- fn: function(editor, range, count, param) {
- editor.selection.selectRight();
- util.visualMode(editor, false);
- },
- acceptsMotion: true
- },
- "V": {
- fn: function(editor, range, count, param) {
- var row = editor.getCursorPosition().row;
- editor.selection.moveTo(row, 0);
- editor.selection.selectLineEnd();
- editor.selection.visualLineStart = row;
- util.visualMode(editor, true);
- },
- acceptsMotion: true
- },
- "Y": {
- fn: function(editor, range, count, param) {
- util.copyLine(editor);
- }
- },
- "p": {
- fn: function(editor, range, count, param) {
- var defaultReg = registers._default;
- editor.setOverwrite(false);
- if (defaultReg.isLine) {
- var pos = editor.getCursorPosition();
- pos.column = editor.session.getLine(pos.row).length;
- var text = lang.stringRepeat("\n" + defaultReg.text, count || 1);
- editor.session.insert(pos, text);
- editor.moveCursorTo(pos.row + 1, 0);
- }
- else {
- editor.navigateRight();
- editor.insert(lang.stringRepeat(defaultReg.text, count || 1));
- editor.navigateLeft();
- }
- editor.setOverwrite(true);
- editor.selection.clearSelection();
- }
- },
- "P": {
- fn: function(editor, range, count, param) {
- var defaultReg = registers._default;
- editor.setOverwrite(false);
- if (defaultReg.isLine) {
- var pos = editor.getCursorPosition();
- pos.column = 0;
- var text = lang.stringRepeat(defaultReg.text + "\n", count || 1);
- editor.session.insert(pos, text);
- editor.moveCursorToPosition(pos);
- }
- else {
- editor.insert(lang.stringRepeat(defaultReg.text, count || 1));
- }
- editor.setOverwrite(true);
- editor.selection.clearSelection();
- }
- },
- "J": {
- fn: function(editor, range, count, param) {
- var session = editor.session;
- range = editor.getSelectionRange();
- var pos = {row: range.start.row, column: range.start.column};
- count = count || range.end.row - range.start.row;
- var maxRow = Math.min(pos.row + (count || 1), session.getLength() - 1);
- range.start.column = session.getLine(pos.row).length;
- range.end.column = session.getLine(maxRow).length;
- range.end.row = maxRow;
- var text = "";
- for (var i = pos.row; i < maxRow; i++) {
- var nextLine = session.getLine(i + 1);
- text += " " + /^\s*(.*)$/.exec(nextLine)[1] || "";
- }
- session.replace(range, text);
- editor.moveCursorTo(pos.row, pos.column);
- }
- },
- "u": {
- fn: function(editor, range, count, param) {
- count = parseInt(count || 1, 10);
- for (var i = 0; i < count; i++) {
- editor.undo();
- }
- editor.selection.clearSelection();
- }
- },
- "ctrl-r": {
- fn: function(editor, range, count, param) {
- count = parseInt(count || 1, 10);
- for (var i = 0; i < count; i++) {
- editor.redo();
- }
- editor.selection.clearSelection();
- }
- },
- ":": {
- fn: function(editor, range, count, param) {
- var val = ":";
- if (count > 1)
- val = ".,.+" + count + val;
- if (editor.showCommandLine)
- editor.showCommandLine(val);
- }
- },
- "/": {
- fn: function(editor, range, count, param) {
- if (editor.showCommandLine)
- editor.showCommandLine("/");
- }
- },
- "?": {
- fn: function(editor, range, count, param) {
- if (editor.showCommandLine)
- editor.showCommandLine("?");
- }
- },
- ".": {
- fn: function(editor, range, count, param) {
- util.onInsertReplaySequence = inputBuffer.lastInsertCommands;
- var previous = inputBuffer.previous;
- if (previous) // If there is a previous action
- inputBuffer.exec(editor, previous.action, previous.param);
- }
- },
- "ctrl-x": {
- fn: function(editor, range, count, param) {
- editor.modifyNumber(-(count || 1));
- }
- },
- "ctrl-a": {
- fn: function(editor, range, count, param) {
- editor.modifyNumber(count || 1);
- }
- }
- };
- var inputBuffer = exports.inputBuffer = {
- accepting: [NUMBER, OPERATOR, MOTION, ACTION],
- currentCmd: null,
- currentCount: "",
- pendingCount: "",
- status: "",
- operator: null,
- motion: null,
- lastInsertCommands: [],
- push: function(editor, ch, keyId) {
- var status = this.status;
- var isKeyHandled = true;
- this.idle = false;
- var wObj = this.waitingForParam;
- if (/^numpad\d+$/i.test(ch))
- ch = ch.substr(6);
-
- if (wObj) {
- this.exec(editor, wObj, ch);
- }
- else if (!(ch === "0" && !this.currentCount.length) &&
- (/^\d+$/.test(ch) && this.isAccepting(NUMBER))) {
- this.currentCount += ch;
- this.currentCmd = NUMBER;
- this.accepting = [NUMBER, OPERATOR, MOTION, ACTION];
- }
- else if (!this.operator && this.isAccepting(OPERATOR) && operators[ch]) {
- this.operator = {
- ch: ch,
- count: this.getCount()
- };
- this.currentCmd = OPERATOR;
- this.accepting = [NUMBER, MOTION, ACTION];
- this.exec(editor, { operator: this.operator });
- }
- else if (motions[ch] && this.isAccepting(MOTION)) {
- this.currentCmd = MOTION;
- var ctx = {
- operator: this.operator,
- motion: {
- ch: ch,
- count: this.getCount()
- }
- };
- if (motions[ch].param)
- this.waitForParam(ctx);
- else
- this.exec(editor, ctx);
- }
- else if (alias[ch] && this.isAccepting(MOTION)) {
- alias[ch].operator.count = this.getCount();
- this.exec(editor, alias[ch]);
- }
- else if (actions[ch] && this.isAccepting(ACTION)) {
- var actionObj = {
- action: {
- fn: actions[ch].fn,
- count: this.getCount()
- }
- };
- if (actions[ch].param) {
- this.waitForParam(actionObj);
- }
- else {
- this.exec(editor, actionObj);
- }
- if (actions[ch].acceptsMotion)
- this.idle = false;
- }
- else if (this.operator) {
- this.operator.count = this.getCount();
- this.exec(editor, { operator: this.operator }, ch);
- }
- else {
- isKeyHandled = ch.length == 1;
- this.reset();
- }
-
- if (this.waitingForParam || this.motion || this.operator) {
- this.status += ch;
- } else if (this.currentCount) {
- this.status = this.currentCount;
- } else if (this.status) {
- this.status = "";
- }
- if (this.status != status)
- editor._emit("changeStatus");
- return isKeyHandled;
- },
- waitForParam: function(cmd) {
- this.waitingForParam = cmd;
- },
- getCount: function() {
- var count = this.currentCount || this.pendingCount;
- this.currentCount = "";
- this.pendingCount = count;
- return count && parseInt(count, 10);
- },
- exec: function(editor, action, param) {
- var m = action.motion;
- var o = action.operator;
- var a = action.action;
- if (!param)
- param = action.param;
- if (o) {
- this.previous = {
- action: action,
- param: param
- };
- }
- if (o && !editor.selection.isEmpty()) {
- if (operators[o.ch].selFn) {
- operators[o.ch].selFn(editor, editor.getSelectionRange(), o.count, param);
- this.reset();
- }
- return;
- }
- else if (!m && !a && o && param) {
- operators[o.ch].fn(editor, null, o.count, param);
- this.reset();
- }
- else if (m) {
- var run = function(fn) {
- if (fn && typeof fn === "function") { // There should always be a motion
- if (m.count && !motionObj.handlesCount)
- repeat(fn, m.count, [editor, null, m.count, param]);
- else
- fn(editor, null, m.count, param);
- }
- };
- var motionObj = motions[m.ch];
- var selectable = motionObj.sel;
- if (!o) {
- if ((util.onVisualMode || util.onVisualLineMode) && selectable)
- run(motionObj.sel);
- else
- run(motionObj.nav);
- }
- else if (selectable) {
- repeat(function() {
- run(motionObj.sel);
- operators[o.ch].fn(editor, editor.getSelectionRange(),
- o.count, motionObj.param ? motionObj : param);
- }, o.count || 1);
- }
- this.reset();
- }
- else if (a) {
- a.fn(editor, editor.getSelectionRange(), a.count, param);
- this.reset();
- }
- handleCursorMove(editor);
- },
- isAccepting: function(type) {
- return this.accepting.indexOf(type) !== -1;
- },
- reset: function() {
- this.operator = null;
- this.motion = null;
- this.currentCount = "";
- this.pendingCount = "";
- this.status = "";
- this.accepting = [NUMBER, OPERATOR, MOTION, ACTION];
- this.idle = true;
- this.waitingForParam = null;
- }
- };
- function setPreviousCommand(fn) {
- inputBuffer.previous = { action: { action: { fn: fn } } };
- }
- exports.coreCommands = {
- start: {
- exec: function start(editor) {
- util.insertMode(editor);
- setPreviousCommand(start);
- }
- },
- startBeginning: {
- exec: function startBeginning(editor) {
- editor.navigateLineStart();
- util.insertMode(editor);
- setPreviousCommand(startBeginning);
- }
- },
- stop: {
- exec: function stop(editor) {
- inputBuffer.reset();
- util.onVisualMode = false;
- util.onVisualLineMode = false;
- inputBuffer.lastInsertCommands = util.normalMode(editor);
- }
- },
- append: {
- exec: function append(editor) {
- var pos = editor.getCursorPosition();
- var lineLen = editor.session.getLine(pos.row).length;
- if (lineLen)
- editor.navigateRight();
- util.insertMode(editor);
- setPreviousCommand(append);
- }
- },
- appendEnd: {
- exec: function appendEnd(editor) {
- editor.navigateLineEnd();
- util.insertMode(editor);
- setPreviousCommand(appendEnd);
- }
- }
- };
- var handleCursorMove = exports.onCursorMove = function(editor, e) {
- if (util.currentMode === 'insert' || handleCursorMove.running)
- return;
- else if(!editor.selection.isEmpty()) {
- handleCursorMove.running = true;
- if (util.onVisualLineMode) {
- var originRow = editor.selection.visualLineStart;
- var cursorRow = editor.getCursorPosition().row;
- if(originRow <= cursorRow) {
- var endLine = editor.session.getLine(cursorRow);
- editor.selection.moveTo(originRow, 0);
- editor.selection.selectTo(cursorRow, endLine.length);
- } else {
- var endLine = editor.session.getLine(originRow);
- editor.selection.moveTo(originRow, endLine.length);
- editor.selection.selectTo(cursorRow, 0);
- }
- }
- handleCursorMove.running = false;
- return;
- }
- else {
- if (e && (util.onVisualLineMode || util.onVisualMode)) {
- editor.selection.clearSelection();
- util.normalMode(editor);
- }
- handleCursorMove.running = true;
- var pos = editor.getCursorPosition();
- var lineLen = editor.session.getLine(pos.row).length;
- if (lineLen && pos.column === lineLen)
- editor.navigateLeft();
- handleCursorMove.running = false;
- }
- };
- });
- ace.define("ace/keyboard/vim",["require","exports","module","ace/keyboard/vim/commands","ace/keyboard/vim/maps/util","ace/lib/useragent"], function(require, exports, module) {
- "use strict";
- var cmds = require("./vim/commands");
- var coreCommands = cmds.coreCommands;
- var util = require("./vim/maps/util");
- var useragent = require("../lib/useragent");
- var startCommands = {
- "i": {
- command: coreCommands.start
- },
- "I": {
- command: coreCommands.startBeginning
- },
- "a": {
- command: coreCommands.append
- },
- "A": {
- command: coreCommands.appendEnd
- },
- "ctrl-f": {
- command: "gotopagedown"
- },
- "ctrl-b": {
- command: "gotopageup"
- }
- };
- exports.handler = {
- $id: "ace/keyboard/vim",
- handleMacRepeat: function(data, hashId, key) {
- if (hashId == -1) {
- data.inputChar = key;
- data.lastEvent = "input";
- } else if (data.inputChar && data.$lastHash == hashId && data.$lastKey == key) {
- if (data.lastEvent == "input") {
- data.lastEvent = "input1";
- } else if (data.lastEvent == "input1") {
- return true;
- }
- } else {
- data.$lastHash = hashId;
- data.$lastKey = key;
- data.lastEvent = "keypress";
- }
- },
- updateMacCompositionHandlers: function(editor, enable) {
- var onCompositionUpdateOverride = function(text) {
- if (util.currentMode !== "insert") {
- var el = this.textInput.getElement();
- el.blur();
- el.focus();
- el.value = text;
- } else {
- this.onCompositionUpdateOrig(text);
- }
- };
- var onCompositionStartOverride = function(text) {
- if (util.currentMode === "insert") {
- this.onCompositionStartOrig(text);
- }
- };
- if (enable) {
- if (!editor.onCompositionUpdateOrig) {
- editor.onCompositionUpdateOrig = editor.onCompositionUpdate;
- editor.onCompositionUpdate = onCompositionUpdateOverride;
- editor.onCompositionStartOrig = editor.onCompositionStart;
- editor.onCompositionStart = onCompositionStartOverride;
- }
- } else {
- if (editor.onCompositionUpdateOrig) {
- editor.onCompositionUpdate = editor.onCompositionUpdateOrig;
- editor.onCompositionUpdateOrig = null;
- editor.onCompositionStart = editor.onCompositionStartOrig;
- editor.onCompositionStartOrig = null;
- }
- }
- },
- handleKeyboard: function(data, hashId, key, keyCode, e) {
- if (hashId !== 0 && (!key || keyCode == -1))
- return null;
-
- var editor = data.editor;
- var vimState = data.vimState || "start";
-
- if (hashId == 1)
- key = "ctrl-" + key;
- if (key == "ctrl-c") {
- if (!useragent.isMac && editor.getCopyText()) {
- editor.once("copy", function() {
- if (vimState == "start")
- coreCommands.stop.exec(editor);
- else
- editor.selection.clearSelection();
- });
- return {command: "null", passEvent: true};
- }
- return {command: coreCommands.stop};
- } else if ((key == "esc" && hashId === 0) || key == "ctrl-[") {
- return {command: coreCommands.stop};
- } else if (vimState == "start") {
- if (useragent.isMac && this.handleMacRepeat(data, hashId, key)) {
- hashId = -1;
- key = data.inputChar;
- }
-
- if (hashId == -1 || hashId == 1 || hashId === 0 && key.length > 1) {
- if (cmds.inputBuffer.idle && startCommands[key])
- return startCommands[key];
- var isHandled = cmds.inputBuffer.push(editor, key);
- if (!isHandled && hashId !== -1)
- return;
- return {command: "null", passEvent: !isHandled};
- } else if (key == "esc" && hashId === 0) {
- return {command: coreCommands.stop};
- }
- else if (hashId === 0 || hashId == 4) {
- return {command: "null", passEvent: true};
- }
- } else {
- if (key == "ctrl-w") {
- return {command: "removewordleft"};
- }
- }
- },
- attach: function(editor) {
- editor.on("click", exports.onCursorMove);
- if (util.currentMode !== "insert")
- cmds.coreCommands.stop.exec(editor);
- editor.$vimModeHandler = this;
-
- this.updateMacCompositionHandlers(editor, true);
- },
- detach: function(editor) {
- editor.removeListener("click", exports.onCursorMove);
- util.noMode(editor);
- util.currentMode = "normal";
- this.updateMacCompositionHandlers(editor, false);
- },
- actions: cmds.actions,
- getStatusText: function() {
- if (util.currentMode == "insert")
- return "INSERT";
- if (util.onVisualMode)
- return (util.onVisualLineMode ? "VISUAL LINE " : "VISUAL ") + cmds.inputBuffer.status;
- return cmds.inputBuffer.status;
- }
- };
- exports.onCursorMove = function(e) {
- cmds.onCursorMove(e.editor, e);
- exports.onCursorMove.scheduled = false;
- };
- });
|