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

@ -768,7 +768,7 @@ var Document = function(text, mode) {
(function() {
this.$wrapLimit = 12;
this.$wrapLimit = 24;
this.$useWrapMode = false;
this.setUseWrapMode = function(useWrapMode) {
var _self = this;
@ -894,6 +894,10 @@ var Document = function(text, mode) {
var docColumn = column +
(docRow < linesCount ? wrapData[docRow][row - 1] || 0 : 0);
if (this.lines[docRow]) {
docColumn = Math.min(docColumn, this.lines[docRow].length);
}
return {
row: docRow,
column: docColumn

View file

@ -64,7 +64,7 @@ var Editor =function(renderer, doc) {
return event.preventDefault(e);
});
var mouseTarget = renderer.getMouseEventTarget();
var mouseTarget = renderer.getMouseEventTarget();
event.addListener(mouseTarget, "mousedown", this.onMouseDown.bind(this));
event.addMultiMouseDownListener(mouseTarget, 0, 2, 500, this.onMouseDoubleClick.bind(this));
event.addMultiMouseDownListener(mouseTarget, 0, 3, 600, this.onMouseTripleClick.bind(this));
@ -368,13 +368,11 @@ var Editor =function(renderer, doc) {
this.onMouseDoubleClick = function(e) {
this.selection.selectWord();
this.$clickSelection = this.getSelectionRange();
this.$updateDesiredColumn();
};
this.onMouseTripleClick = function(e) {
this.selection.selectLine();
this.$clickSelection = this.getSelectionRange();
this.$updateDesiredColumn();
};
this.onMouseWheel = function(e) {
@ -592,7 +590,7 @@ var Editor =function(renderer, doc) {
if (this.selection.isEmpty())
this.selection.selectLeft();
this.moveCursorToPosition(this.doc.remove(this.getSelectionRange()));
this.clearSelection();
};
@ -633,7 +631,6 @@ var Editor =function(renderer, doc) {
var range = this.doc.outdentRows(selection.getRange());
selection.setSelectionRange(range, selection.isBackwards());
this.$updateDesiredColumn();
};
this.toggleCommentLines = function() {
@ -825,17 +822,14 @@ var Editor =function(renderer, doc) {
this.clearSelection = function() {
this.selection.clearSelection();
this.$updateDesiredColumn();
};
this.moveCursorTo = function(row, column) {
this.selection.moveCursorTo(row, column);
this.$updateDesiredColumn();
};
this.moveCursorToPosition = function(pos) {
this.selection.moveCursorToPosition(pos);
this.$updateDesiredColumn();
};
@ -854,35 +848,18 @@ var Editor =function(renderer, doc) {
this.navigateTo = function(row, column) {
this.clearSelection();
this.moveCursorTo(row, column);
this.$updateDesiredColumn(column);
};
this.navigateUp = function() {
this.selection.clearSelection();
this.selection.moveCursorBy(-1, 0);
if (this.$desiredColumn) {
var cursor = this.getCursorPosition();
var column = this.doc.screenToDocumentColumn(cursor.row, this.$desiredColumn);
this.selection.moveCursorTo(cursor.row, column);
}
};
this.navigateDown = function() {
this.selection.clearSelection();
this.selection.moveCursorBy(1, 0);
if (this.$desiredColumn) {
var cursor = this.getCursorPosition();
var column = this.doc.screenToDocumentColumn(cursor.row, this.$desiredColumn);
this.selection.moveCursorTo(cursor.row, column);
}
};
this.$updateDesiredColumn = function() {
var cursor = this.getCursorPosition();
this.$desiredColumn = this.doc.documentToScreenColumn(cursor.row, cursor.column);
};
this.navigateLeft = function() {
if (!this.selection.isEmpty()) {
@ -944,7 +921,6 @@ var Editor =function(renderer, doc) {
this.$tryReplace(range, replacement);
if (range !== null)
this.selection.setSelectionRange(range);
this.$updateDesiredColumn();
},
this.replaceAll = function(replacement, options) {
@ -963,7 +939,6 @@ var Editor =function(renderer, doc) {
this.$tryReplace(ranges[i], replacement);
if (ranges[0] !== null)
this.selection.setSelectionRange(ranges[0]);
this.$updateDesiredColumn();
},
this.$tryReplace = function(range, replacement) {
@ -1016,7 +991,6 @@ var Editor =function(renderer, doc) {
var range = this.$search.find(this.doc);
if (range) {
this.gotoLine(range.end.row+1, range.end.column);
this.$updateDesiredColumn();
this.selection.setSelectionRange(range);
}
};

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 = {};