Skip to content

Commit

Permalink
Fix bug in coordsChar when there's a collapsed range at start of line
Browse files Browse the repository at this point in the history
Issue #5966
  • Loading branch information
marijnh committed Aug 8, 2019
1 parent 1580dd1 commit dbc8832
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/measurement/position_measurement.js
Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dbc8832

Please sign in to comment.