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:
Leandro Melo
2011-08-12 12:13:23 +02:00
committed by Leandro T. C. Melo
parent 916317a9fb
commit 3945b9a70f
4 changed files with 96 additions and 0 deletions

View File

@@ -31,6 +31,7 @@
#include "syntaxhighlighter.h"
#include "basetextdocument.h"
#include "basetextdocumentlayout.h"
#include <qtextdocument.h>
#include <qtextlayout.h>
@@ -76,10 +77,12 @@ public:
}
void applyFormatChanges(int from, int charsRemoved, int charsAdded);
QVector<QTextCharFormat> formatChanges;
QTextBlock currentBlock;
bool rehighlightPending;
bool inReformatBlocks;
BaseTextDocumentLayout::FoldValidator foldValidator;
};
static bool adjustRange(QTextLayout::FormatRange &range, int from, int charsRemoved, int charsAdded) {
@@ -180,6 +183,8 @@ void SyntaxHighlighterPrivate::_q_reformatBlocks(int from, int charsRemoved, int
void SyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int charsAdded)
{
foldValidator.reset();
rehighlightPending = false;
QTextBlock block = doc->findBlock(from);
@@ -206,6 +211,8 @@ void SyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int ch
}
formatChanges.clear();
foldValidator.finalize();
}
void SyntaxHighlighterPrivate::reformatBlock(const QTextBlock &block, int from, int charsRemoved, int charsAdded)
@@ -220,6 +227,8 @@ void SyntaxHighlighterPrivate::reformatBlock(const QTextBlock &block, int from,
q->highlightBlock(block.text());
applyFormatChanges(from, charsRemoved, charsAdded);
foldValidator.process(currentBlock);
currentBlock = QTextBlock();
}
@@ -375,6 +384,7 @@ void SyntaxHighlighter::setDocument(QTextDocument *doc)
this, SLOT(_q_reformatBlocks(int,int,int)));
d->rehighlightPending = true;
QTimer::singleShot(0, this, SLOT(_q_delayedRehighlight()));
d->foldValidator.setup(qobject_cast<BaseTextDocumentLayout *>(doc->documentLayout()));
}
}