forked from qt-creator/qt-creator
Editors: Make sure folded blocks remain consistent
When folding indents change and a block becomes no longer folded we need to update the user data. This patch tries to handle general inconsistencies that might arise in such situations. Notice however that there are stil other problems to be addressed (including issues in Qt). Task-number: QTCREATORBUG-5771 Change-Id: I38b869832159598d46cde00058308c218ca31f1a Reviewed-on: http://codereview.qt.nokia.com/2908 Reviewed-by: Robert Löhning <robert.loehning@nokia.com> Reviewed-by: Matthias Ettrich
This commit is contained in:
committed by
Leandro T. C. Melo
parent
916317a9fb
commit
3945b9a70f
@@ -575,3 +575,69 @@ QSizeF BaseTextDocumentLayout::documentSize() const
|
||||
size.setWidth(qMax((qreal)m_requiredWidth, size.width()));
|
||||
return size;
|
||||
}
|
||||
|
||||
BaseTextDocumentLayout::FoldValidator::FoldValidator()
|
||||
: m_layout(0)
|
||||
, m_requestDocUpdate(false)
|
||||
, m_insideFold(0)
|
||||
{}
|
||||
|
||||
void BaseTextDocumentLayout::FoldValidator::setup(BaseTextDocumentLayout *layout)
|
||||
{
|
||||
m_layout = layout;
|
||||
}
|
||||
|
||||
void BaseTextDocumentLayout::FoldValidator::reset()
|
||||
{
|
||||
m_insideFold = 0;
|
||||
m_requestDocUpdate = false;
|
||||
}
|
||||
|
||||
void BaseTextDocumentLayout::FoldValidator::process(QTextBlock block)
|
||||
{
|
||||
if (!m_layout)
|
||||
return;
|
||||
|
||||
const QTextBlock &previous = block.previous();
|
||||
if (!previous.isValid())
|
||||
return;
|
||||
|
||||
if ((BaseTextDocumentLayout::isFolded(previous)
|
||||
&& !BaseTextDocumentLayout::canFold(previous))
|
||||
|| (!BaseTextDocumentLayout::isFolded(previous)
|
||||
&& BaseTextDocumentLayout::canFold(previous)
|
||||
&& !block.isVisible())) {
|
||||
BaseTextDocumentLayout::setFolded(previous, !BaseTextDocumentLayout::isFolded(previous));
|
||||
}
|
||||
|
||||
if (BaseTextDocumentLayout::isFolded(previous) && !m_insideFold)
|
||||
m_insideFold = BaseTextDocumentLayout::foldingIndent(block);
|
||||
|
||||
bool toggleVisibility = false;
|
||||
if (m_insideFold) {
|
||||
if (BaseTextDocumentLayout::foldingIndent(block) >= m_insideFold) {
|
||||
if (block.isVisible())
|
||||
toggleVisibility = true;
|
||||
} else {
|
||||
m_insideFold = 0;
|
||||
if (!block.isVisible())
|
||||
toggleVisibility = true;
|
||||
}
|
||||
} else if (!block.isVisible()) {
|
||||
toggleVisibility = true;
|
||||
}
|
||||
|
||||
if (toggleVisibility) {
|
||||
block.setVisible(!block.isVisible());
|
||||
block.setLineCount(block.isVisible() ? qMax(1, block.layout()->lineCount()) : 0);
|
||||
m_requestDocUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
void BaseTextDocumentLayout::FoldValidator::finalize()
|
||||
{
|
||||
if (m_requestDocUpdate && m_layout) {
|
||||
m_layout->requestUpdate();
|
||||
m_layout->emitDocumentSizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user