fix clipping at the boundaries, and add more tests

This commit is contained in:
nightwing 2011-11-18 17:39:03 +04:00
commit e2d47c6a60
2 changed files with 14 additions and 6 deletions

View file

@ -1386,9 +1386,7 @@ var EditSession = function(text, mode) {
}
var doCache = !rowCache.length || i == rowCache.length;
// clamp row before clamping column, for selection on last line
var maxRow = this.getLength() - 1;
var foldLine = this.getNextFoldLine(docRow);
var foldStart = foldLine ? foldLine.start.row : Infinity;
@ -1416,6 +1414,12 @@ var EditSession = function(text, mode) {
if (foldLine && foldLine.start.row <= docRow) {
line = this.getFoldDisplayLine(foldLine);
docRow = foldLine.start.row;
} else if (row + rowLength <= screenRow || docRow > maxRow) {
// clip at the end of the document
return {
row: maxRow,
column: this.getLine(maxRow).length
}
} else {
line = this.getLine(docRow);
foldLine = null;
@ -1434,10 +1438,6 @@ var EditSession = function(text, mode) {
docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
// clip row at the end of the document
if (docRow > maxRow)
docColumn = Number.MAX_VALUE;
// Need to do some clamping action here.
if (this.$useWrapMode) {
if (docColumn >= column) {

View file

@ -363,6 +363,14 @@ module.exports = {
assert.position(session.screenToDocumentPosition(1, 30), 1, 12);
assert.position(session.screenToDocumentPosition(20, 50), 1, 12);
assert.position(session.screenToDocumentPosition(20, 5), 1, 12);
// and the same for folded rows
session.addFold("...", new Range(0,1,1,3));
assert.position(session.screenToDocumentPosition(1, 2), 1, 12);
// for wrapped rows
session.setUseWrapMode(true);
session.setWrapLimitRange(5,5);
assert.position(session.screenToDocumentPosition(4, 1), 1, 12);
},
"test: wrapLine split function" : function() {