Index: autotests/src/katefoldingtest.h =================================================================== --- autotests/src/katefoldingtest.h +++ autotests/src/katefoldingtest.h @@ -33,6 +33,7 @@ private Q_SLOTS: void testCrash311866(); void testBug295632(); + void testCrash367466(); }; #endif // KATE_FOLDING_TEST_H Index: autotests/src/katefoldingtest.cpp =================================================================== --- autotests/src/katefoldingtest.cpp +++ autotests/src/katefoldingtest.cpp @@ -110,3 +110,39 @@ QString line = doc.line(0); QCOMPARE(line, QString("oooox----------")); } + +// This testcase tests the follwing: +// - the cursor is first set into the word 'hello' +// - then lines 0-3 are folded. +// - the real text cursor is still in the word 'hello' +// - the important issue is: The display cursor must be in the visible line range +// --> if this test passes, KateViewInternal's m_displayCursor is properly adapted. +void KateFoldingTest::testCrash367466() +{ + KTextEditor::DocumentPrivate doc; + QString text = "fold begin\n" + "\n" + "\n" + "fold end\n" + "hello\n" + "world\n"; + doc.setText(text); + + // view must be visible... + KTextEditor::ViewPrivate *view = static_cast(doc.createView(0)); + view->show(); + view->resize(400, 300); + view->setCursorPosition(KTextEditor::Cursor(5, 2)); + QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(5, 2)); + qint64 foldId = view->textFolding().newFoldingRange(KTextEditor::Range(0, 0, 3, 8)); + + view->textFolding().foldRange(foldId); + QVERIFY(view->textFolding().isLineVisible(0)); + QVERIFY(!view->textFolding().isLineVisible(1)); + QVERIFY(!view->textFolding().isLineVisible(2)); + QVERIFY(!view->textFolding().isLineVisible(3)); + QVERIFY(view->textFolding().isLineVisible(4)); + + view->up(); + QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(4, 2)); +} Index: src/view/kateviewinternal.cpp =================================================================== --- src/view/kateviewinternal.cpp +++ src/view/kateviewinternal.cpp @@ -709,6 +709,10 @@ // set cursor to start of folding region updateCursor(foldingRange.start(), true); + } else { + // we need to force an update of the cursor, since otherwise the m_displayCursor + // line may be below the total amount of visible lines. + updateCursor(m_cursor, true); } updateView(); @@ -1516,6 +1520,9 @@ return; } + // assert that the display cursor is in visible lines + Q_ASSERT(m_displayCursor.line() <= m_view->textFolding().visibleLines() - 1); + /** * move cursor to start of line, if we are at first line! */