aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2024-02-29 12:44:58 +0100
committerEike Ziller <eike.ziller@qt.io>2024-02-29 12:44:58 +0100
commit6c2df76737b49019d51eda0fd757f0721d3e7d82 (patch)
treeb3d5fbebcc28f57c7f57c041a634590e6b152582 /src/plugins/texteditor
parent5af531cd39067366cea627e3db1a0b83d7172873 (diff)
parent49ab0c41097cb9165274cc4daad651133547794e (diff)
Merge remote-tracking branch 'origin/13.0'
Conflicts: src/plugins/android/androidsettingswidget.cpp Change-Id: Ifcb16aa16c7bc2792de25d0ee7a22cf0e39a05f8
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/fontsettings.cpp5
-rw-r--r--src/plugins/texteditor/fontsettings.h2
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.cpp18
-rw-r--r--src/plugins/texteditor/syntaxhighlighter.h36
-rw-r--r--src/plugins/texteditor/syntaxhighlighterrunner.cpp13
-rw-r--r--src/plugins/texteditor/syntaxhighlighterrunner.h1
-rw-r--r--src/plugins/texteditor/texteditor.cpp74
-rw-r--r--src/plugins/texteditor/texteditor.h1
8 files changed, 105 insertions, 45 deletions
diff --git a/src/plugins/texteditor/fontsettings.cpp b/src/plugins/texteditor/fontsettings.cpp
index 5b79514d92..e74a37c0d3 100644
--- a/src/plugins/texteditor/fontsettings.cpp
+++ b/src/plugins/texteditor/fontsettings.cpp
@@ -356,13 +356,14 @@ QFont FontSettings::font() const
{
QFont f(family(), fontSize());
f.setStyleStrategy(m_antialias ? QFont::PreferAntialias : QFont::NoAntialias);
+ f.setWeight(fontNormalWeight());
return f;
}
-int FontSettings::fontNormalWeight() const
+QFont::Weight FontSettings::fontNormalWeight() const
{
// TODO: Fix this when we upgrade "Source Code Pro" to a version greater than 2.0.30
- int weight = QFont::Normal;
+ QFont::Weight weight = QFont::Normal;
if (Utils::HostOsInfo::isMacHost() && m_family == g_sourceCodePro)
weight = QFont::Medium;
return weight;
diff --git a/src/plugins/texteditor/fontsettings.h b/src/plugins/texteditor/fontsettings.h
index 338948d9e9..2cf23ec5a3 100644
--- a/src/plugins/texteditor/fontsettings.h
+++ b/src/plugins/texteditor/fontsettings.h
@@ -61,7 +61,7 @@ public:
void setRelativeLineSpacing(int relativeLineSpacing);
QFont font() const;
- int fontNormalWeight() const;
+ QFont::Weight fontNormalWeight() const;
bool antialias() const;
void setAntialias(bool antialias);
diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp
index 0ed00af389..34f4b1c777 100644
--- a/src/plugins/texteditor/syntaxhighlighter.cpp
+++ b/src/plugins/texteditor/syntaxhighlighter.cpp
@@ -81,6 +81,10 @@ void SyntaxHighlighter::delayedRehighlight()
if (!d->rehighlightPending)
return;
d->rehighlightPending = false;
+
+ if (document()->isEmpty())
+ return;
+
rehighlight();
}
@@ -197,6 +201,10 @@ void SyntaxHighlighterPrivate::reformatBlocks(int from, int charsRemoved, int ch
QList<SyntaxHighlighter::Result> vecRes;
+ SyntaxHighlighter::Result resStart;
+ resStart.m_state = SyntaxHighlighter::State::Start;
+ vecRes << resStart;
+
while (block.isValid() && (block.position() < endPosition || forceHighlightOfNextBlock)) {
if (QThread::currentThread()->isInterruptionRequested())
break;
@@ -758,7 +766,10 @@ void SyntaxHighlighter::setExtraFormats(const QTextBlock &block,
SyntaxHighlighter::Result res;
res.m_formatRanges = block.layout()->formats();
res.fillByBlock(block);
- emit resultsReady({res});
+ res.m_state = SyntaxHighlighter::State::Extras;
+ SyntaxHighlighter::Result resDone;
+ resDone.m_state = SyntaxHighlighter::State::Done;
+ emit resultsReady({res, resDone});
document()->markContentsDirty(block.position(), blockLength - 1);
d->inReformatBlocks = wasInReformatBlocks;
@@ -784,7 +795,10 @@ void SyntaxHighlighter::clearExtraFormats(const QTextBlock &block)
SyntaxHighlighter::Result res;
res.m_formatRanges = block.layout()->formats();
res.fillByBlock(block);
- emit resultsReady({res});
+ res.m_state = SyntaxHighlighter::State::Extras;
+ SyntaxHighlighter::Result resDone;
+ resDone.m_state = SyntaxHighlighter::State::Done;
+ emit resultsReady({res, resDone});
document()->markContentsDirty(block.position(), blockLength - 1);
d->inReformatBlocks = wasInReformatBlocks;
diff --git a/src/plugins/texteditor/syntaxhighlighter.h b/src/plugins/texteditor/syntaxhighlighter.h
index 94cee8a65e..533c628b9c 100644
--- a/src/plugins/texteditor/syntaxhighlighter.h
+++ b/src/plugins/texteditor/syntaxhighlighter.h
@@ -53,8 +53,10 @@ public:
virtual void setFontSettings(const TextEditor::FontSettings &fontSettings);
TextEditor::FontSettings fontSettings() const;
- enum State {
+ enum State {
+ Start,
InProgress,
+ Extras,
Done
};
@@ -71,7 +73,6 @@ public:
m_hasBlockUserData = true;
m_foldingIndent = userDate->foldingIndent();
- m_folded = userDate->folded();
m_ifdefedOut = userDate->ifdefedOut();
m_foldingStartIncluded = userDate->foldingStartIncluded();
m_foldingEndIncluded = userDate->foldingEndIncluded();
@@ -83,28 +84,27 @@ public:
{
block.setUserState(m_userState);
- if (m_hasBlockUserData) {
- TextBlockUserData *data = TextDocumentLayout::userData(block);
- data->setExpectedRawStringSuffix(m_expectedRawStringSuffix);
- data->setFolded(m_folded);
- data->setFoldingIndent(m_foldingIndent);
- data->setFoldingStartIncluded(m_foldingStartIncluded);
- data->setFoldingEndIncluded(m_foldingEndIncluded);
-
- if (m_ifdefedOut)
- data->setIfdefedOut();
- else
- data->clearIfdefedOut();
-
- data->setParentheses(m_parentheses);
- }
+ if (!m_hasBlockUserData)
+ return;
+
+ TextBlockUserData *data = TextDocumentLayout::userData(block);
+ data->setExpectedRawStringSuffix(m_expectedRawStringSuffix);
+ data->setFoldingIndent(m_foldingIndent);
+ data->setFoldingStartIncluded(m_foldingStartIncluded);
+ data->setFoldingEndIncluded(m_foldingEndIncluded);
+
+ if (m_ifdefedOut)
+ data->setIfdefedOut();
+ else
+ data->clearIfdefedOut();
+
+ data->setParentheses(m_parentheses);
}
int m_blockNumber;
bool m_hasBlockUserData = false;
int m_foldingIndent : 16;
- uint m_folded : 1;
uint m_ifdefedOut : 1;
uint m_foldingStartIncluded : 1;
uint m_foldingEndIncluded : 1;
diff --git a/src/plugins/texteditor/syntaxhighlighterrunner.cpp b/src/plugins/texteditor/syntaxhighlighterrunner.cpp
index bf53d90561..228b866849 100644
--- a/src/plugins/texteditor/syntaxhighlighterrunner.cpp
+++ b/src/plugins/texteditor/syntaxhighlighterrunner.cpp
@@ -100,7 +100,6 @@ public:
SyntaxHighlighter *m_highlighter = nullptr;
QTextDocument *m_document = nullptr;
-
signals:
void resultsReady(const QList<SyntaxHighlighter::Result> &result);
@@ -130,6 +129,8 @@ SyntaxHighlighterRunner::SyntaxHighlighterRunner(SyntaxHighlighter *highlighter,
&QTextDocument::contentsChange,
this,
&SyntaxHighlighterRunner::changeDocument);
+
+ m_foldValidator.setup(qobject_cast<TextDocumentLayout *>(document->documentLayout()));
} else {
connect(d,
&SyntaxHighlighterRunnerPrivate::resultsReady,
@@ -169,7 +170,12 @@ void SyntaxHighlighterRunner::applyFormatRanges(const QList<SyntaxHighlighter::R
for (const SyntaxHighlighter::Result &result : results) {
m_syntaxInfoUpdated = result.m_state;
+ if (m_syntaxInfoUpdated == SyntaxHighlighter::State::Start) {
+ m_foldValidator.reset();
+ continue;
+ }
if (m_syntaxInfoUpdated == SyntaxHighlighter::State::Done) {
+ m_foldValidator.finalize();
emit highlightingFinished();
return;
}
@@ -181,12 +187,11 @@ void SyntaxHighlighterRunner::applyFormatRanges(const QList<SyntaxHighlighter::R
result.copyToBlock(docBlock);
if (result.m_formatRanges != docBlock.layout()->formats()) {
- TextDocumentLayout::FoldValidator foldValidator;
- foldValidator.setup(qobject_cast<TextDocumentLayout *>(m_document->documentLayout()));
docBlock.layout()->setFormats(result.m_formatRanges);
m_document->markContentsDirty(docBlock.position(), docBlock.length());
- foldValidator.process(docBlock);
}
+ if (m_syntaxInfoUpdated != SyntaxHighlighter::State::Extras)
+ m_foldValidator.process(docBlock);
}
}
diff --git a/src/plugins/texteditor/syntaxhighlighterrunner.h b/src/plugins/texteditor/syntaxhighlighterrunner.h
index ccb292ea08..5540bd666a 100644
--- a/src/plugins/texteditor/syntaxhighlighterrunner.h
+++ b/src/plugins/texteditor/syntaxhighlighterrunner.h
@@ -56,6 +56,7 @@ private:
bool m_useGenericHighlighter = false;
QString m_definitionName;
std::optional<QThread> m_thread;
+ TextDocumentLayout::FoldValidator m_foldValidator;
};
} // namespace TextEditor
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 70239b286e..baf027d124 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -3492,13 +3492,36 @@ QByteArray TextEditorWidget::saveState() const
return state;
}
+bool TextEditorWidget::singleShotAfterHighlightingDone(std::function<void()> &&f)
+{
+ if (d->m_document->syntaxHighlighterRunner()
+ && !d->m_document->syntaxHighlighterRunner()->syntaxInfoUpdated()) {
+ connect(d->m_document->syntaxHighlighterRunner(),
+ &SyntaxHighlighterRunner::highlightingFinished,
+ this,
+ [f = std::move(f)] { f(); }, Qt::SingleShotConnection);
+ return true;
+ }
+ return false;
+}
+
void TextEditorWidget::restoreState(const QByteArray &state)
{
+ const auto callFoldLicenseHeader = [this] {
+ auto callFold = [this] {
+ if (d->m_displaySettings.m_autoFoldFirstComment)
+ d->foldLicenseHeader();
+ };
+
+ if (!singleShotAfterHighlightingDone(callFold))
+ callFold();
+ };
+
if (state.isEmpty()) {
- if (d->m_displaySettings.m_autoFoldFirstComment)
- d->foldLicenseHeader();
+ callFoldLicenseHeader();
return;
}
+
int version;
int vval;
int hval;
@@ -3514,24 +3537,27 @@ void TextEditorWidget::restoreState(const QByteArray &state)
if (version >= 1) {
QList<int> collapsedBlocks;
stream >> collapsedBlocks;
- QTextDocument *doc = document();
- bool layoutChanged = false;
- for (const int blockNumber : std::as_const(collapsedBlocks)) {
- QTextBlock block = doc->findBlockByNumber(qMax(0, blockNumber));
- if (block.isValid()) {
- TextDocumentLayout::doFoldOrUnfold(block, false);
- layoutChanged = true;
+ auto foldingRestore = [this, collapsedBlocks] {
+ QTextDocument *doc = document();
+ bool layoutChanged = false;
+ for (const int blockNumber : std::as_const(collapsedBlocks)) {
+ QTextBlock block = doc->findBlockByNumber(qMax(0, blockNumber));
+ if (block.isValid()) {
+ TextDocumentLayout::doFoldOrUnfold(block, false);
+ layoutChanged = true;
+ }
}
- }
- if (layoutChanged) {
- auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
- QTC_ASSERT(documentLayout, return );
- documentLayout->requestUpdate();
- documentLayout->emitDocumentSizeChanged();
- }
+ if (layoutChanged) {
+ auto documentLayout = qobject_cast<TextDocumentLayout *>(doc->documentLayout());
+ QTC_ASSERT(documentLayout, return);
+ documentLayout->requestUpdate();
+ documentLayout->emitDocumentSizeChanged();
+ }
+ };
+ if (!singleShotAfterHighlightingDone(foldingRestore))
+ foldingRestore();
} else {
- if (d->m_displaySettings.m_autoFoldFirstComment)
- d->foldLicenseHeader();
+ callFoldLicenseHeader();
}
d->m_lastCursorChangeWasInteresting = false; // avoid adding last position to history
@@ -6642,6 +6668,9 @@ void TextEditorWidget::ensureCursorVisible()
void TextEditorWidget::ensureBlockIsUnfolded(QTextBlock block)
{
+ if (singleShotAfterHighlightingDone([this, block] { ensureBlockIsUnfolded(block); }))
+ return;
+
if (!block.isVisible()) {
auto documentLayout = qobject_cast<TextDocumentLayout*>(document()->documentLayout());
QTC_ASSERT(documentLayout, return);
@@ -8215,6 +8244,9 @@ void TextEditorWidget::foldCurrentBlock()
void TextEditorWidget::fold(const QTextBlock &block)
{
+ if (singleShotAfterHighlightingDone([this, block] { fold(block); }))
+ return;
+
QTextDocument *doc = document();
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
QTC_ASSERT(documentLayout, return);
@@ -8235,6 +8267,9 @@ void TextEditorWidget::fold(const QTextBlock &block)
void TextEditorWidget::unfold(const QTextBlock &block)
{
+ if (singleShotAfterHighlightingDone([this, block] { unfold(block); }))
+ return;
+
QTextDocument *doc = document();
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
QTC_ASSERT(documentLayout, return);
@@ -8254,6 +8289,9 @@ void TextEditorWidget::unfoldCurrentBlock()
void TextEditorWidget::unfoldAll()
{
+ if (singleShotAfterHighlightingDone([this] { unfoldAll(); }))
+ return;
+
QTextDocument *doc = document();
auto documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
QTC_ASSERT(documentLayout, return);
diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h
index 33b8cb84f0..85344a8dbd 100644
--- a/src/plugins/texteditor/texteditor.h
+++ b/src/plugins/texteditor/texteditor.h
@@ -645,6 +645,7 @@ private:
friend class Internal::TextEditorOverlay;
friend class RefactorOverlay;
+ bool singleShotAfterHighlightingDone(std::function<void()> &&f);
void updateVisualWrapColumn();
};