forked from qt-creator/qt-creator
TextEditor: simplify SyntaxHighlighterRunner::cloneDocument
Change-Id: I2cf2673bd79dd92de43392dc890f4f7482b483f6 Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
This commit is contained in:
@@ -42,7 +42,7 @@ public:
|
||||
&SyntaxHighlighterRunnerPrivate::resultsReady);
|
||||
}
|
||||
|
||||
void cloneDocument(int from,
|
||||
void changeDocument(int from,
|
||||
int charsRemoved,
|
||||
const QString textAdded,
|
||||
const QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> &blocksPreedit)
|
||||
@@ -156,8 +156,9 @@ void BaseSyntaxHighlighterRunner::applyFormatRanges(const SyntaxHighlighter::Res
|
||||
}
|
||||
}
|
||||
|
||||
void BaseSyntaxHighlighterRunner::cloneDocumentData(int from, int charsRemoved, int charsAdded)
|
||||
void BaseSyntaxHighlighterRunner::changeDocument(int from, int charsRemoved, int charsAdded)
|
||||
{
|
||||
QTC_ASSERT(m_document, return);
|
||||
m_syntaxInfoUpdated = SyntaxHighlighter::State::InProgress;
|
||||
QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> blocksPreedit;
|
||||
QTextBlock block = m_document->findBlock(from);
|
||||
@@ -170,16 +171,8 @@ void BaseSyntaxHighlighterRunner::cloneDocumentData(int from, int charsRemoved,
|
||||
block = block.next();
|
||||
}
|
||||
const QString text = Utils::Text::textAt(QTextCursor(m_document), from, charsAdded);
|
||||
cloneDocument(from, charsRemoved, text, blocksPreedit);
|
||||
}
|
||||
|
||||
void BaseSyntaxHighlighterRunner::cloneDocument(int from,
|
||||
int charsRemoved,
|
||||
const QString textAdded,
|
||||
const QMap<int, BlockPreeditData> &blocksPreedit)
|
||||
{
|
||||
QMetaObject::invokeMethod(d.get(), [this, from, charsRemoved, textAdded, blocksPreedit] {
|
||||
d->cloneDocument(from, charsRemoved, textAdded, blocksPreedit);
|
||||
QMetaObject::invokeMethod(d.get(), [this, from, charsRemoved, text, blocksPreedit] {
|
||||
d->changeDocument(from, charsRemoved, text, blocksPreedit);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -254,16 +247,11 @@ ThreadedSyntaxHighlighterRunner::ThreadedSyntaxHighlighterRunner(SyntaxHighLight
|
||||
applyFormatRanges(res);
|
||||
});
|
||||
|
||||
cloneDocumentData(0, 0, document->characterCount());
|
||||
changeDocument(0, 0, document->characterCount());
|
||||
connect(document,
|
||||
&QTextDocument::contentsChange,
|
||||
this,
|
||||
[this](int from, int charsRemoved, int charsAdded) {
|
||||
if (!this->document())
|
||||
return;
|
||||
|
||||
cloneDocumentData(from, charsRemoved, charsAdded);
|
||||
});
|
||||
&ThreadedSyntaxHighlighterRunner::changeDocument);
|
||||
}
|
||||
|
||||
ThreadedSyntaxHighlighterRunner::~ThreadedSyntaxHighlighterRunner()
|
||||
|
||||
@@ -58,11 +58,7 @@ protected:
|
||||
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
||||
QPointer<QTextDocument> m_document = nullptr;
|
||||
void applyFormatRanges(const SyntaxHighlighter::Result &result);
|
||||
void cloneDocumentData(int from, int charsRemoved, int charsAdded);
|
||||
void cloneDocument(int from,
|
||||
int charsRemoved,
|
||||
const QString textAdded,
|
||||
const QMap<int, BlockPreeditData> &blocksPreedit);
|
||||
void changeDocument(int from, int charsRemoved, int charsAdded);
|
||||
|
||||
SyntaxHighlighter::State m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user