commit
35155075e0
18 changed files with 9777 additions and 2468 deletions
|
|
@ -969,10 +969,8 @@ var EditSession = function(text, mode) {
|
||||||
try {
|
try {
|
||||||
this.$worker = this.$mode.createWorker(this);
|
this.$worker = this.$mode.createWorker(this);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof console == "object") {
|
if (typeof console == "object" && console.error)
|
||||||
console.log("Could not load worker");
|
console.log("Could not load worker", e);
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
this.$worker = null;
|
this.$worker = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ var Editor = function(renderer, session) {
|
||||||
if (this.curOp) {
|
if (this.curOp) {
|
||||||
if (e && e.returnValue === false)
|
if (e && e.returnValue === false)
|
||||||
return this.curOp = null;
|
return this.curOp = null;
|
||||||
|
this._signal("beforeEndOperation");
|
||||||
var command = this.curOp.command;
|
var command = this.curOp.command;
|
||||||
if (command && command.scrollIntoView) {
|
if (command && command.scrollIntoView) {
|
||||||
switch (command.scrollIntoView) {
|
switch (command.scrollIntoView) {
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,618 +0,0 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Distributed under the BSD license:
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
define(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) {
|
|
||||||
//editor.selection.selectLine();
|
|
||||||
//editor.selection.selectLeft();
|
|
||||||
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,
|
|
||||||
//currentMode: 0,
|
|
||||||
currentCount: "",
|
|
||||||
pendingCount: "",
|
|
||||||
status: "",
|
|
||||||
|
|
||||||
// Types
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
// If input is a number (that doesn't start with 0)
|
|
||||||
else if (!(ch === "0" && !this.currentCount.length) &&
|
|
||||||
(/^\d+$/.test(ch) && this.isAccepting(NUMBER))) {
|
|
||||||
// Assuming that ch is always of type String, and not 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// There is an operator, but no motion or action. We try to pass the
|
|
||||||
// current ch to the operator to see if it responds to it (an example
|
|
||||||
// of this is the 'dd' operator).
|
|
||||||
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 Insert mode as soon as possible. Works like typing <Esc> in
|
|
||||||
// insert mode.
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Distributed under the BSD license:
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
"use strict"
|
|
||||||
|
|
||||||
define(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"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
@ -1,681 +0,0 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Distributed under the BSD license:
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
|
|
||||||
define(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);
|
|
||||||
//this.debug()
|
|
||||||
return this.ch;
|
|
||||||
};
|
|
||||||
this.prev = function() {
|
|
||||||
this.ch = line[--this.col] || this.handleNewLine(-1);
|
|
||||||
//this.debug()
|
|
||||||
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;
|
|
||||||
|
|
||||||
// Solving the behavior at the end of the line due to the
|
|
||||||
// different 0 index-based colum positions in ACE.
|
|
||||||
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))
|
|
||||||
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))
|
|
||||||
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["$"];
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
@ -1,201 +0,0 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Distributed under the BSD license:
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
define(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();
|
|
||||||
// check if end of the document was reached
|
|
||||||
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) {
|
|
||||||
// range.end.column ++;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
@ -1,132 +0,0 @@
|
||||||
define(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';
|
|
||||||
// Switch editor to insert mode
|
|
||||||
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) {
|
|
||||||
// Ok, we're apparently replaying ("."), so let's do it
|
|
||||||
editor.commands.macro = this.onInsertReplaySequence;
|
|
||||||
editor.commands.replay(editor);
|
|
||||||
this.onInsertReplaySequence = null;
|
|
||||||
this.normalMode(editor);
|
|
||||||
} else {
|
|
||||||
editor._emit("changeStatus");
|
|
||||||
// Record any movements, insertions in insert mode
|
|
||||||
if(!editor.commands.recording)
|
|
||||||
editor.commands.toggleRecording(editor);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
normalMode: function(editor) {
|
|
||||||
// Switch editor to normal mode
|
|
||||||
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");
|
|
||||||
// Save recorded keystrokes
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
|
||||||
* Distributed under the BSD license:
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Ajax.org B.V.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
|
||||||
* documentation and/or other materials provided with the distribution.
|
|
||||||
* * Neither the name of Ajax.org B.V. nor the
|
|
||||||
* names of its contributors may be used to endorse or promote products
|
|
||||||
* derived from this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* ***** END LICENSE BLOCK ***** */
|
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
|
||||||
|
|
||||||
"never use strict";
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
_default: {
|
|
||||||
text: "",
|
|
||||||
isLine: false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
});
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -196,10 +196,14 @@ var Cursor = function(parentEl) {
|
||||||
|
|
||||||
var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
|
var style = (this.cursors[cursorIndex++] || this.addCursor()).style;
|
||||||
|
|
||||||
|
if (!this.drawCursor) {
|
||||||
style.left = pixelPos.left + "px";
|
style.left = pixelPos.left + "px";
|
||||||
style.top = pixelPos.top + "px";
|
style.top = pixelPos.top + "px";
|
||||||
style.width = config.characterWidth + "px";
|
style.width = config.characterWidth + "px";
|
||||||
style.height = config.lineHeight + "px";
|
style.height = config.lineHeight + "px";
|
||||||
|
} else {
|
||||||
|
this.drawCursor(style, pixelPos, config, selections[i], this.session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (this.cursors.length > cursorIndex)
|
while (this.cursors.length > cursorIndex)
|
||||||
this.removeCursor();
|
this.removeCursor();
|
||||||
|
|
@ -212,6 +216,8 @@ var Cursor = function(parentEl) {
|
||||||
this.restartTimer();
|
this.restartTimer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.drawCursor = null;
|
||||||
|
|
||||||
this.$setOverwrite = function(overwrite) {
|
this.$setOverwrite = function(overwrite) {
|
||||||
if (overwrite != this.overwrite) {
|
if (overwrite != this.overwrite) {
|
||||||
this.overwrite = overwrite;
|
this.overwrite = overwrite;
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,6 @@ var testRanges = function(str) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
name: "ACE multi_select.js",
|
|
||||||
|
|
||||||
"test: cstyle": function() {
|
"test: cstyle": function() {
|
||||||
function testValue(line) {
|
function testValue(line) {
|
||||||
assert.equal(editor.getValue(), Array(4).join(line + "\n"));
|
assert.equal(editor.getValue(), Array(4).join(line + "\n"));
|
||||||
|
|
|
||||||
|
|
@ -552,7 +552,8 @@ var Editor = require("./editor").Editor;
|
||||||
var pos = anchor == this.multiSelect.anchor
|
var pos = anchor == this.multiSelect.anchor
|
||||||
? range.cursor == range.start ? range.end : range.start
|
? range.cursor == range.start ? range.end : range.start
|
||||||
: range.cursor;
|
: range.cursor;
|
||||||
if (!isSamePoint(pos, anchor))
|
if (pos.row != anchor.row
|
||||||
|
|| this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column)
|
||||||
this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
|
this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ var assert = require("./test/assertions");
|
||||||
var JavaScriptMode = require("./mode/javascript").Mode;
|
var JavaScriptMode = require("./mode/javascript").Mode;
|
||||||
var PlaceHolder = require("./placeholder").PlaceHolder;
|
var PlaceHolder = require("./placeholder").PlaceHolder;
|
||||||
var UndoManager = require("./undomanager").UndoManager;
|
var UndoManager = require("./undomanager").UndoManager;
|
||||||
|
require("./multi_select")
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
|
|
@ -89,7 +90,7 @@ module.exports = {
|
||||||
editor.insert('v');
|
editor.insert('v');
|
||||||
assert.equal(session.doc.getValue(), "var v$a = 10;\nconsole.log(v$a, v$a);");
|
assert.equal(session.doc.getValue(), "var v$a = 10;\nconsole.log(v$a, v$a);");
|
||||||
next();
|
next();
|
||||||
}, 10);
|
}, 20);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: detaching placeholder" : function() {
|
"test: detaching placeholder" : function() {
|
||||||
|
|
|
||||||
|
|
@ -102,8 +102,8 @@ var Search = function() {
|
||||||
* @returns {Range}
|
* @returns {Range}
|
||||||
**/
|
**/
|
||||||
this.find = function(session) {
|
this.find = function(session) {
|
||||||
var iterator = this.$matchIterator(session, this.$options);
|
var options = this.$options;
|
||||||
|
var iterator = this.$matchIterator(session, options);
|
||||||
if (!iterator)
|
if (!iterator)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -112,6 +112,12 @@ var Search = function() {
|
||||||
if (!range.start) {
|
if (!range.start) {
|
||||||
var column = range.offset + (offset || 0);
|
var column = range.offset + (offset || 0);
|
||||||
firstRange = new Range(row, column, row, column + range.length);
|
firstRange = new Range(row, column, row, column + range.length);
|
||||||
|
if (!range.length && options.start && options.start.start
|
||||||
|
&& options.skipCurrent != false && firstRange.isEqual(options.start)
|
||||||
|
) {
|
||||||
|
firstRange = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
firstRange = range;
|
firstRange = range;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -240,8 +246,7 @@ var Search = function() {
|
||||||
if (!re)
|
if (!re)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var self = this, callback, backwards = options.backwards;
|
var callback;
|
||||||
|
|
||||||
if (options.$isMultiLine) {
|
if (options.$isMultiLine) {
|
||||||
var len = re.length;
|
var len = re.length;
|
||||||
var matchIterator = function(line, row, offset) {
|
var matchIterator = function(line, row, offset) {
|
||||||
|
|
@ -266,7 +271,7 @@ var Search = function() {
|
||||||
if (callback(range))
|
if (callback(range))
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
} else if (backwards) {
|
} else if (options.backwards) {
|
||||||
var matchIterator = function(line, row, startIndex) {
|
var matchIterator = function(line, row, startIndex) {
|
||||||
var matches = lang.getMatchOffsets(line, re);
|
var matches = lang.getMatchOffsets(line, re);
|
||||||
for (var i = matches.length-1; i >= 0; i--)
|
for (var i = matches.length-1; i >= 0; i--)
|
||||||
|
|
@ -282,10 +287,12 @@ var Search = function() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lineIterator = this.$lineIterator(session, options);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
forEach: function(_callback) {
|
forEach: function(_callback) {
|
||||||
callback = _callback;
|
callback = _callback;
|
||||||
self.$lineIterator(session, options).forEach(matchIterator);
|
lineIterator.forEach(matchIterator);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var EditSession = require("./edit_session").EditSession;
|
var EditSession = require("./edit_session").EditSession;
|
||||||
|
var MockRenderer = require("./test/mockrenderer").MockRenderer;
|
||||||
|
var Editor = require("./editor").Editor;
|
||||||
var Search = require("./search").Search;
|
var Search = require("./search").Search;
|
||||||
var assert = require("./test/assertions");
|
var assert = require("./test/assertions");
|
||||||
|
|
||||||
|
|
@ -451,6 +453,37 @@ module.exports = {
|
||||||
assert.position(ranges[1].end, 0, 11);
|
assert.position(ranges[1].end, 0, 11);
|
||||||
assert.position(ranges[0].start, 0, 0);
|
assert.position(ranges[0].start, 0, 0);
|
||||||
assert.position(ranges[0].end, 0, 3);
|
assert.position(ranges[0].end, 0, 3);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: find next empty range" : function() {
|
||||||
|
var session = new EditSession("foo foobar foo");
|
||||||
|
var editor = new Editor(new MockRenderer(), session);
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
needle: "o*",
|
||||||
|
wrap: true,
|
||||||
|
regExp: true,
|
||||||
|
backwards: false
|
||||||
|
};
|
||||||
|
var positions = [4, 5.2, 7, 8, 9, 10, 11, 12.2, 14, 0, 1.2, 3];
|
||||||
|
|
||||||
|
session.selection.moveCursorTo(0, 3);
|
||||||
|
for (var i = 0; i < 12; i++) {
|
||||||
|
editor.find(options)
|
||||||
|
var range = editor.selection.getRange();
|
||||||
|
var start = range.start.column;
|
||||||
|
var len = range.end.column - start;
|
||||||
|
assert.equal(start + 0.1 * len, positions[i])
|
||||||
|
}
|
||||||
|
options.backwards = true;
|
||||||
|
positions = [1.2, 1, 0, 14, 12.2, 12, 11, 10, 9, 8, 7, 5.2, 5, 4, 3];
|
||||||
|
for (var i = 0; i < 16; i++) {
|
||||||
|
editor.find(options);
|
||||||
|
var range = editor.selection.getRange();
|
||||||
|
var start = range.start.column;
|
||||||
|
var len = range.end.column - start;
|
||||||
|
console.log(start + 0.1 * len)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ var testNames = [
|
||||||
"ace/multi_select_test",
|
"ace/multi_select_test",
|
||||||
"ace/mouse/mouse_handler_test",
|
"ace/mouse/mouse_handler_test",
|
||||||
"ace/occur_test",
|
"ace/occur_test",
|
||||||
|
"ace/placeholder_test",
|
||||||
"ace/range_test",
|
"ace/range_test",
|
||||||
"ace/range_list_test",
|
"ace/range_list_test",
|
||||||
"ace/search_test",
|
"ace/search_test",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
var https = require("https")
|
var https = require("https");
|
||||||
, http = require("http")
|
var http = require("http");
|
||||||
, url = require("url")
|
var url = require("url");
|
||||||
, fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
var Path = require("path");
|
var Path = require("path");
|
||||||
var spawn = require("child_process").spawn;
|
var spawn = require("child_process").spawn;
|
||||||
|
|
@ -119,6 +119,22 @@ var deps = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
vim: {
|
||||||
|
fetch: function(){
|
||||||
|
var rootHref = "https://raw.githubusercontent.com/codemirror/CodeMirror/master/"
|
||||||
|
var fileMap = {"keymap/vim.js": "keyboard/vim.js", "test/vim_test.js": "keyboard/vim_test.js"};
|
||||||
|
async.forEach(Object.keys(fileMap), function(x, next) {
|
||||||
|
download(rootHref + x, function(e, d) {
|
||||||
|
d = d.replace(/^\(function.*{[^{}]+^}[^{}]+{/m, "define(function(require, exports, module) {");
|
||||||
|
d = d.replace(/^\s*return vimApi;\s*};/gm, " //};")
|
||||||
|
.replace("var Vim = function() {", "$& return vimApi; } //{")
|
||||||
|
fs.writeFile(rootDir + fileMap[x], d, next)
|
||||||
|
})
|
||||||
|
}, function() {
|
||||||
|
console.log("done")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
coffee: {
|
coffee: {
|
||||||
fetch: function(){
|
fetch: function(){
|
||||||
var rootHref = "https://raw.github.com/jashkenas/coffee-script/master/";
|
var rootHref = "https://raw.github.com/jashkenas/coffee-script/master/";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue