1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2010, Ajax.org B.V.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of Ajax.org B.V. nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
* ***** END LICENSE BLOCK ***** */
31
define('ace/keyboard/vim', ['require', 'exports', 'module' , 'ace/keyboard/vim/commands', 'ace/keyboard/vim/maps/util', 'ace/lib/useragent'], function(require, exports, module) {
34
var cmds = require("./vim/commands");
35
var coreCommands = cmds.coreCommands;
36
var util = require("./vim/maps/util");
37
var useragent = require("../lib/useragent");
41
command: coreCommands.start
44
command: coreCommands.startBeginning
47
command: coreCommands.append
50
command: coreCommands.appendEnd
53
command: "gotopagedown"
61
handleMacRepeat: function(data, hashId, key) {
64
data.lastEvent = "input";
65
} else if (data.inputChar && data.$lastHash == hashId && data.$lastKey == key) {
66
if (data.lastEvent == "input") {
67
data.lastEvent = "input1";
68
} else if (data.lastEvent == "input1") {
72
data.$lastHash = hashId;
74
data.lastEvent = "keypress";
78
handleKeyboard: function(data, hashId, key, keyCode, e) {
79
if (hashId != 0 && (key == "" || key == "\x00"))
85
if ((key == "esc" && hashId == 0) || key == "ctrl-[") {
86
return {command: coreCommands.stop};
87
} else if (data.state == "start") {
88
if (useragent.isMac && this.handleMacRepeat(data, hashId, key)) {
93
if (hashId == -1 || hashId == 1 || hashId == 0 && key.length > 1) {
94
if (cmds.inputBuffer.idle && startCommands[key])
95
return startCommands[key];
98
exec: function(editor) {
99
return cmds.inputBuffer.push(editor, key);
103
} // if no modifier || shift: wait for input.
104
else if (key.length == 1 && (hashId == 0 || hashId == 4)) {
105
return {command: "null", passEvent: true};
106
} else if (key == "esc" && hashId == 0) {
107
return {command: coreCommands.stop};
110
if (key == "ctrl-w") {
111
return {command: "removewordleft"};
116
attach: function(editor) {
117
editor.on("click", exports.onCursorMove);
118
if (util.currentMode !== "insert")
119
cmds.coreCommands.stop.exec(editor);
120
editor.$vimModeHandler = this;
123
detach: function(editor) {
124
editor.removeListener("click", exports.onCursorMove);
126
util.currentMode = "normal";
129
actions: cmds.actions,
130
getStatusText: function() {
131
if (util.currentMode == "insert")
133
if (util.onVisualMode)
134
return (util.onVisualLineMode ? "VISUAL LINE " : "VISUAL ") + cmds.inputBuffer.status;
135
return cmds.inputBuffer.status;
140
exports.onCursorMove = function(e) {
141
cmds.onCursorMove(e.editor, e);
142
exports.onCursorMove.scheduled = false;
147
define('ace/keyboard/vim/commands', ['require', 'exports', 'module' , '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) {
151
var util = require("./maps/util");
152
var motions = require("./maps/motions");
153
var operators = require("./maps/operators");
154
var alias = require("./maps/aliases");
155
var registers = require("./registers");
161
var HMARGIN = 8; // Minimum amount of line separation between margins;
163
var repeat = function repeat(fn, count, args) {
165
fn.apply(this, args);
168
var ensureScrollMargin = function(editor) {
169
var renderer = editor.renderer;
170
var pos = renderer.$cursorLayer.getPixelPosition();
174
var margin = HMARGIN * renderer.layerConfig.lineHeight;
175
if (2 * margin > renderer.$size.scrollerHeight)
176
margin = renderer.$size.scrollerHeight / 2;
178
if (renderer.scrollTop > top - margin) {
179
renderer.session.setScrollTop(top - margin);
182
if (renderer.scrollTop + renderer.$size.scrollerHeight < top + margin + renderer.lineHeight) {
183
renderer.session.setScrollTop(top + margin + renderer.lineHeight - renderer.$size.scrollerHeight);
187
var actions = exports.actions = {
190
fn: function(editor, range, count, param) {
193
editor.renderer.alignCursor(null, 0.5);
196
editor.renderer.alignCursor(null, 0);
199
editor.renderer.alignCursor(null, 1);
206
fn: function(editor, range, count, param) {
207
if (param && param.length) {
208
repeat(function() { editor.insert(param); }, count || 1);
209
editor.navigateLeft();
214
fn: function(editor, range, count, param) {
215
util.insertMode(editor);
216
editor.setOverwrite(true);
220
fn: function(editor, range, count) {
222
var range = editor.selection.getRange();
225
var text = editor.session.getTextRange(range);
226
var toggled = text.toUpperCase();
228
editor.navigateRight();
230
editor.session.replace(range, toggled);
235
fn: function(editor, range, count, param) {
236
editor.selection.selectWord();
238
ensureScrollMargin(editor);
239
var r = editor.selection.getRange();
240
editor.selection.setSelectionRange(r, true);
244
fn: function(editor, range, count, param) {
245
editor.selection.selectWord();
246
editor.findPrevious();
247
ensureScrollMargin(editor);
248
var r = editor.selection.getRange();
249
editor.selection.setSelectionRange(r, true);
254
fn: function(editor, range, count, param) {
255
var s = editor.session;
256
var markers = s.vimMarkers || (s.vimMarkers = {});
257
var c = editor.getCursorPosition();
258
if (!markers[param]) {
259
markers[param] = editor.session.doc.createAnchor(c);
261
markers[param].setPosition(c.row, c.column, true);
265
fn: function(editor, range, count, param) {
266
var options = editor.getLastSearchOptions();
267
options.backwards = false;
269
editor.selection.moveCursorRight();
270
editor.selection.clearSelection();
271
editor.findNext(options);
273
ensureScrollMargin(editor);
274
var r = editor.selection.getRange();
275
r.end.row = r.start.row;
276
r.end.column = r.start.column;
277
editor.selection.setSelectionRange(r, true);
281
fn: function(editor, range, count, param) {
282
var options = editor.getLastSearchOptions();
283
options.backwards = true;
285
editor.findPrevious(options);
286
ensureScrollMargin(editor);
287
var r = editor.selection.getRange();
288
r.end.row = r.start.row;
289
r.end.column = r.start.column;
290
editor.selection.setSelectionRange(r, true);
294
fn: function(editor, range, count, param) {
295
editor.selection.selectRight();
296
util.visualMode(editor, false);
301
fn: function(editor, range, count, param) {
302
var row = editor.getCursorPosition().row;
303
editor.selection.clearSelection();
304
editor.selection.moveCursorTo(row, 0);
305
editor.selection.selectLineEnd();
306
editor.selection.visualLineStart = row;
308
util.visualMode(editor, true);
313
fn: function(editor, range, count, param) {
314
util.copyLine(editor);
318
fn: function(editor, range, count, param) {
319
var defaultReg = registers._default;
321
editor.setOverwrite(false);
322
if (defaultReg.isLine) {
323
var pos = editor.getCursorPosition();
324
var lines = defaultReg.text.split("\n");
325
editor.session.getDocument().insertLines(pos.row + 1, lines);
326
editor.moveCursorTo(pos.row + 1, 0);
329
editor.navigateRight();
330
editor.insert(defaultReg.text);
331
editor.navigateLeft();
333
editor.setOverwrite(true);
334
editor.selection.clearSelection();
338
fn: function(editor, range, count, param) {
339
var defaultReg = registers._default;
340
editor.setOverwrite(false);
342
if (defaultReg.isLine) {
343
var pos = editor.getCursorPosition();
344
var lines = defaultReg.text.split("\n");
345
editor.session.getDocument().insertLines(pos.row, lines);
346
editor.moveCursorTo(pos.row, 0);
349
editor.insert(defaultReg.text);
351
editor.setOverwrite(true);
352
editor.selection.clearSelection();
356
fn: function(editor, range, count, param) {
357
var session = editor.session;
358
range = editor.getSelectionRange();
359
var pos = {row: range.start.row, column: range.start.column};
360
count = count || range.end.row - range.start.row;
361
var maxRow = Math.min(pos.row + (count || 1), session.getLength() - 1);
363
range.start.column = session.getLine(pos.row).length;
364
range.end.column = session.getLine(maxRow).length;
365
range.end.row = maxRow;
368
for (var i = pos.row; i < maxRow; i++) {
369
var nextLine = session.getLine(i + 1);
370
text += " " + /^\s*(.*)$/.exec(nextLine)[1] || "";
373
session.replace(range, text);
374
editor.moveCursorTo(pos.row, pos.column);
378
fn: function(editor, range, count, param) {
379
count = parseInt(count || 1, 10);
380
for (var i = 0; i < count; i++) {
383
editor.selection.clearSelection();
387
fn: function(editor, range, count, param) {
388
count = parseInt(count || 1, 10);
389
for (var i = 0; i < count; i++) {
392
editor.selection.clearSelection();
396
fn: function(editor, range, count, param) {
400
fn: function(editor, range, count, param) {
404
fn: function(editor, range, count, param) {
408
fn: function(editor, range, count, param) {
409
util.onInsertReplaySequence = inputBuffer.lastInsertCommands;
410
var previous = inputBuffer.previous;
411
if (previous) // If there is a previous action
412
inputBuffer.exec(editor, previous.action, previous.param);
416
fn: function(editor, range, count, param) {
417
editor.modifyNumber(-(count || 1));
421
fn: function(editor, range, count, param) {
422
editor.modifyNumber(count || 1);
427
var inputBuffer = exports.inputBuffer = {
428
accepting: [NUMBER, OPERATOR, MOTION, ACTION],
435
lastInsertCommands: [],
437
push: function(editor, ch, keyId) {
438
var isKeyHandled = true;
440
var wObj = this.waitingForParam;
442
this.exec(editor, wObj, ch);
444
else if (!(ch === "0" && !this.currentCount.length) &&
445
(ch.match(/^\d+$/) && this.isAccepting(NUMBER))) {
446
this.currentCount += ch;
447
this.currentCmd = NUMBER;
448
this.accepting = [NUMBER, OPERATOR, MOTION, ACTION];
450
else if (!this.operator && this.isAccepting(OPERATOR) && operators[ch]) {
453
count: this.getCount()
455
this.currentCmd = OPERATOR;
456
this.accepting = [NUMBER, MOTION, ACTION];
457
this.exec(editor, { operator: this.operator });
459
else if (motions[ch] && this.isAccepting(MOTION)) {
460
this.currentCmd = MOTION;
463
operator: this.operator,
466
count: this.getCount()
470
if (motions[ch].param)
471
this.waitForParam(ctx);
473
this.exec(editor, ctx);
475
else if (alias[ch] && this.isAccepting(MOTION)) {
476
alias[ch].operator.count = this.getCount();
477
this.exec(editor, alias[ch]);
479
else if (actions[ch] && this.isAccepting(ACTION)) {
483
count: this.getCount()
487
if (actions[ch].param) {
488
this.waitForParam(actionObj);
491
this.exec(editor, actionObj);
494
if (actions[ch].acceptsMotion)
497
else if (this.operator) {
498
this.exec(editor, { operator: this.operator }, ch);
501
isKeyHandled = ch.length == 1;
505
if (this.waitingForParam || this.motion || this.operator) {
507
} else if (this.currentCount) {
508
this.status = this.currentCount;
509
} else if (this.status) {
514
editor._emit("changeStatus");
518
waitForParam: function(cmd) {
519
this.waitingForParam = cmd;
522
getCount: function() {
523
var count = this.currentCount;
524
this.currentCount = "";
525
return count && parseInt(count, 10);
528
exec: function(editor, action, param) {
529
var m = action.motion;
530
var o = action.operator;
531
var a = action.action;
534
param = action.param;
543
if (o && !editor.selection.isEmpty()) {
544
if (operators[o.ch].selFn) {
545
operators[o.ch].selFn(editor, editor.getSelectionRange(), o.count, param);
550
else if (!m && !a && o && param) {
551
operators[o.ch].fn(editor, null, o.count, param);
555
var run = function(fn) {
556
if (fn && typeof fn === "function") { // There should always be a motion
557
if (m.count && !motionObj.handlesCount)
558
repeat(fn, m.count, [editor, null, m.count, param]);
560
fn(editor, null, m.count, param);
564
var motionObj = motions[m.ch];
565
var selectable = motionObj.sel;
568
if ((util.onVisualMode || util.onVisualLineMode) && selectable)
573
else if (selectable) {
576
operators[o.ch].fn(editor, editor.getSelectionRange(), o.count, param);
582
a.fn(editor, editor.getSelectionRange(), a.count, param);
585
handleCursorMove(editor);
588
isAccepting: function(type) {
589
return this.accepting.indexOf(type) !== -1;
593
this.operator = null;
595
this.currentCount = "";
597
this.accepting = [NUMBER, OPERATOR, MOTION, ACTION];
599
this.waitingForParam = null;
603
function setPreviousCommand(fn) {
604
inputBuffer.previous = { action: { action: { fn: fn } } };
607
exports.coreCommands = {
609
exec: function start(editor) {
610
util.insertMode(editor);
611
setPreviousCommand(start);
615
exec: function startBeginning(editor) {
616
editor.navigateLineStart();
617
util.insertMode(editor);
618
setPreviousCommand(startBeginning);
622
exec: function stop(editor) {
624
util.onVisualMode = false;
625
util.onVisualLineMode = false;
626
inputBuffer.lastInsertCommands = util.normalMode(editor);
630
exec: function append(editor) {
631
var pos = editor.getCursorPosition();
632
var lineLen = editor.session.getLine(pos.row).length;
634
editor.navigateRight();
635
util.insertMode(editor);
636
setPreviousCommand(append);
640
exec: function appendEnd(editor) {
641
editor.navigateLineEnd();
642
util.insertMode(editor);
643
setPreviousCommand(appendEnd);
648
var handleCursorMove = exports.onCursorMove = function(editor, e) {
649
if (util.currentMode === 'insert' || handleCursorMove.running)
651
else if(!editor.selection.isEmpty()) {
652
handleCursorMove.running = true;
653
if (util.onVisualLineMode) {
654
var originRow = editor.selection.visualLineStart;
655
var cursorRow = editor.getCursorPosition().row;
656
if(originRow <= cursorRow) {
657
var endLine = editor.session.getLine(cursorRow);
658
editor.selection.clearSelection();
659
editor.selection.moveCursorTo(originRow, 0);
660
editor.selection.selectTo(cursorRow, endLine.length);
662
var endLine = editor.session.getLine(originRow);
663
editor.selection.clearSelection();
664
editor.selection.moveCursorTo(originRow, endLine.length);
665
editor.selection.selectTo(cursorRow, 0);
668
handleCursorMove.running = false;
672
if (e && (util.onVisualLineMode || util.onVisualMode)) {
673
editor.selection.clearSelection();
674
util.normalMode(editor);
677
handleCursorMove.running = true;
678
var pos = editor.getCursorPosition();
679
var lineLen = editor.session.getLine(pos.row).length;
681
if (lineLen && pos.column === lineLen)
682
editor.navigateLeft();
683
handleCursorMove.running = false;
687
define('ace/keyboard/vim/maps/util', ['require', 'exports', 'module' , 'ace/keyboard/vim/registers', 'ace/lib/dom'], function(require, exports, module) {
688
var registers = require("../registers");
690
var dom = require("../../../lib/dom");
691
dom.importCssString('.insert-mode .ace_cursor{\
692
border-left: 2px solid #333333;\
694
.ace_dark.insert-mode .ace_cursor{\
695
border-left: 2px solid #eeeeee;\
697
.normal-mode .ace_cursor{\
698
border: 0!important;\
699
background-color: red;\
705
onVisualLineMode: false,
706
currentMode: 'normal',
707
noMode: function(editor) {
708
editor.unsetStyle('insert-mode');
709
editor.unsetStyle('normal-mode');
710
if (editor.commands.recording)
711
editor.commands.toggleRecording(editor);
712
editor.setOverwrite(false);
714
insertMode: function(editor) {
715
this.currentMode = 'insert';
716
editor.setStyle('insert-mode');
717
editor.unsetStyle('normal-mode');
719
editor.setOverwrite(false);
720
editor.keyBinding.$data.buffer = "";
721
editor.keyBinding.$data.state = "insertMode";
722
this.onVisualMode = false;
723
this.onVisualLineMode = false;
724
if(this.onInsertReplaySequence) {
725
editor.commands.macro = this.onInsertReplaySequence;
726
editor.commands.replay(editor);
727
this.onInsertReplaySequence = null;
728
this.normalMode(editor);
730
editor._emit("changeStatus");
731
if(!editor.commands.recording)
732
editor.commands.toggleRecording(editor);
735
normalMode: function(editor) {
736
this.currentMode = 'normal';
738
editor.unsetStyle('insert-mode');
739
editor.setStyle('normal-mode');
740
editor.clearSelection();
743
if (!editor.getOverwrite()) {
744
pos = editor.getCursorPosition();
746
editor.navigateLeft();
749
editor.setOverwrite(true);
750
editor.keyBinding.$data.buffer = "";
751
editor.keyBinding.$data.state = "start";
752
this.onVisualMode = false;
753
this.onVisualLineMode = false;
754
editor._emit("changeStatus");
755
if (editor.commands.recording) {
756
editor.commands.toggleRecording(editor);
757
return editor.commands.macro;
763
visualMode: function(editor, lineMode) {
765
(this.onVisualLineMode && lineMode)
766
|| (this.onVisualMode && !lineMode)
768
this.normalMode(editor);
772
editor.setStyle('insert-mode');
773
editor.unsetStyle('normal-mode');
775
editor._emit("changeStatus");
777
this.onVisualLineMode = true;
779
this.onVisualMode = true;
780
this.onVisualLineMode = false;
783
getRightNthChar: function(editor, cursor, ch, n) {
784
var line = editor.getSession().getLine(cursor.row);
785
var matches = line.substr(cursor.column + 1).split(ch);
787
return n < matches.length ? matches.slice(0, n).join(ch).length : null;
789
getLeftNthChar: function(editor, cursor, ch, n) {
790
var line = editor.getSession().getLine(cursor.row);
791
var matches = line.substr(0, cursor.column).split(ch);
793
return n < matches.length ? matches.slice(-1 * n).join(ch).length : null;
795
toRealChar: function(ch) {
799
if (/^shift-./.test(ch))
800
return ch[ch.length - 1].toUpperCase();
804
copyLine: function(editor) {
805
var pos = editor.getCursorPosition();
806
editor.selection.clearSelection();
807
editor.moveCursorTo(pos.row, pos.column);
808
editor.selection.selectLine();
809
registers._default.isLine = true;
810
registers._default.text = editor.getCopyText().replace(/\n$/, "");
811
editor.selection.clearSelection();
812
editor.moveCursorTo(pos.row, pos.column);
817
define('ace/keyboard/vim/registers', ['require', 'exports', 'module' ], function(require, exports, module) {
831
define('ace/keyboard/vim/maps/motions', ['require', 'exports', 'module' , 'ace/keyboard/vim/maps/util', 'ace/search', 'ace/range'], function(require, exports, module) {
834
var util = require("./util");
836
var keepScrollPosition = function(editor, fn) {
837
var scrollTopRow = editor.renderer.getScrollTopRow();
838
var initialRow = editor.getCursorPosition().row;
839
var diff = initialRow - scrollTopRow;
840
fn && fn.call(editor);
841
editor.renderer.scrollToRow(editor.getCursorPosition().row - diff);
845
if (typeof m == "function") {
849
var getPos = m.getPos;
851
m.nav = function(editor, range, count, param) {
852
var a = getPos(editor, range, count, param, false);
855
editor.clearSelection();
856
editor.moveCursorTo(a.row, a.column);
858
m.sel = function(editor, range, count, param) {
859
var a = getPos(editor, range, count, param, true);
862
editor.selection.selectTo(a.row, a.column);
867
var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
868
var wordSeparatorRe = /[.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
870
var StringStream = function(editor, cursor) {
871
var sel = editor.selection;
872
this.range = sel.getRange();
873
cursor = cursor || sel.selectionLead;
874
this.row = cursor.row;
875
this.col = cursor.column;
876
var line = editor.session.getLine(this.row);
877
var maxRow = editor.session.getLength();
878
this.ch = line[this.col] || '\n';
879
this.skippedLines = 0;
881
this.next = function() {
882
this.ch = line[++this.col] || this.handleNewLine(1);
885
this.prev = function() {
886
this.ch = line[--this.col] || this.handleNewLine(-1);
889
this.peek = function(dir) {
890
var ch = line[this.col + dir];
895
if (this.col == line.length - 1)
897
return editor.session.getLine(this.row + 1)[0] || '\n';
900
this.handleNewLine = function(dir) {
902
if (this.col == line.length)
904
if (this.row == maxRow - 1)
908
line = editor.session.getLine(this.row);
910
return line[0] || '\n';
916
line = editor.session.getLine(this.row);
917
this.col = line.length;
922
this.debug = function() {
923
console.log(line.substring(0, this.col)+'|'+this.ch+'\''+this.col+'\''+line.substr(this.col+1));
927
var Search = require("../../../search").Search;
928
var search = new Search();
930
function find(editor, needle, dir) {
931
search.$options.needle = needle;
932
search.$options.backwards = dir == -1;
933
return search.find(editor.session);
936
var Range = require("../../../range").Range;
939
"w": new Motion(function(editor) {
940
var str = new StringStream(editor);
942
if (str.ch && wordSeparatorRe.test(str.ch)) {
943
while (str.ch && wordSeparatorRe.test(str.ch))
946
while (str.ch && !nonWordRe.test(str.ch))
949
while (str.ch && whiteRe.test(str.ch) && str.skippedLines < 2)
952
str.skippedLines == 2 && str.prev();
953
return {column: str.col, row: str.row};
955
"W": new Motion(function(editor) {
956
var str = new StringStream(editor);
957
while(str.ch && !(whiteRe.test(str.ch) && !whiteRe.test(str.peek(1))) && str.skippedLines < 2)
959
if (str.skippedLines == 2)
964
return {column: str.col, row: str.row};
966
"b": new Motion(function(editor) {
967
var str = new StringStream(editor);
970
while (str.ch && whiteRe.test(str.ch) && str.skippedLines > -2)
973
if (str.ch && wordSeparatorRe.test(str.ch)) {
974
while (str.ch && wordSeparatorRe.test(str.ch))
977
while (str.ch && !nonWordRe.test(str.ch))
980
str.ch && str.next();
981
return {column: str.col, row: str.row};
983
"B": new Motion(function(editor) {
984
var str = new StringStream(editor);
986
while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(-1))) && str.skippedLines > -2)
989
if (str.skippedLines == -2)
992
return {column: str.col, row: str.row};
994
"e": new Motion(function(editor) {
995
var str = new StringStream(editor);
998
while (str.ch && whiteRe.test(str.ch))
1001
if (str.ch && wordSeparatorRe.test(str.ch)) {
1002
while (str.ch && wordSeparatorRe.test(str.ch))
1005
while (str.ch && !nonWordRe.test(str.ch))
1008
str.ch && str.prev();
1009
return {column: str.col, row: str.row};
1011
"E": new Motion(function(editor) {
1012
var str = new StringStream(editor);
1014
while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(1))))
1017
return {column: str.col, row: str.row};
1021
nav: function(editor) {
1022
var pos = editor.getCursorPosition();
1023
var col = pos.column;
1024
var lineLen = editor.session.getLine(pos.row).length;
1025
if (lineLen && col !== lineLen)
1026
editor.navigateRight();
1028
sel: function(editor) {
1029
var pos = editor.getCursorPosition();
1030
var col = pos.column;
1031
var lineLen = editor.session.getLine(pos.row).length;
1032
if (lineLen && col !== lineLen) //In selection mode you can select the newline
1033
editor.selection.selectRight();
1037
nav: function(editor) {
1038
var pos = editor.getCursorPosition();
1040
editor.navigateLeft();
1042
sel: function(editor) {
1043
var pos = editor.getCursorPosition();
1045
editor.selection.selectLeft();
1049
nav: function(editor) {
1050
var row = editor.renderer.getScrollTopRow();
1051
editor.moveCursorTo(row);
1053
sel: function(editor) {
1054
var row = editor.renderer.getScrollTopRow();
1055
editor.selection.selectTo(row);
1059
nav: function(editor) {
1060
var topRow = editor.renderer.getScrollTopRow();
1061
var bottomRow = editor.renderer.getScrollBottomRow();
1062
var row = topRow + ((bottomRow - topRow) / 2);
1063
editor.moveCursorTo(row);
1065
sel: function(editor) {
1066
var topRow = editor.renderer.getScrollTopRow();
1067
var bottomRow = editor.renderer.getScrollBottomRow();
1068
var row = topRow + ((bottomRow - topRow) / 2);
1069
editor.selection.selectTo(row);
1073
nav: function(editor) {
1074
var row = editor.renderer.getScrollBottomRow();
1075
editor.moveCursorTo(row);
1077
sel: function(editor) {
1078
var row = editor.renderer.getScrollBottomRow();
1079
editor.selection.selectTo(row);
1083
nav: function(editor) {
1084
editor.navigateUp();
1086
sel: function(editor) {
1087
editor.selection.selectUp();
1091
nav: function(editor) {
1092
editor.navigateDown();
1094
sel: function(editor) {
1095
editor.selection.selectDown();
1101
sel: function(editor, range, count, param) {
1104
editor.selection.selectWord();
1107
editor.selection.selectAWord();
1112
var cursor = editor.getCursorPosition();
1113
var end = editor.session.$findClosingBracket(param, cursor, /paren/);
1116
var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/);
1120
editor.selection.setSelectionRange(Range.fromPoints(start, end));
1125
var end = find(editor, param, 1);
1128
var start = find(editor, param, -1);
1131
editor.selection.setSelectionRange(Range.fromPoints(start.end, end.start));
1138
sel: function(editor, range, count, param) {
1141
editor.selection.selectAWord();
1144
editor.selection.selectAWord();
1149
var cursor = editor.getCursorPosition();
1150
var end = editor.session.$findClosingBracket(param, cursor, /paren/);
1153
var start = editor.session.$findOpeningBracket(editor.session.$brackets[param], cursor, /paren/);
1157
editor.selection.setSelectionRange(Range.fromPoints(start, end));
1162
var end = find(editor, param, 1);
1165
var start = find(editor, param, -1);
1169
editor.selection.setSelectionRange(Range.fromPoints(start.start, end.end));
1178
getPos: function(editor, range, count, param, isSel) {
1179
var cursor = editor.getCursorPosition();
1180
var column = util.getRightNthChar(editor, cursor, param, count || 1);
1182
if (typeof column === "number") {
1183
cursor.column += column + (isSel ? 2 : 1);
1191
getPos: function(editor, range, count, param, isSel) {
1192
var cursor = editor.getCursorPosition();
1193
var column = util.getLeftNthChar(editor, cursor, param, count || 1);
1195
if (typeof column === "number") {
1196
cursor.column -= column + 1;
1204
getPos: function(editor, range, count, param, isSel) {
1205
var cursor = editor.getCursorPosition();
1206
var column = util.getRightNthChar(editor, cursor, param, count || 1);
1208
if (typeof column === "number") {
1209
cursor.column += column + (isSel ? 1 : 0);
1217
getPos: function(editor, range, count, param, isSel) {
1218
var cursor = editor.getCursorPosition();
1219
var column = util.getLeftNthChar(editor, cursor, param, count || 1);
1221
if (typeof column === "number") {
1222
cursor.column -= column;
1229
nav: function(editor) {
1230
editor.navigateLineStart();
1232
sel: function(editor) {
1233
editor.selection.selectLineStart();
1237
nav: function(editor) {
1238
editor.navigateLineEnd();
1240
sel: function(editor) {
1241
editor.selection.selectLineEnd();
1244
"0": new Motion(function(ed) {
1245
return {row: ed.selection.lead.row, column: 0};
1248
nav: function(editor, range, count, param) {
1249
if (!count && count !== 0) { // Stupid JS
1250
count = editor.session.getLength();
1252
editor.gotoLine(count);
1254
sel: function(editor, range, count, param) {
1255
if (!count && count !== 0) { // Stupid JS
1256
count = editor.session.getLength();
1258
editor.selection.selectTo(count, 0);
1263
nav: function(editor, range, count, param) {
1266
console.log("Middle line");
1269
console.log("End of prev word");
1272
editor.gotoLine(count || 0);
1274
editor.gotoLine(count || 0);
1276
editor.gotoLine(count || 0);
1279
sel: function(editor, range, count, param) {
1282
console.log("Middle line");
1285
console.log("End of prev word");
1288
editor.selection.selectTo(count || 0, 0);
1293
nav: function(editor, range, count, param) {
1299
if (content.length) {
1300
editor.navigateLineEnd()
1301
editor.insert(content);
1302
util.insertMode(editor);
1307
nav: function(editor, range, count, param) {
1308
var row = editor.getCursorPosition().row;
1314
if (content.length) {
1316
editor.navigateUp();
1317
editor.navigateLineEnd()
1318
editor.insert(content);
1320
editor.session.insert({row: 0, column: 0}, content);
1321
editor.navigateUp();
1323
util.insertMode(editor);
1327
"%": new Motion(function(editor){
1328
var brRe = /[\[\]{}()]/g;
1329
var cursor = editor.getCursorPosition();
1330
var ch = editor.session.getLine(cursor.row)[cursor.column];
1331
if (!brRe.test(ch)) {
1332
var range = find(editor, brRe);
1335
cursor = range.start;
1337
var match = editor.session.findMatchingBracket({
1339
column: cursor.column + 1
1344
"{": new Motion(function(ed) {
1345
var session = ed.session;
1346
var row = session.selection.lead.row;
1347
while(row > 0 && !/\S/.test(session.getLine(row)))
1349
while(/\S/.test(session.getLine(row)))
1351
return {column: 0, row: row};
1353
"}": new Motion(function(ed) {
1354
var session = ed.session;
1355
var l = session.getLength();
1356
var row = session.selection.lead.row;
1357
while(row < l && !/\S/.test(session.getLine(row)))
1359
while(/\S/.test(session.getLine(row)))
1361
return {column: 0, row: row};
1364
nav: function(editor, range, count, param) {
1365
editor.selection.clearSelection();
1366
keepScrollPosition(editor, editor.gotoPageDown);
1368
sel: function(editor, range, count, param) {
1369
keepScrollPosition(editor, editor.selectPageDown);
1373
nav: function(editor, range, count, param) {
1374
editor.selection.clearSelection();
1375
keepScrollPosition(editor, editor.gotoPageUp);
1377
sel: function(editor, range, count, param) {
1378
keepScrollPosition(editor, editor.selectPageUp);
1384
getPos: function(editor, range, count, param, isSel) {
1385
var s = editor.session;
1386
var marker = s.vimMarkers && s.vimMarkers[param];
1388
return marker.getPosition();
1395
getPos: function(editor, range, count, param, isSel) {
1396
var s = editor.session;
1397
var marker = s.vimMarkers && s.vimMarkers[param];
1399
var pos = marker.getPosition();
1400
var line = editor.session.getLine(pos.row);
1401
pos.column = line.search(/\S/);
1402
if (pos.column == -1)
1403
pos.column = line.length;
1410
module.exports.backspace = module.exports.left = module.exports.h;
1411
module.exports.right = module.exports.l;
1412
module.exports.up = module.exports.k;
1413
module.exports.down = module.exports.j;
1414
module.exports.pagedown = module.exports["ctrl-d"];
1415
module.exports.pageup = module.exports["ctrl-u"];
1419
define('ace/keyboard/vim/maps/operators', ['require', 'exports', 'module' , 'ace/keyboard/vim/maps/util', 'ace/keyboard/vim/registers'], function(require, exports, module) {
1423
var util = require("./util");
1424
var registers = require("../registers");
1428
selFn: function(editor, range, count, param) {
1429
registers._default.text = editor.getCopyText();
1430
registers._default.isLine = util.onVisualLineMode;
1431
if(util.onVisualLineMode)
1432
editor.removeLines();
1434
editor.session.remove(range);
1435
util.normalMode(editor);
1437
fn: function(editor, range, count, param) {
1441
registers._default.text = "";
1442
registers._default.isLine = true;
1443
for (var i = 0; i < count; i++) {
1444
editor.selection.selectLine();
1445
registers._default.text += editor.getCopyText();
1446
var selRange = editor.getSelectionRange();
1447
if (!selRange.isMultiLine()) {
1448
lastLineReached = true
1449
var row = selRange.start.row - 1;
1450
var col = editor.session.getLine(row).length
1451
selRange.setStart(row, col);
1452
editor.session.remove(selRange);
1453
editor.selection.clearSelection();
1456
editor.session.remove(selRange);
1457
editor.selection.clearSelection();
1459
registers._default.text = registers._default.text.replace(/\n$/, "");
1463
editor.selection.setSelectionRange(range);
1464
registers._default.text = editor.getCopyText();
1465
registers._default.isLine = false;
1466
editor.session.remove(range);
1467
editor.selection.clearSelection();
1473
selFn: function(editor, range, count, param) {
1474
editor.session.remove(range);
1475
util.insertMode(editor);
1477
fn: function(editor, range, count, param) {
1481
for (var i = 0; i < count; i++) {
1482
editor.removeLines();
1483
util.insertMode(editor);
1489
editor.session.remove(range);
1490
util.insertMode(editor);
1496
selFn: function(editor, range, count, param) {
1497
registers._default.text = editor.getCopyText();
1498
registers._default.isLine = util.onVisualLineMode;
1499
editor.selection.clearSelection();
1500
util.normalMode(editor);
1502
fn: function(editor, range, count, param) {
1506
var pos = editor.getCursorPosition();
1507
editor.selection.selectLine();
1508
for (var i = 0; i < count - 1; i++) {
1509
editor.selection.moveCursorDown();
1511
registers._default.text = editor.getCopyText().replace(/\n$/, "");
1512
editor.selection.clearSelection();
1513
registers._default.isLine = true;
1514
editor.moveCursorToPosition(pos);
1518
var pos = editor.getCursorPosition();
1519
editor.selection.setSelectionRange(range);
1520
registers._default.text = editor.getCopyText();
1521
registers._default.isLine = false;
1522
editor.selection.clearSelection();
1523
editor.moveCursorTo(pos.row, pos.column);
1529
selFn: function(editor, range, count, param) {
1531
for (var i = 0; i < count; i++) {
1534
util.normalMode(editor);
1536
fn: function(editor, range, count, param) {
1537
count = parseInt(count || 1, 10);
1540
var pos = editor.getCursorPosition();
1541
editor.selection.selectLine();
1542
for (var i = 0; i < count - 1; i++) {
1543
editor.selection.moveCursorDown();
1546
editor.selection.clearSelection();
1547
editor.moveCursorToPosition(pos);
1548
editor.navigateLineEnd();
1549
editor.navigateLineStart();
1555
selFn: function(editor, range, count, param) {
1557
for (var i = 0; i < count; i++) {
1558
editor.blockOutdent();
1560
util.normalMode(editor);
1562
fn: function(editor, range, count, param) {
1566
var pos = editor.getCursorPosition();
1567
editor.selection.selectLine();
1568
for (var i = 0; i < count - 1; i++) {
1569
editor.selection.moveCursorDown();
1571
editor.blockOutdent();
1572
editor.selection.clearSelection();
1573
editor.moveCursorToPosition(pos);
1574
editor.navigateLineEnd();
1575
editor.navigateLineStart();
1585
define('ace/keyboard/vim/maps/aliases', ['require', 'exports', 'module' ], function(require, exports, module) {