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:
@@ -9,18 +9,18 @@
|
||||
#include "clangmodelmanagersupport.h"
|
||||
#include "tasktimers.h"
|
||||
|
||||
#include <cppeditor/cppeditorwidget.h>
|
||||
#include <cppeditor/semantichighlighter.h>
|
||||
#include <languageclient/languageclientmanager.h>
|
||||
#include <languageclient/semantichighlightsupport.h>
|
||||
#include <languageserverprotocol/lsptypes.h>
|
||||
#include <texteditor/blockrange.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/textstyles.h>
|
||||
|
||||
#include <QtConcurrent>
|
||||
#include <QTextDocument>
|
||||
|
||||
#include <new>
|
||||
|
||||
using namespace LanguageClient;
|
||||
using namespace LanguageServerProtocol;
|
||||
using namespace TextEditor;
|
||||
@@ -256,6 +256,10 @@ void handleInactiveRegions(LanguageClient::Client *client, const JsonRpcMessage
|
||||
params->uri().toFilePath(client->hostPathMapper()));
|
||||
if (!doc)
|
||||
return;
|
||||
const auto editorWidget = CppEditor::CppEditorWidget::fromTextDocument(doc);
|
||||
if (!editorWidget)
|
||||
return;
|
||||
|
||||
const QList<Range> inactiveRegions = params->inactiveRegions();
|
||||
QList<BlockRange> ifdefedOutBlocks;
|
||||
for (const Range &r : inactiveRegions) {
|
||||
@@ -263,7 +267,7 @@ void handleInactiveRegions(LanguageClient::Client *client, const JsonRpcMessage
|
||||
const int endPos = r.end().toPositionInDocument(doc->document()) + 1;
|
||||
ifdefedOutBlocks.emplaceBack(startPos, endPos);
|
||||
}
|
||||
doc->setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
editorWidget->setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
}
|
||||
|
||||
QString inactiveRegionsMethodName()
|
||||
|
@@ -835,7 +835,9 @@ void ClangdTestHighlighting::initTestCase()
|
||||
{
|
||||
ClangdTest::initTestCase();
|
||||
|
||||
connect(document("highlighting.cpp"), &TextDocument::ifdefedOutBlocksChanged, this,
|
||||
using CppEditor::CppEditorWidget;
|
||||
connect(CppEditorWidget::fromTextDocument(document("highlighting.cpp")),
|
||||
&CppEditorWidget::ifdefedOutBlocksChanged, this,
|
||||
[this](const QList<BlockRange> &ranges) { m_ifdefedOutBlocks = ranges; });
|
||||
QTimer timer;
|
||||
timer.setSingleShot(true);
|
||||
|
@@ -38,6 +38,7 @@ add_qtc_plugin(CppEditor
|
||||
cppeditortr.h
|
||||
cppeditorconstants.h
|
||||
cppeditordocument.cpp cppeditordocument.h
|
||||
cppeditorlogging.cpp cppeditorlogging.h
|
||||
cppeditoroutline.cpp cppeditoroutline.h
|
||||
cppeditorplugin.cpp
|
||||
cppeditorwidget.cpp cppeditorwidget.h
|
||||
|
@@ -84,6 +84,8 @@ QtcPlugin {
|
||||
"cppdoxygen.cpp",
|
||||
"cppdoxygen.h",
|
||||
"cppdoxygen.kwgen",
|
||||
"cppeditorlogging.cpp",
|
||||
"cppeditorlogging.h",
|
||||
"cppeditorwidget.cpp",
|
||||
"cppeditorwidget.h",
|
||||
"cppeditor.qrc",
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "baseeditordocumentparser.h"
|
||||
#include "cppcodeformatter.h"
|
||||
#include "cppeditorconstants.h"
|
||||
#include "cppeditorlogging.h"
|
||||
#include "cppeditortr.h"
|
||||
#include "cppmodelmanager.h"
|
||||
#include "cppeditorconstants.h"
|
||||
@@ -307,6 +308,64 @@ void CppEditorDocument::setExtraPreprocessorDirectives(const QByteArray &directi
|
||||
}
|
||||
}
|
||||
|
||||
void CppEditorDocument::setIfdefedOutBlocks(const QList<TextEditor::BlockRange> &blocks)
|
||||
{
|
||||
if (syntaxHighlighter() && syntaxHighlighter()->syntaxHighlighterUpToDate()) {
|
||||
connect(syntaxHighlighter(),
|
||||
&SyntaxHighlighter::finished,
|
||||
this,
|
||||
[this, blocks] { setIfdefedOutBlocks(blocks); },
|
||||
Qt::SingleShotConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
auto documentLayout = qobject_cast<TextDocumentLayout*>(document()->documentLayout());
|
||||
QTC_ASSERT(documentLayout, return);
|
||||
|
||||
QTextBlock block = document()->firstBlock();
|
||||
bool needUpdate = false;
|
||||
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(highlighterLog)
|
||||
<< "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();
|
||||
}
|
||||
|
||||
void CppEditorDocument::setPreferredParseContext(const QString &parseContextId)
|
||||
{
|
||||
const BaseEditorDocumentParser::Ptr parser = processor()->parser();
|
||||
|
@@ -38,6 +38,9 @@ public:
|
||||
void setPreferredParseContext(const QString &parseContextId);
|
||||
void setExtraPreprocessorDirectives(const QByteArray &directives);
|
||||
|
||||
// the blocks list must be sorted
|
||||
void setIfdefedOutBlocks(const QList<TextEditor::BlockRange> &blocks);
|
||||
|
||||
void scheduleProcessDocument();
|
||||
|
||||
ParseContextModel &parseContextModel();
|
||||
|
10
src/plugins/cppeditor/cppeditorlogging.cpp
Normal file
10
src/plugins/cppeditor/cppeditorlogging.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "cppeditorlogging.h"
|
||||
|
||||
namespace CppEditor::Internal {
|
||||
|
||||
Q_LOGGING_CATEGORY(highlighterLog, "qtc.cppeditor.syntaxhighlighter", QtWarningMsg)
|
||||
|
||||
} // namespace CppEditor::Internal
|
11
src/plugins/cppeditor/cppeditorlogging.h
Normal file
11
src/plugins/cppeditor/cppeditorlogging.h
Normal file
@@ -0,0 +1,11 @@
|
||||
// Copyright (C) 2024 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
#pragma once
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
namespace CppEditor::Internal {
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(highlighterLog)
|
||||
|
||||
} // namespace CppEditor::Internal
|
@@ -44,6 +44,7 @@
|
||||
#include <texteditor/completionsettings.h>
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/refactoroverlay.h>
|
||||
#include <texteditor/syntaxhighlighter.h>
|
||||
#include <texteditor/textdocument.h>
|
||||
#include <texteditor/textdocumentlayout.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
@@ -419,6 +420,17 @@ CppEditorWidget::CppEditorWidget()
|
||||
qRegisterMetaType<SemanticInfo>("SemanticInfo");
|
||||
}
|
||||
|
||||
CppEditorWidget *CppEditorWidget::fromTextDocument(TextEditor::TextDocument *doc)
|
||||
{
|
||||
const QVector<BaseTextEditor *> editors = BaseTextEditor::textEditorsForDocument(doc);
|
||||
for (BaseTextEditor * const editor : editors) {
|
||||
if (const auto editorWidget = qobject_cast<CppEditor::CppEditorWidget *>(
|
||||
editor->editorWidget()))
|
||||
return editorWidget;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CppEditorWidget::finalizeInitialization()
|
||||
{
|
||||
d->m_cppEditorDocument = qobject_cast<CppEditorDocument *>(textDocument());
|
||||
@@ -594,7 +606,7 @@ void CppEditorWidget::onIfdefedOutBlocksUpdated(unsigned revision,
|
||||
{
|
||||
if (revision != documentRevision())
|
||||
return;
|
||||
textDocument()->setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
}
|
||||
|
||||
void CppEditorWidget::findUsages()
|
||||
@@ -1484,6 +1496,14 @@ const QList<QTextEdit::ExtraSelection> CppEditorWidget::unselectLeadingWhitespac
|
||||
return filtered;
|
||||
}
|
||||
|
||||
void CppEditorWidget::setIfdefedOutBlocks(const QList<TextEditor::BlockRange> &blocks)
|
||||
{
|
||||
cppEditorDocument()->setIfdefedOutBlocks(blocks);
|
||||
#ifdef WITH_TESTS
|
||||
emit ifdefedOutBlocksChanged(blocks);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CppEditorWidget::isInTestMode() const { return d->inTestMode; }
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include <functional>
|
||||
|
||||
namespace TextEditor {
|
||||
class BlockRange;
|
||||
class IAssistProposal;
|
||||
class IAssistProvider;
|
||||
}
|
||||
@@ -37,6 +38,8 @@ public:
|
||||
CppEditorWidget();
|
||||
~CppEditorWidget() override;
|
||||
|
||||
static CppEditorWidget *fromTextDocument(TextEditor::TextDocument *doc);
|
||||
|
||||
Internal::CppEditorDocument *cppEditorDocument() const;
|
||||
|
||||
bool isSemanticInfoValidExceptLocalUses() const;
|
||||
@@ -83,6 +86,8 @@ public:
|
||||
static const QList<QTextEdit::ExtraSelection>
|
||||
unselectLeadingWhitespace(const QList<QTextEdit::ExtraSelection> &selections);
|
||||
|
||||
void setIfdefedOutBlocks(const QList<TextEditor::BlockRange> &blocks);
|
||||
|
||||
bool isInTestMode() const;
|
||||
void setProposals(const TextEditor::IAssistProposal *immediateProposal,
|
||||
const TextEditor::IAssistProposal *finalProposal);
|
||||
@@ -91,6 +96,7 @@ public:
|
||||
signals:
|
||||
void proposalsReady(const TextEditor::IAssistProposal *immediateProposal,
|
||||
const TextEditor::IAssistProposal *finalProposal);
|
||||
void ifdefedOutBlocksChanged(const QList<TextEditor::BlockRange> &blocks);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "cpphighlighter.h"
|
||||
|
||||
#include "cppdoxygen.h"
|
||||
#include "cppeditorlogging.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
@@ -15,7 +16,6 @@
|
||||
#include <cplusplus/Lexer.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QLoggingCategory>
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextDocument>
|
||||
#include <QTextLayout>
|
||||
@@ -28,8 +28,7 @@ using namespace TextEditor;
|
||||
using namespace CPlusPlus;
|
||||
|
||||
namespace CppEditor {
|
||||
|
||||
static Q_LOGGING_CATEGORY(log, "qtc.cppeditor.syntaxhighlighter", QtWarningMsg)
|
||||
using namespace Internal;
|
||||
|
||||
CppHighlighter::CppHighlighter(QTextDocument *document) :
|
||||
SyntaxHighlighter(document)
|
||||
@@ -39,16 +38,17 @@ CppHighlighter::CppHighlighter(QTextDocument *document) :
|
||||
|
||||
void CppHighlighter::highlightBlock(const QString &text)
|
||||
{
|
||||
qCDebug(log) << "highlighting line" << (currentBlock().blockNumber() + 1);
|
||||
qCDebug(highlighterLog) << "highlighting line" << (currentBlock().blockNumber() + 1);
|
||||
|
||||
const int previousBlockState_ = previousBlockState();
|
||||
int lexerState = 0, initialBraceDepth = 0;
|
||||
if (previousBlockState_ != -1) {
|
||||
lexerState = previousBlockState_ & 0xff;
|
||||
initialBraceDepth = previousBlockState_ >> 8;
|
||||
qCDebug(log) << "initial brace depth carried over from previous block" << initialBraceDepth;
|
||||
qCDebug(highlighterLog) << "initial brace depth carried over from previous block"
|
||||
<< initialBraceDepth;
|
||||
} else {
|
||||
qCDebug(log) << "initial brace depth 0";
|
||||
qCDebug(highlighterLog) << "initial brace depth 0";
|
||||
}
|
||||
|
||||
int braceDepth = initialBraceDepth;
|
||||
@@ -69,9 +69,9 @@ void CppHighlighter::highlightBlock(const QString &text)
|
||||
static const auto lexerStateWithoutNewLineExpectedBit = [](int state) { return state & ~0x80; };
|
||||
initialLexerState = lexerStateWithoutNewLineExpectedBit(initialLexerState);
|
||||
int foldingIndent = initialBraceDepth;
|
||||
qCDebug(log) << "folding indent initialized to brace depth" << foldingIndent;
|
||||
qCDebug(highlighterLog) << "folding indent initialized to brace depth" << foldingIndent;
|
||||
if (TextBlockUserData *userData = TextDocumentLayout::textUserData(currentBlock())) {
|
||||
qCDebug(log) << "resetting stored folding data for current block";
|
||||
qCDebug(highlighterLog) << "resetting stored folding data for current block";
|
||||
userData->setFoldingIndent(0);
|
||||
userData->setFoldingStartIncluded(false);
|
||||
userData->setFoldingEndIncluded(false);
|
||||
@@ -90,7 +90,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
||||
}
|
||||
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
|
||||
TextDocumentLayout::setExpectedRawStringSuffix(currentBlock(), inheritedRawStringSuffix);
|
||||
qCDebug(log) << "no tokens, storing brace depth" << braceDepth << "and foldingIndent"
|
||||
qCDebug(highlighterLog) << "no tokens, storing brace depth" << braceDepth << "and foldingIndent"
|
||||
<< foldingIndent;
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
||||
insertParen({Parenthesis::Opened, c, tk.utf16charsBegin()});
|
||||
if (tk.is(T_LBRACE)) {
|
||||
++braceDepth;
|
||||
qCDebug(log) << "encountered opening brace, increasing brace depth to" << braceDepth;
|
||||
qCDebug(highlighterLog) << "encountered opening brace, increasing brace depth to" << braceDepth;
|
||||
|
||||
// if a folding block opens at the beginning of a line, treat the line before
|
||||
// as if it were inside the folding block except if it is a comment or the line does
|
||||
@@ -147,7 +147,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
||||
&& tk.utf16charsBegin() == firstNonSpace) {
|
||||
++foldingIndent;
|
||||
TextDocumentLayout::userData(currentBlock())->setFoldingStartIncluded(true);
|
||||
qCDebug(log)
|
||||
qCDebug(highlighterLog)
|
||||
<< "folding character is first on one line, increase folding indent to"
|
||||
<< foldingIndent << "and set foldingStartIncluded in stored data";
|
||||
}
|
||||
@@ -157,16 +157,16 @@ void CppHighlighter::highlightBlock(const QString &text)
|
||||
insertParen({Parenthesis::Closed, c, tk.utf16charsBegin()});
|
||||
if (tk.is(T_RBRACE)) {
|
||||
--braceDepth;
|
||||
qCDebug(log) << "encountered closing brace, decreasing brace depth to" << braceDepth;
|
||||
qCDebug(highlighterLog) << "encountered closing brace, decreasing brace depth to" << braceDepth;
|
||||
if (braceDepth < foldingIndent) {
|
||||
// unless we are at the end of the block, we reduce the folding indent
|
||||
if (isLastToken || tokens.at(i + 1).is(T_SEMICOLON)) {
|
||||
qCDebug(log) << "token is last token in statement or line, setting "
|
||||
qCDebug(highlighterLog) << "token is last token in statement or line, setting "
|
||||
"foldingEndIncluded in stored data";
|
||||
TextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true);
|
||||
} else {
|
||||
foldingIndent = qMin(braceDepth, foldingIndent);
|
||||
qCDebug(log) << "setting folding indent to minimum of current value and "
|
||||
qCDebug(highlighterLog) << "setting folding indent to minimum of current value and "
|
||||
"brace depth, which is"
|
||||
<< foldingIndent;
|
||||
}
|
||||
@@ -218,17 +218,17 @@ void CppHighlighter::highlightBlock(const QString &text)
|
||||
if (initialLexerState && i == 0 && (tk.is(T_COMMENT) || tk.is(T_DOXY_COMMENT))
|
||||
&& (tokens.size() > 1 || !lexerState)) {
|
||||
--braceDepth;
|
||||
qCDebug(log)
|
||||
qCDebug(highlighterLog)
|
||||
<< "encountered some comment-related condition, decreasing brace depth to"
|
||||
<< braceDepth;
|
||||
// unless we are at the end of the block, we reduce the folding indent
|
||||
if (isLastToken) {
|
||||
qCDebug(log) << "token is last token on line, setting "
|
||||
qCDebug(highlighterLog) << "token is last token on line, setting "
|
||||
"foldingEndIncluded in stored data";
|
||||
TextDocumentLayout::userData(currentBlock())->setFoldingEndIncluded(true);
|
||||
} else {
|
||||
foldingIndent = qMin(braceDepth, foldingIndent);
|
||||
qCDebug(log) << "setting folding indent to minimum of current value and "
|
||||
qCDebug(highlighterLog) << "setting folding indent to minimum of current value and "
|
||||
"brace depth, which is"
|
||||
<< foldingIndent;
|
||||
}
|
||||
@@ -272,7 +272,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
||||
if (lastToken.is(T_COMMENT) || lastToken.is(T_DOXY_COMMENT)) {
|
||||
insertParen({Parenthesis::Opened, QLatin1Char('+'), lastToken.utf16charsBegin()});
|
||||
++braceDepth;
|
||||
qCDebug(log)
|
||||
qCDebug(highlighterLog)
|
||||
<< "encountered some comment-related condition, increasing brace depth to"
|
||||
<< braceDepth;
|
||||
}
|
||||
@@ -286,13 +286,13 @@ void CppHighlighter::highlightBlock(const QString &text)
|
||||
userData && userData->ifdefedOut()) {
|
||||
braceDepth = initialBraceDepth;
|
||||
foldingIndent = initialBraceDepth;
|
||||
qCDebug(log) << "block is ifdefed out, resetting brace depth and folding indent to"
|
||||
qCDebug(highlighterLog) << "block is ifdefed out, resetting brace depth and folding indent to"
|
||||
<< initialBraceDepth;
|
||||
}
|
||||
|
||||
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
|
||||
setCurrentBlockState((braceDepth << 8) | tokenize.state());
|
||||
qCDebug(log) << "storing brace depth" << braceDepth << "and folding indent" << foldingIndent;
|
||||
qCDebug(highlighterLog) << "storing brace depth" << braceDepth << "and folding indent" << foldingIndent;
|
||||
|
||||
TextDocumentLayout::setExpectedRawStringSuffix(currentBlock(),
|
||||
tokenize.expectedRawStringSuffix());
|
||||
|
@@ -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;
|
||||
|
@@ -84,9 +84,6 @@ public:
|
||||
void autoFormat(const QTextCursor &cursor);
|
||||
bool applyChangeSet(const Utils::ChangeSet &changeSet);
|
||||
|
||||
// the blocks list must be sorted
|
||||
void setIfdefedOutBlocks(const QList<BlockRange> &blocks);
|
||||
|
||||
TextMarks marks() const;
|
||||
bool addMark(TextMark *mark);
|
||||
TextMarks marksAt(int line) const;
|
||||
@@ -162,10 +159,6 @@ signals:
|
||||
void fontSettingsChanged();
|
||||
void markRemoved(TextMark *mark);
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
void ifdefedOutBlocksChanged(const QList<BlockRange> &blocks);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void applyFontSettings();
|
||||
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
||||
|
Reference in New Issue
Block a user