code: function coordsChar(cm, x, y) {
      var doc = cm.doc;
      y += cm.display.viewOffset;
      if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
      var lineNo = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
      if (lineNo > last)
        return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
      if (x < 0) x = 0;
  
      for (;;) {
        var lineObj = getLine(doc, lineNo);
        var found = coordsCharInner(cm, lineObj, lineNo, x, y);
        var merged = collapsedSpanAtEnd(lineObj);
        var mergedPos = merged && merged.find();
        if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
          lineNo = mergedPos.to.line;
        else
          return found;
      }
    }
docs: Coords must be lineSpace-local