Merge pull request #982 from ajaxorg/vim

vim mode: fix df
This commit is contained in:
Mostafa Eweda 2012-10-01 08:16:29 -07:00
commit 7877ff5e44

View file

@ -28,9 +28,9 @@
*
* ***** END LICENSE BLOCK ***** */
"use strict"
define(function(require, exports, module) {
"use strict";
var util = require("./util");
@ -42,42 +42,27 @@ var keepScrollPosition = function(editor, fn) {
editor.renderer.scrollToRow(editor.getCursorPosition().row - diff);
};
function Motion(getRange, type){
if (type == 'extend')
var extend = true;
else
var reverse = type;
this.nav = function(editor) {
var r = getRange(editor);
if (!r)
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;
if (!r.end)
var a = r;
else if (reverse)
var a = r.start;
else
var a = r.end;
editor.clearSelection();
editor.moveCursorTo(a.row, a.column);
}
this.sel = function(editor){
var r = getRange(editor);
if (!r)
};
m.sel = function(editor, range, count, param) {
var a = getPos(editor, range, count, param, true);
if (!a)
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);
}
};
return m;
}
var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
@ -90,20 +75,20 @@ var StringStream = function(editor, cursor) {
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'
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)
@ -113,7 +98,7 @@ var StringStream = function(editor, cursor) {
if (this.col == line.length - 1)
return '\n';
return editor.session.getLine(this.row + 1)[0] || '\n';
}
};
this.handleNewLine = function(dir) {
if (dir == 1){
@ -128,7 +113,7 @@ var StringStream = function(editor, cursor) {
return line[0] || '\n';
}
if (dir == -1) {
if (this.row == 0)
if (this.row === 0)
return '';
this.row --;
line = editor.session.getLine(this.row);
@ -136,11 +121,11 @@ var StringStream = function(editor, cursor) {
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("ace/search").Search;
var search = new Search();
@ -179,7 +164,7 @@ module.exports = {
else
str.next();
return {column: str.col, row: str.row}
return {column: str.col, row: str.row};
}),
"b": new Motion(function(editor) {
var str = new StringStream(editor);
@ -199,7 +184,7 @@ module.exports = {
return {column: str.col, row: str.row};
}),
"B": new Motion(function(editor) {
var str = new StringStream(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();
@ -208,7 +193,7 @@ module.exports = {
str.next();
return {column: str.col, row: str.row};
}, true),
}),
"e": new Motion(function(editor) {
var str = new StringStream(editor);
@ -389,98 +374,58 @@ module.exports = {
}
},
"f": {
"f": new Motion({
param: true,
handlesCount: true,
nav: function(editor, range, count, param) {
var ed = editor;
var cursor = ed.getCursorPosition();
getPos: function(editor, range, count, param, isSel) {
var cursor = editor.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 + 1);
cursor.column += column + (isSel ? 2 : 1);
return cursor;
}
},
sel: function(editor, range, count, param) {
var ed = editor;
var cursor = ed.getCursorPosition();
}
}),
"F": new Motion({
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);
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,
handlesCount: true,
nav: function(editor, range, count, param) {
var ed = editor;
var cursor = ed.getCursorPosition();
getPos: function(editor, range, count, param, isSel) {
var cursor = editor.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, cursor.column - column - 1);
}
},
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);
cursor.column -= column;
return cursor;
}
}
},
"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) {