Commit 5888f4b7 authored by Dominik Haumann's avatar Dominik Haumann
Browse files

make sure cursor stays visible/valid when text is folded

FIXED-IN: 4.11
BUG: 311866
CCBUG: 200858
parent 7ba51160
......@@ -156,6 +156,15 @@ qint64 TextFolding::newFoldingRange (const KTextEditor::Range &range, FoldingRan
return newRange->id;
KTextEditor::Range TextFolding::foldingRange(qint64 id) const
FoldingRange* range = m_idToFoldingRange.value (id);
if (!range)
return KTextEditor::Range::invalid();
return KTextEditor::Range(range->start->toCursor(), range->end->toCursor());
bool TextFolding::foldRange (qint64 id)
......@@ -78,7 +78,17 @@ class KATEPART_TESTS_EXPORT TextFolding : public QObject {
* the ids are stable for one Kate::TextFolding, e.g. you can rely in unit tests that you get 0,1,.... for successfully created ranges!
qint64 newFoldingRange (const KTextEditor::Range &range, FoldingRangeFlags flags = FoldingRangeFlags());
* Returns the folding range associated with @p id.
* If @p id is not a valid id, the returned range matches KTextEditor::Range::invalid().
* @note This works for either persistend ranges or folded ranges.
* Note, that the highlighting does not add folds unless text is folded.
* @return the folding range for @p id
KTextEditor::Range foldingRange(qint64 id) const;
* Fold the given range.
* @param id id of the range to fold
......@@ -668,13 +668,15 @@ void KateViewInternal::slotRegionVisibilityChanged()
if (startPos() > max)
#if 0 // DON'T MESS WITH THE CURSORS and foldedselection_test
m_preserveX = true;
KTextEditor::Cursor newPos = toRealCursor(toVirtualCursor(m_cursor));
KateTextLayout newLine = cache()->textLayout(newPos);
newPos = renderer()->xToCursor(newLine, m_preservedX, !m_view->wrapCursor());
updateCursor(newPos, true);
// if text was folded: make sure the cursor is on a visible line
qint64 foldedRangeId = -1;
if (!m_view->textFolding().isLineVisible (m_cursor.line(), &foldedRangeId)) {
KTextEditor::Range foldingRange = m_view->textFolding().foldingRange(foldedRangeId);
// set cursor to start of folding region
updateCursor(foldingRange.start(), true);
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