Commit e82806eb authored by Sven Brauch's avatar Sven Brauch

don't crash if coordinates of a cursor behind the document's end are requested

This caused various crashes in the bracket matching animation and the
collaborative plugin's popup animations if they affected text near the end
of the document which was then removed. The fix applied by this commit is
rather broad, but should prevent all similar crashes in the future
by making the API more robust.

REVIEW:119078
parent c991f2e2
......@@ -390,6 +390,7 @@ int KateLayoutCache::viewLine(const KTextEditor::Cursor& realCursor)
{
if (realCursor.column() <= 0 || realCursor.line() < 0) return 0;
Q_ASSERT(realCursor.line() < m_renderer->doc()->lines());
KateLineLayoutPtr thisLine = line(realCursor.line());
for (int i = 0; i < thisLine->viewLineCount(); ++i) {
......
......@@ -738,6 +738,9 @@ int KateViewInternal::linesDisplayed() const
QPoint KateViewInternal::cursorToCoordinate( const KTextEditor::Cursor & cursor, bool realCursor, bool includeBorder ) const
{
if (cursor.line() >= doc()->lines()) {
return QPoint(-1, -1);
}
int viewLine = cache()->displayViewLine(realCursor ? toVirtualCursor(cursor) : cursor, true);
if (viewLine < 0 || viewLine >= cache()->viewCacheLineCount())
......
......@@ -68,6 +68,7 @@ void KateViewTest::testCoordinatesToCursor()
// behind end of line should give an invalid cursor
QCOMPARE(view1->coordinatesToCursor(view1->cursorToCoordinate(KTextEditor::Cursor(1, 5))),
KTextEditor::Cursor::invalid());
QCOMPARE(view1->cursorToCoordinate(KTextEditor::Cursor(3, 1)), QPoint(-1, -1));
}
void KateViewTest::testReloadMultipleViews()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment