From dbc88322c9b303791ab97812bf4e064ca41f25b7 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 8 Aug 2019 07:09:05 +0200 Subject: [PATCH] Fix bug in coordsChar when there's a collapsed range at start of line Issue #5966 --- src/measurement/position_measurement.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/measurement/position_measurement.js b/src/measurement/position_measurement.js index fa8b4c31c0..73b081ba0e 100644 --- a/src/measurement/position_measurement.js +++ b/src/measurement/position_measurement.js @@ -412,7 +412,7 @@ export function estimateCoords(cm, pos) { function PosWithInfo(line, ch, sticky, outside, xRel) { let pos = Pos(line, ch, sticky) pos.xRel = xRel - if (outside) pos.outside = true + if (outside) pos.outside = outside return pos } @@ -421,16 +421,16 @@ function PosWithInfo(line, ch, sticky, outside, xRel) { export function coordsChar(cm, x, y) { let doc = cm.doc y += cm.display.viewOffset - if (y < 0) return PosWithInfo(doc.first, 0, null, true, -1) + if (y < 0) return PosWithInfo(doc.first, 0, null, -1, -1) let lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1 if (lineN > last) - return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, true, 1) + return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, 1, 1) if (x < 0) x = 0 let lineObj = getLine(doc, lineN) for (;;) { let found = coordsCharInner(cm, lineObj, lineN, x, y) - let collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 ? 1 : 0)) + let collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 || found.outside > 0 ? 1 : 0)) if (!collapsed) return found let rangeEnd = collapsed.find(1) if (rangeEnd.line == lineN) return rangeEnd @@ -518,7 +518,7 @@ function coordsCharInner(cm, lineObj, lineNo, x, y) { // base X position let coords = cursorCoords(cm, Pos(lineNo, ch, sticky), "line", lineObj, preparedMeasure) baseX = coords.left - outside = y < coords.top || y >= coords.bottom + outside = y < coords.top ? -1 : y >= coords.bottom ? 1 : 0 } ch = skipExtendingChars(lineObj.text, ch, 1)