commit
7877ff5e44
1 changed files with 63 additions and 118 deletions
|
|
@ -28,9 +28,9 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
"use strict"
|
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var util = require("./util");
|
var util = require("./util");
|
||||||
|
|
||||||
|
|
@ -42,42 +42,27 @@ var keepScrollPosition = function(editor, fn) {
|
||||||
editor.renderer.scrollToRow(editor.getCursorPosition().row - diff);
|
editor.renderer.scrollToRow(editor.getCursorPosition().row - diff);
|
||||||
};
|
};
|
||||||
|
|
||||||
function Motion(getRange, type){
|
function Motion(m) {
|
||||||
if (type == 'extend')
|
if (typeof m == "function") {
|
||||||
var extend = true;
|
var getPos = m;
|
||||||
else
|
m = this;
|
||||||
var reverse = type;
|
} else {
|
||||||
|
var getPos = m.getPos;
|
||||||
this.nav = function(editor) {
|
}
|
||||||
var r = getRange(editor);
|
m.nav = function(editor, range, count, param) {
|
||||||
if (!r)
|
var a = getPos(editor, range, count, param, false);
|
||||||
|
if (!a)
|
||||||
return;
|
return;
|
||||||
if (!r.end)
|
|
||||||
var a = r;
|
|
||||||
else if (reverse)
|
|
||||||
var a = r.start;
|
|
||||||
else
|
|
||||||
var a = r.end;
|
|
||||||
|
|
||||||
editor.clearSelection();
|
editor.clearSelection();
|
||||||
editor.moveCursorTo(a.row, a.column);
|
editor.moveCursorTo(a.row, a.column);
|
||||||
}
|
};
|
||||||
this.sel = function(editor){
|
m.sel = function(editor, range, count, param) {
|
||||||
var r = getRange(editor);
|
var a = getPos(editor, range, count, param, true);
|
||||||
if (!r)
|
if (!a)
|
||||||
return;
|
return;
|
||||||
if (extend)
|
|
||||||
return editor.selection.setSelectionRange(r);
|
|
||||||
|
|
||||||
if (!r.end)
|
|
||||||
var a = r;
|
|
||||||
else if (reverse)
|
|
||||||
var a = r.start;
|
|
||||||
else
|
|
||||||
var a = r.end;
|
|
||||||
|
|
||||||
editor.selection.selectTo(a.row, a.column);
|
editor.selection.selectTo(a.row, a.column);
|
||||||
}
|
};
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
|
var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
|
||||||
|
|
@ -90,20 +75,20 @@ var StringStream = function(editor, cursor) {
|
||||||
this.row = cursor.row;
|
this.row = cursor.row;
|
||||||
this.col = cursor.column;
|
this.col = cursor.column;
|
||||||
var line = editor.session.getLine(this.row);
|
var line = editor.session.getLine(this.row);
|
||||||
var maxRow = editor.session.getLength()
|
var maxRow = editor.session.getLength();
|
||||||
this.ch = line[this.col] || '\n'
|
this.ch = line[this.col] || '\n';
|
||||||
this.skippedLines = 0;
|
this.skippedLines = 0;
|
||||||
|
|
||||||
this.next = function() {
|
this.next = function() {
|
||||||
this.ch = line[++this.col] || this.handleNewLine(1);
|
this.ch = line[++this.col] || this.handleNewLine(1);
|
||||||
//this.debug()
|
//this.debug()
|
||||||
return this.ch;
|
return this.ch;
|
||||||
}
|
};
|
||||||
this.prev = function() {
|
this.prev = function() {
|
||||||
this.ch = line[--this.col] || this.handleNewLine(-1);
|
this.ch = line[--this.col] || this.handleNewLine(-1);
|
||||||
//this.debug()
|
//this.debug()
|
||||||
return this.ch;
|
return this.ch;
|
||||||
}
|
};
|
||||||
this.peek = function(dir) {
|
this.peek = function(dir) {
|
||||||
var ch = line[this.col + dir];
|
var ch = line[this.col + dir];
|
||||||
if (ch)
|
if (ch)
|
||||||
|
|
@ -113,7 +98,7 @@ var StringStream = function(editor, cursor) {
|
||||||
if (this.col == line.length - 1)
|
if (this.col == line.length - 1)
|
||||||
return '\n';
|
return '\n';
|
||||||
return editor.session.getLine(this.row + 1)[0] || '\n';
|
return editor.session.getLine(this.row + 1)[0] || '\n';
|
||||||
}
|
};
|
||||||
|
|
||||||
this.handleNewLine = function(dir) {
|
this.handleNewLine = function(dir) {
|
||||||
if (dir == 1){
|
if (dir == 1){
|
||||||
|
|
@ -128,7 +113,7 @@ var StringStream = function(editor, cursor) {
|
||||||
return line[0] || '\n';
|
return line[0] || '\n';
|
||||||
}
|
}
|
||||||
if (dir == -1) {
|
if (dir == -1) {
|
||||||
if (this.row == 0)
|
if (this.row === 0)
|
||||||
return '';
|
return '';
|
||||||
this.row --;
|
this.row --;
|
||||||
line = editor.session.getLine(this.row);
|
line = editor.session.getLine(this.row);
|
||||||
|
|
@ -136,11 +121,11 @@ var StringStream = function(editor, cursor) {
|
||||||
this.skippedLines--;
|
this.skippedLines--;
|
||||||
return '\n';
|
return '\n';
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
this.debug = function() {
|
this.debug = function() {
|
||||||
console.log(line.substring(0, this.col)+'|'+this.ch+'\''+this.col+'\''+line.substr(this.col+1));
|
console.log(line.substring(0, this.col)+'|'+this.ch+'\''+this.col+'\''+line.substr(this.col+1));
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
var Search = require("ace/search").Search;
|
var Search = require("ace/search").Search;
|
||||||
var search = new Search();
|
var search = new Search();
|
||||||
|
|
@ -179,7 +164,7 @@ module.exports = {
|
||||||
else
|
else
|
||||||
str.next();
|
str.next();
|
||||||
|
|
||||||
return {column: str.col, row: str.row}
|
return {column: str.col, row: str.row};
|
||||||
}),
|
}),
|
||||||
"b": new Motion(function(editor) {
|
"b": new Motion(function(editor) {
|
||||||
var str = new StringStream(editor);
|
var str = new StringStream(editor);
|
||||||
|
|
@ -199,7 +184,7 @@ module.exports = {
|
||||||
return {column: str.col, row: str.row};
|
return {column: str.col, row: str.row};
|
||||||
}),
|
}),
|
||||||
"B": new Motion(function(editor) {
|
"B": new Motion(function(editor) {
|
||||||
var str = new StringStream(editor)
|
var str = new StringStream(editor);
|
||||||
str.prev();
|
str.prev();
|
||||||
while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(-1))) && str.skippedLines > -2)
|
while(str.ch && !(!whiteRe.test(str.ch) && whiteRe.test(str.peek(-1))) && str.skippedLines > -2)
|
||||||
str.prev();
|
str.prev();
|
||||||
|
|
@ -208,7 +193,7 @@ module.exports = {
|
||||||
str.next();
|
str.next();
|
||||||
|
|
||||||
return {column: str.col, row: str.row};
|
return {column: str.col, row: str.row};
|
||||||
}, true),
|
}),
|
||||||
"e": new Motion(function(editor) {
|
"e": new Motion(function(editor) {
|
||||||
var str = new StringStream(editor);
|
var str = new StringStream(editor);
|
||||||
|
|
||||||
|
|
@ -389,98 +374,58 @@ module.exports = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"f": {
|
"f": new Motion({
|
||||||
param: true,
|
param: true,
|
||||||
handlesCount: true,
|
handlesCount: true,
|
||||||
nav: function(editor, range, count, param) {
|
getPos: function(editor, range, count, param, isSel) {
|
||||||
var ed = editor;
|
var cursor = editor.getCursorPosition();
|
||||||
var cursor = ed.getCursorPosition();
|
|
||||||
var column = util.getRightNthChar(editor, cursor, param, count || 1);
|
var column = util.getRightNthChar(editor, cursor, param, count || 1);
|
||||||
|
|
||||||
if (typeof column === "number") {
|
if (typeof column === "number") {
|
||||||
ed.selection.clearSelection(); // Why does it select in the first place?
|
cursor.column += column + (isSel ? 2 : 1);
|
||||||
ed.moveCursorTo(cursor.row, column + cursor.column + 1);
|
return cursor;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
sel: function(editor, range, count, param) {
|
}),
|
||||||
var ed = editor;
|
"F": new Motion({
|
||||||
var cursor = ed.getCursorPosition();
|
param: true,
|
||||||
|
handlesCount: true,
|
||||||
|
getPos: function(editor, range, count, param, isSel) {
|
||||||
|
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) {
|
||||||
|
var cursor = editor.getCursorPosition();
|
||||||
var column = util.getRightNthChar(editor, cursor, param, count || 1);
|
var column = util.getRightNthChar(editor, cursor, param, count || 1);
|
||||||
|
|
||||||
if (typeof column === "number") {
|
if (typeof column === "number") {
|
||||||
ed.moveCursorTo(cursor.row, column + cursor.column + 1);
|
cursor.column += column + (isSel ? 1 : 0);
|
||||||
|
return cursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
"F": {
|
"T": new Motion({
|
||||||
param: true,
|
param: true,
|
||||||
handlesCount: true,
|
handlesCount: true,
|
||||||
nav: function(editor, range, count, param) {
|
getPos: function(editor, range, count, param, isSel) {
|
||||||
var ed = editor;
|
var cursor = editor.getCursorPosition();
|
||||||
var cursor = ed.getCursorPosition();
|
|
||||||
var column = util.getLeftNthChar(editor, cursor, param, count || 1);
|
var column = util.getLeftNthChar(editor, cursor, param, count || 1);
|
||||||
|
|
||||||
if (typeof column === "number") {
|
if (typeof column === "number") {
|
||||||
ed.selection.clearSelection(); // Why does it select in the first place?
|
cursor.column -= column;
|
||||||
ed.moveCursorTo(cursor.row, cursor.column - column - 1);
|
return cursor;
|
||||||
}
|
|
||||||
},
|
|
||||||
sel: function(editor, range, count, param) {
|
|
||||||
var ed = editor;
|
|
||||||
var cursor = ed.getCursorPosition();
|
|
||||||
var column = util.getLeftNthChar(editor, cursor, param, count || 1);
|
|
||||||
|
|
||||||
if (typeof column === "number") {
|
|
||||||
ed.moveCursorTo(cursor.row, cursor.column - column - 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
"t": {
|
|
||||||
param: true,
|
|
||||||
handlesCount: true,
|
|
||||||
nav: function(editor, range, count, param) {
|
|
||||||
var ed = editor;
|
|
||||||
var cursor = ed.getCursorPosition();
|
|
||||||
var column = util.getRightNthChar(editor, cursor, param, count || 1);
|
|
||||||
|
|
||||||
if (typeof column === "number") {
|
|
||||||
ed.selection.clearSelection(); // Why does it select in the first place?
|
|
||||||
ed.moveCursorTo(cursor.row, column + cursor.column);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sel: function(editor, range, count, param) {
|
|
||||||
var ed = editor;
|
|
||||||
var cursor = ed.getCursorPosition();
|
|
||||||
var column = util.getRightNthChar(editor, cursor, param, count || 1);
|
|
||||||
|
|
||||||
if (typeof column === "number") {
|
|
||||||
ed.moveCursorTo(cursor.row, column + cursor.column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"T": {
|
|
||||||
param: true,
|
|
||||||
handlesCount: true,
|
|
||||||
nav: function(editor, range, count, param) {
|
|
||||||
var ed = editor;
|
|
||||||
var cursor = ed.getCursorPosition();
|
|
||||||
var column = util.getLeftNthChar(editor, cursor, param, count || 1);
|
|
||||||
|
|
||||||
if (typeof column === "number") {
|
|
||||||
ed.selection.clearSelection(); // Why does it select in the first place?
|
|
||||||
ed.moveCursorTo(cursor.row, -column + cursor.column);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
sel: function(editor, range, count, param) {
|
|
||||||
var ed = editor;
|
|
||||||
var cursor = ed.getCursorPosition();
|
|
||||||
var column = util.getLeftNthChar(editor, cursor, param, count || 1);
|
|
||||||
|
|
||||||
if (typeof column === "number") {
|
|
||||||
ed.moveCursorTo(cursor.row, -column + cursor.column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"^": {
|
"^": {
|
||||||
nav: function(editor) {
|
nav: function(editor) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue