move () on Selection. Add support for moveDown/Up when in wrapMode

This commit is contained in:
Julian Viereck 2011-01-09 01:28:03 +01:00
commit bc4c9c6060
3 changed files with 33 additions and 39 deletions

View file

@ -158,11 +158,20 @@ var Selection = function(doc) {
this.setSelectionRange = function(range, reverse) {
if (reverse) {
this.setSelectionAnchor(range.end.row, range.end.column);
this.selectTo(range.start.row, range.start.column);
this.selectTo(range.start.row, range.start.column);
} else {
this.setSelectionAnchor(range.start.row, range.start.column);
this.selectTo(range.end.row, range.end.column);
}
this.$updateDesiredColumn();
};
this.$updateDesiredColumn = function() {
var cursor = this.getCursor();
if (cursor) {
this.$desiredColumn = this.doc.documentToScreenPosition(cursor.row, cursor.column).column;
console.log("selection.$updateDesiredColumn", this.$desiredColumn);
}
};
this.$moveSelection = function(mover) {
@ -241,7 +250,7 @@ var Selection = function(doc) {
var column = cursor.column;
var range = this.doc.getWordRange(cursor.row, column);
this.setSelectionRange(range);
/*this.setSelectionAnchor(cursor.row, start);
this.$moveSelection(function() {
this.moveCursorTo(cursor.row, end);
@ -265,7 +274,7 @@ var Selection = function(doc) {
this.moveCursorLeft = function() {
if (this.selectionLead.column == 0) {
// cursor is a line start
// cursor is a line (start
if (this.selectionLead.row > 0) {
this.moveCursorTo(this.selectionLead.row - 1, this.doc
.getLine(this.selectionLead.row - 1).length);
@ -309,7 +318,7 @@ var Selection = function(doc) {
else if (leadingSpace[0].length >= column)
this.moveCursorTo(row, 0);
else
this.moveCursorTo(row, leadingSpace[0].length);
this.moveCursorTo(row, leadingSpace[0].length);
};
this.moveCursorLineEnd = function() {
@ -380,7 +389,17 @@ var Selection = function(doc) {
};
this.moveCursorBy = function(rows, chars) {
this.moveCursorTo(this.selectionLead.row + rows, this.selectionLead.column + chars);
if (this.doc.getUseWrapMode()) {
var pos = this.doc.documentToScreenPosition(
this.selectionLead.row, this.selectionLead.column);
pos = this.doc.screenToDocumentPosition(
pos.row + rows, (this.$desiredColumn || pos.column));
this.moveCursorTo(pos.row, pos.column + chars, chars == 0);
} else {
this.moveCursorTo(this.selectionLead.row + rows,
(this.$desiredColumn || this.selectionLead.column) + chars,
chars == 0);
}
};
@ -388,20 +407,17 @@ var Selection = function(doc) {
this.moveCursorTo(position.row, position.column);
};
this.moveCursorTo = function(row, column) {
this.moveCursorTo = function(row, column, preventUpdateDesiredColumn) {
var cursor = this.$clipPositionToDocument(row, column);
// only dispatch change if the cursor actually changed
if (cursor.row !== this.selectionLead.row || cursor.column !== this.selectionLead.column) {
this.selectionLead = cursor;
!preventUpdateDesiredColumn && this.$updateDesiredColumn(column);
this._dispatchEvent("changeCursor", { data: this.getCursor() });
}
};
this.moveCursorUp = function() {
this.moveCursorBy(-1, 0);
};
this.$clipPositionToDocument = function(row, column) {
var pos = {};