Commit 1e909269 authored by David Schulz's avatar David Schulz

Editor: Simplify FoldValidator::process.

Change-Id: I9181c18ae5a36f5ab0027fb36cea21f4f2a5e99c
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 3aae2989
......@@ -655,34 +655,27 @@ void TextDocumentLayout::FoldValidator::process(QTextBlock block)
if (!previous.isValid())
return;
if ((TextDocumentLayout::isFolded(previous)
&& !TextDocumentLayout::canFold(previous))
|| (!TextDocumentLayout::isFolded(previous)
&& TextDocumentLayout::canFold(previous)
&& previous.isVisible()
&& !block.isVisible())) {
TextDocumentLayout::setFolded(previous, !TextDocumentLayout::isFolded(previous));
}
if (TextDocumentLayout::isFolded(previous) && !m_insideFold)
m_insideFold = TextDocumentLayout::foldingIndent(block);
bool toggleVisibility = false;
if (m_insideFold) {
if (TextDocumentLayout::foldingIndent(block) >= m_insideFold) {
if (block.isVisible())
toggleVisibility = true;
} else {
const bool preIsFolded = isFolded(previous);
const bool preCanFold = canFold(previous);
const bool isVisible = block.isVisible();
if (preIsFolded && !preCanFold)
setFolded(previous, false);
else if (!preIsFolded && preCanFold && previous.isVisible() && !isVisible)
setFolded(previous, true);
if (isFolded(previous) && !m_insideFold)
m_insideFold = foldingIndent(block);
bool shouldBeVisible = m_insideFold == 0;
if (!shouldBeVisible) {
shouldBeVisible = foldingIndent(block) < m_insideFold;
if (shouldBeVisible)
m_insideFold = 0;
if (!block.isVisible())
toggleVisibility = true;
}
} else if (!block.isVisible()) {
toggleVisibility = true;
}
if (toggleVisibility) {
block.setVisible(!block.isVisible());
if (shouldBeVisible != isVisible) {
block.setVisible(shouldBeVisible);
block.setLineCount(block.isVisible() ? qMax(1, block.layout()->lineCount()) : 0);
m_requestDocUpdate = 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