forked from qt-creator/qt-creator
TextEditor: Move TextDocument::setIfdefedOutBlocks() to CppEditor
... where it belongs. Change-Id: I4e7f344ed2d4af626965cf1f8a318de56a03a8bc Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -526,72 +526,6 @@ bool TextDocument::applyChangeSet(const ChangeSet &changeSet)
|
||||
return PlainRefactoringFileFactory().file(filePath())->apply(changeSet);
|
||||
}
|
||||
|
||||
// the blocks list must be sorted
|
||||
void TextDocument::setIfdefedOutBlocks(const QList<BlockRange> &blocks)
|
||||
{
|
||||
if (syntaxHighlighter() && !syntaxHighlighter()->syntaxHighlighterUpToDate()) {
|
||||
connect(syntaxHighlighter(),
|
||||
&SyntaxHighlighter::finished,
|
||||
this,
|
||||
[this, blocks] { setIfdefedOutBlocks(blocks); },
|
||||
Qt::SingleShotConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
QTextDocument *doc = document();
|
||||
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
||||
QTC_ASSERT(documentLayout, return);
|
||||
|
||||
bool needUpdate = false;
|
||||
|
||||
QTextBlock block = doc->firstBlock();
|
||||
|
||||
int rangeNumber = 0;
|
||||
int braceDepthDelta = 0;
|
||||
while (block.isValid()) {
|
||||
bool cleared = false;
|
||||
bool set = false;
|
||||
if (rangeNumber < blocks.size()) {
|
||||
const BlockRange &range = blocks.at(rangeNumber);
|
||||
if (block.position() >= range.first()
|
||||
&& ((block.position() + block.length() - 1) <= range.last() || !range.last()))
|
||||
set = TextDocumentLayout::setIfdefedOut(block);
|
||||
else
|
||||
cleared = TextDocumentLayout::clearIfdefedOut(block);
|
||||
if (block.contains(range.last()))
|
||||
++rangeNumber;
|
||||
} else {
|
||||
cleared = TextDocumentLayout::clearIfdefedOut(block);
|
||||
}
|
||||
|
||||
if (cleared || set) {
|
||||
needUpdate = true;
|
||||
int delta = TextDocumentLayout::braceDepthDelta(block);
|
||||
if (cleared)
|
||||
braceDepthDelta += delta;
|
||||
else if (set)
|
||||
braceDepthDelta -= delta;
|
||||
}
|
||||
|
||||
if (braceDepthDelta) {
|
||||
qCDebug(Internal::foldingLog)
|
||||
<< "changing brace depth and folding indent by" << braceDepthDelta << "for line"
|
||||
<< (block.blockNumber() + 1) << "due to ifdefed out code";
|
||||
TextDocumentLayout::changeBraceDepth(block,braceDepthDelta);
|
||||
TextDocumentLayout::changeFoldingIndent(block, braceDepthDelta); // ### C++ only, refactor!
|
||||
}
|
||||
|
||||
block = block.next();
|
||||
}
|
||||
|
||||
if (needUpdate)
|
||||
documentLayout->requestUpdate();
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
emit ifdefedOutBlocksChanged(blocks);
|
||||
#endif
|
||||
}
|
||||
|
||||
const ExtraEncodingSettings &TextDocument::extraEncodingSettings() const
|
||||
{
|
||||
return d->m_extraEncodingSettings;
|
||||
|
||||
Reference in New Issue
Block a user