From 334b4c110434d88e1cc0e4bef2e9fc43fb330170 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sat, 30 Apr 2016 11:51:54 +0200 Subject: [PATCH] Overshoot to the end of the text node when the position cannot be found ...because the only possible scenario when a logical position in a text node cannot be found is when the requested pixel position is exactly at the end of the node. --- spec/lines-yardstick-spec.coffee | 7 ++++--- src/lines-yardstick.coffee | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/lines-yardstick-spec.coffee b/spec/lines-yardstick-spec.coffee index 72609143e..0cbb6e312 100644 --- a/spec/lines-yardstick-spec.coffee +++ b/spec/lines-yardstick-spec.coffee @@ -155,9 +155,10 @@ describe "LinesYardstick", -> expect(linesYardstick.screenPositionForPixelPosition({top: 28, left: 100})).toEqual([2, 14]) expect(linesYardstick.screenPositionForPixelPosition({top: 32, left: 24.3})).toEqual([2, 3]) expect(linesYardstick.screenPositionForPixelPosition({top: 46, left: 66.5})).toEqual([3, 9]) - expect(linesYardstick.screenPositionForPixelPosition({top: 80, left: 99.9})).toEqual([5, 14]) - expect(linesYardstick.screenPositionForPixelPosition({top: 80, left: 224.2365234375})).toEqual([5, 29]) - expect(linesYardstick.screenPositionForPixelPosition({top: 80, left: 225})).toEqual([5, 30]) + expect(linesYardstick.screenPositionForPixelPosition({top: 70, left: 99.9})).toEqual([5, 14]) + expect(linesYardstick.screenPositionForPixelPosition({top: 70, left: 224.2365234375})).toEqual([5, 29]) + expect(linesYardstick.screenPositionForPixelPosition({top: 70, left: 225})).toEqual([5, 30]) + expect(linesYardstick.screenPositionForPixelPosition({top: 84, left: 247.1})).toEqual([6, 33]) it "clips pixel positions above buffer start", -> expect(linesYardstick.screenPositionForPixelPosition(top: -Infinity, left: -Infinity)).toEqual [0, 0] diff --git a/src/lines-yardstick.coffee b/src/lines-yardstick.coffee index 39e16a8e0..af12242a3 100644 --- a/src/lines-yardstick.coffee +++ b/src/lines-yardstick.coffee @@ -75,6 +75,7 @@ class LinesYardstick characterIndex = nextCharIndex break + characterIndex = textNode.textContent.length if characterIndex is -1 textNodeStartColumn = 0 textNodeStartColumn += textNodes[i].length for i in [0...textNodeIndex] by 1 Point(row, textNodeStartColumn + characterIndex)