File 0002-Fix-crash-Make-sure-the-display-cursor-is-valid-afte.patch of Package ktexteditor.7413
From 98c449878f59ea99772e20c19ebff7e01b84068c Mon Sep 17 00:00:00 2001
From: Dominik Haumann <dhaumann@kde.org>
Date: Thu, 8 Sep 2016 15:32:39 +0200
Subject: [PATCH 2/3] Fix crash: Make sure the display cursor is valid after
text folding
This bug existed at least since KDE 4.3 (2009), took a long time to track it down.
FIXED-IN: KDE Frameworks 5.27
BUG: 367466
Differential-Revision: https://phabricator.kde.org/D2709
(cherry picked from commit 09a1e864d54735ebcab6bf31198fdef969b92a67)
---
autotests/src/katefoldingtest.cpp | 38 ++++++++++++++++++++++++++++++++++++++
autotests/src/katefoldingtest.h | 1 +
src/view/kateviewinternal.cpp | 7 +++++++
3 files changed, 46 insertions(+)
diff --git a/autotests/src/katefoldingtest.cpp b/autotests/src/katefoldingtest.cpp
index a2526d5..79f88fe 100644
--- a/autotests/src/katefoldingtest.cpp
+++ b/autotests/src/katefoldingtest.cpp
@@ -110,3 +110,41 @@ void KateFoldingTest::testBug295632()
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<KTextEditor::ViewPrivate *>(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));
+ QVERIFY(view->textFolding().isLineVisible(5));
+
+ QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(5, 2));
+ view->up();
+ QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(4, 2));
+}
diff --git a/autotests/src/katefoldingtest.h b/autotests/src/katefoldingtest.h
index 0cb8197..9482678 100644
--- a/autotests/src/katefoldingtest.h
+++ b/autotests/src/katefoldingtest.h
@@ -33,6 +33,7 @@ public Q_SLOTS:
private Q_SLOTS:
void testCrash311866();
void testBug295632();
+ void testCrash367466();
};
#endif // KATE_FOLDING_TEST_H
diff --git a/src/view/kateviewinternal.cpp b/src/view/kateviewinternal.cpp
index 8f9d4db..13d031e 100644
--- a/src/view/kateviewinternal.cpp
+++ b/src/view/kateviewinternal.cpp
@@ -707,6 +707,10 @@ void KateViewInternal::slotRegionVisibilityChanged()
// set cursor to start of folding region
updateCursor(foldingRange.start(), true);
+ } else {
+ // 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();
@@ -1514,6 +1518,9 @@ void KateViewInternal::cursorUp(bool sel)
return;
}
+ // assert that the display cursor is in visible lines
+ Q_ASSERT(m_displayCursor.line() < m_view->textFolding().visibleLines());
+
/**
* move cursor to start of line, if we are at first line!
*/
--
2.10.0