diff --git a/src/document/katebuffer.cpp b/src/document/katebuffer.cpp --- a/src/document/katebuffer.cpp +++ b/src/document/katebuffer.cpp @@ -656,6 +656,11 @@ endCursor = KTextEditor::Cursor(endCursor.line() - 1, plainLine(lines() - 1)->length()); } + // Don't return a valid range without content! + if (endCursor.line() - startLine == 1) { + return KTextEditor::Range::invalid(); + } + /** * return computed range */ diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp --- a/src/view/kateview.cpp +++ b/src/view/kateview.cpp @@ -1312,7 +1312,8 @@ for (int ln = foldingRange.start().line() + 1; ln < foldingRange.end().line(); ++ln) { KTextEditor::Range fr = foldLine(ln); if (fr.isValid()) { - ln = fr.end().line() - 1; + // qMax to avoid infinite loop in case of range without content + ln = qMax(ln, fr.end().line() - 1); actionDone = true; } }