diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp --- a/src/view/kateview.cpp +++ b/src/view/kateview.cpp @@ -1265,14 +1265,23 @@ bool KTextEditor::ViewPrivate::unfoldLine(int line) { bool actionDone = false; + const KTextEditor::Cursor currentCursor = cursorPosition(); // ask the folding info for this line, if any folds are around! // auto = QVector> auto startingRanges = textFolding().foldingRangesStartingOnLine(line); - for (int i = 0; i < startingRanges.size(); ++i) { + for (int i = 0; i < startingRanges.size() && !actionDone; ++i) { + // Avoid jumping view in case of a big unfold and ensure nice highlight of folding marker + setCursorPosition(textFolding().foldingRange(startingRanges[i].first).start()); + actionDone |= textFolding().unfoldRange(startingRanges[i].first); } + if (!actionDone) { + // Nothing unfolded? Restore old cursor position! + setCursorPosition(currentCursor); + } + return actionDone; } @@ -1295,6 +1304,7 @@ } bool actionDone = false; // Track success + const KTextEditor::Cursor currentCursor = cursorPosition(); // Don't be too eager but obliging! Only toggle containing ranges which are // visible -> Be done when the range is folded @@ -1305,6 +1315,11 @@ for (int ln = foldingRange.start().line() + 1; ln < foldingRange.end().line(); ++ln) { actionDone |= unfoldLine(ln); } + + if (actionDone) { + // In most cases we want now a not moved cursor + setCursorPosition(currentCursor); + } } if (!actionDone) {