Commit e5272a11 authored by Milian Wolff's avatar Milian Wolff

Do not crash when encountering invalid cursor in cursorToCoordinate.

This only hit so far when dyn word wrap was enabled. Now we catch it
always and prevent early to prevent the assertion.

BUG: 337863
parent 910071eb
......@@ -404,6 +404,9 @@ int KateLayoutCache::viewLine(const KTextEditor::Cursor& realCursor)
int KateLayoutCache::displayViewLine(const KTextEditor::Cursor& virtualCursor, bool limitToVisible)
{
if (!virtualCursor.isValid())
return -1;
KTextEditor::Cursor work = viewCacheStart();
// only try this with valid lines!
......
......@@ -71,6 +71,22 @@ void KateViewTest::testCoordinatesToCursor()
QCOMPARE(view1->cursorToCoordinate(KTextEditor::Cursor(3, 1)), QPoint(-1, -1));
}
void KateViewTest::testCursorToCoordinates()
{
KateDocument doc(false, false, false);
doc.setText("int a;");
KateView* view = static_cast<KateView*>(doc.createView(0));
// this is important
view->config()->setDynWordWrap(true);
view->show();
// don't crash, see https://bugs.kde.org/show_bug.cgi?id=337863
view->cursorToCoordinate(Cursor(0, 0));
view->cursorToCoordinate(Cursor(1, 0));
view->cursorToCoordinate(Cursor(-1, 0));
}
void KateViewTest::testReloadMultipleViews()
{
KTemporaryFile file;
......
......@@ -39,6 +39,7 @@ private Q_SLOTS:
void testFolding();
void testCoordinatesToCursor();
void testCursorToCoordinates();
void testBug287291();
......
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