Return invalid cursor for coordinates outside text

QTextLine::xToCursor(), to which KateRenderer::xToCursor() delegates, does not allow to distinguish positions "at the end of line" and "beyond the end of line". Remove the old, now broken and useless, fix and replace it with a new one described below.

The horizontal boundaries of text on a line can be obtained via QTextLine::naturalTextRect() or [0, QTextLine::naturalTextWidth()]. So return an invalid cursor from KateViewInternal::coordinatesToCursor() if coord.x() falls out of that range. The two alternative ranges were always equal in my experiments. Opt for the more efficient naturalTextWidth() range check that appears to work well. If it does not work for some use case, the slower naturalTextRect() can be checked instead.

Turns out that most uses of KateViewInternal::coordinatesToCursor() in KTextEditor rely on its current return value for coordinates of an empty space. That is, applying the fix unconditionally breaks functionality that depends on mouse tracking, in particular inline notes. So make the new behavior optional and opt out of it everywhere in KTextEditor. I am not sure whether the old or the new behavior is better in KateViewAccessible::offsetAtPoint(), so keep the old one to be on the safe side.

#25 (closed)

Merge request reports

Loading
Loading