small cleanup

This commit is contained in:
nightwing 2012-08-27 23:00:51 +04:00
commit 3dd051f857
2 changed files with 26 additions and 30 deletions

View file

@ -35,9 +35,9 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
"use strict"
define(function(require, exports, module) { define(function(require, exports, module) {
"use strict";
module.exports = { module.exports = {
"x": { "x": {
operator: { operator: {

View file

@ -36,9 +36,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");
@ -56,36 +56,26 @@ function Motion(getRange, type){
else else
var reverse = type; var reverse = type;
this.nav = function(editor) { this.nav = function(editor, range, count, param) {
var r = getRange(editor); range = getRange(editor, range, count, param);
if (!r) if (!range)
return; return;
if (!r.end) var pos = range.end ? range : range[reverse ? "start" : "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(pos.row, pos.column);
} };
this.sel = function(editor){ this.sel = function(editor, range, count, param){
var r = getRange(editor); range = getRange(editor, range, count, param);
if (!r) if (!range)
return; return;
if (extend) if (extend)
return editor.selection.setSelectionRange(r); return editor.selection.setSelectionRange(range);
if (!r.end) var pos = range.end ? range : range[reverse ? "start" : "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(pos.row, pos.column);
} };
} }
var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/; var nonWordRe = /[\s.\/\\()\"'-:,.;<>~!@#$%^&*|+=\[\]{}`~?]/;
@ -98,8 +88,8 @@ 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() {
@ -187,7 +177,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);
@ -505,6 +495,9 @@ module.exports = {
editor.gotoLine(count || 0); editor.gotoLine(count || 0);
case "U": case "U":
editor.gotoLine(count || 0); editor.gotoLine(count || 0);
case "$":
editor.navigateLineEnd();
break;
} }
}, },
sel: function(editor, range, count, param) { sel: function(editor, range, count, param) {
@ -517,6 +510,9 @@ module.exports = {
break; break;
case "g": case "g":
editor.selection.selectTo(count || 0, 0); editor.selection.selectTo(count || 0, 0);
case "$":
editor.selection.selectLineEnd();
break;
} }
} }
}, },
@ -528,7 +524,7 @@ module.exports = {
content += "\n"; content += "\n";
if (content.length) { if (content.length) {
editor.navigateLineEnd() editor.navigateLineEnd();
editor.insert(content); editor.insert(content);
util.insertMode(editor); util.insertMode(editor);
} }