From e2d47c6a60807be3f1dff1137945c72b3f6a7209 Mon Sep 17 00:00:00 2001 From: nightwing Date: Fri, 18 Nov 2011 17:39:03 +0400 Subject: [PATCH] fix clipping at the boundaries, and add more tests --- lib/ace/edit_session.js | 12 ++++++------ lib/ace/edit_session_test.js | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 621a6211..9754f1b4 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -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) { diff --git a/lib/ace/edit_session_test.js b/lib/ace/edit_session_test.js index a93c9ca2..aeb2cef6 100644 --- a/lib/ace/edit_session_test.js +++ b/lib/ace/edit_session_test.js @@ -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() {