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);
|
&SyntaxHighlighterRunnerPrivate::resultsReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cloneDocument(int from,
|
void changeDocument(int from,
|
||||||
int charsRemoved,
|
int charsRemoved,
|
||||||
const QString textAdded,
|
const QString textAdded,
|
||||||
const QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> &blocksPreedit)
|
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;
|
m_syntaxInfoUpdated = SyntaxHighlighter::State::InProgress;
|
||||||
QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> blocksPreedit;
|
QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> blocksPreedit;
|
||||||
QTextBlock block = m_document->findBlock(from);
|
QTextBlock block = m_document->findBlock(from);
|
||||||
@@ -170,16 +171,8 @@ void BaseSyntaxHighlighterRunner::cloneDocumentData(int from, int charsRemoved,
|
|||||||
block = block.next();
|
block = block.next();
|
||||||
}
|
}
|
||||||
const QString text = Utils::Text::textAt(QTextCursor(m_document), from, charsAdded);
|
const QString text = Utils::Text::textAt(QTextCursor(m_document), from, charsAdded);
|
||||||
cloneDocument(from, charsRemoved, text, blocksPreedit);
|
QMetaObject::invokeMethod(d.get(), [this, from, charsRemoved, text, blocksPreedit] {
|
||||||
}
|
d->changeDocument(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);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,16 +247,11 @@ ThreadedSyntaxHighlighterRunner::ThreadedSyntaxHighlighterRunner(SyntaxHighLight
|
|||||||
applyFormatRanges(res);
|
applyFormatRanges(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
cloneDocumentData(0, 0, document->characterCount());
|
changeDocument(0, 0, document->characterCount());
|
||||||
connect(document,
|
connect(document,
|
||||||
&QTextDocument::contentsChange,
|
&QTextDocument::contentsChange,
|
||||||
this,
|
this,
|
||||||
[this](int from, int charsRemoved, int charsAdded) {
|
&ThreadedSyntaxHighlighterRunner::changeDocument);
|
||||||
if (!this->document())
|
|
||||||
return;
|
|
||||||
|
|
||||||
cloneDocumentData(from, charsRemoved, charsAdded);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadedSyntaxHighlighterRunner::~ThreadedSyntaxHighlighterRunner()
|
ThreadedSyntaxHighlighterRunner::~ThreadedSyntaxHighlighterRunner()
|
||||||
|
|||||||
@@ -58,11 +58,7 @@ protected:
|
|||||||
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
std::unique_ptr<SyntaxHighlighterRunnerPrivate> d;
|
||||||
QPointer<QTextDocument> m_document = nullptr;
|
QPointer<QTextDocument> m_document = nullptr;
|
||||||
void applyFormatRanges(const SyntaxHighlighter::Result &result);
|
void applyFormatRanges(const SyntaxHighlighter::Result &result);
|
||||||
void cloneDocumentData(int from, int charsRemoved, int charsAdded);
|
void changeDocument(int from, int charsRemoved, int charsAdded);
|
||||||
void cloneDocument(int from,
|
|
||||||
int charsRemoved,
|
|
||||||
const QString textAdded,
|
|
||||||
const QMap<int, BlockPreeditData> &blocksPreedit);
|
|
||||||
|
|
||||||
SyntaxHighlighter::State m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;
|
SyntaxHighlighter::State m_syntaxInfoUpdated = SyntaxHighlighter::State::Done;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user