Skip to content

Commit

Permalink
Editor: Simplify FoldValidator::process.
Browse files Browse the repository at this point in the history
Change-Id: I9181c18ae5a36f5ab0027fb36cea21f4f2a5e99c
Reviewed-by: Christian Stenger <[email protected]>
  • Loading branch information
davschul committed Jun 8, 2016
1 parent 3aae298 commit 1e90926
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions src/plugins/texteditor/textdocumentlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1e90926

Please sign in to comment.