Clamp row before column so that selection works at document's end

This commit is contained in:
nightwing 2011-01-31 00:32:53 +08:00 committed by Fabian Jakobs
commit 1f4c093b6e

View file

@ -918,7 +918,7 @@ var EditSession = function(text, mode) {
/**
*
* @returns array
* - array[0]: The documentRow aquivalent.
* - array[0]: The documentRow equivalent.
* - array[1]: The screenRowOffset to the first documentRow on the screen.
*/
this.$screenToDocumentRow = function(row) {
@ -949,23 +949,24 @@ var EditSession = function(text, mode) {
var docRow;
var docColumn;
var remaining = column;
var linesCount = this.getLength();
if (!this.$useWrapMode) {
docRow = row;
docRow = row >= linesCount? linesCount-1 : (row < 0 ? 0 : row);
row = 0;
docColumn = 0;
line = this.getLine(docRow);
} else {
var wrapData = this.$wrapData, linesCount = this.getLength();
var wrapData = this.$wrapData;
var rowData = this.$screenToDocumentRow(row);
row = rowData[1];
docRow = rowData[0];
var docRow = 0;
while (docRow < linesCount && row >= wrapData[docRow].length + 1) {
row -= wrapData[docRow].length + 1;
docRow ++;
}
if (docRow >= linesCount) {
return {
row: docRow,
column: 0
};
docRow = linesCount-1
row = wrapData[docRow].length;
}
docColumn = wrapData[docRow][row - 1] || 0;
line = this.getLine(docRow).substring(docColumn);
@ -1009,15 +1010,16 @@ var EditSession = function(text, mode) {
}
// Clamp docColumn.
if (docRow < linesCount && wrapData[docRow][row]) {
if (docColumn >= wrapData[docRow][row]) {
if (this.$useWrapMode) {
column = wrapData[docRow][row]
if (docColumn >= column) {
// We remove one character at the end such that the docColumn
// position returned is not associated to the next row on the
// screen.
docColumn = wrapData[docRow][row] - 1;
docColumn = column - 1;
}
} else if (this.getLine(docRow)) {
docColumn = Math.min(docColumn, this.getLine(docRow).length);
} else if (line) {
docColumn = Math.min(docColumn, line.length);
}
return {