mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Markdown Highlighter: speed up at first parse
This commit is contained in:
parent
d2ee3e66d6
commit
c7cb95d18b
@ -29,9 +29,16 @@ HGMarkdownHighlighter::HGMarkdownHighlighter(const QVector<HighlightingStyle> &s
|
|||||||
const QHash<QString, QTextCharFormat> &codeBlockStyles,
|
const QHash<QString, QTextCharFormat> &codeBlockStyles,
|
||||||
int waitInterval,
|
int waitInterval,
|
||||||
QTextDocument *parent)
|
QTextDocument *parent)
|
||||||
: QSyntaxHighlighter(parent), highlightingStyles(styles),
|
: QSyntaxHighlighter(parent),
|
||||||
m_codeBlockStyles(codeBlockStyles), m_numOfCodeBlockHighlightsToRecv(0),
|
highlightingStyles(styles),
|
||||||
parsing(0), waitInterval(waitInterval), content(NULL), capacity(0), result(NULL)
|
m_codeBlockStyles(codeBlockStyles),
|
||||||
|
m_numOfCodeBlockHighlightsToRecv(0),
|
||||||
|
parsing(0),
|
||||||
|
waitInterval(waitInterval),
|
||||||
|
m_firstParse(true),
|
||||||
|
content(NULL),
|
||||||
|
capacity(0),
|
||||||
|
result(NULL)
|
||||||
{
|
{
|
||||||
codeBlockStartExp = QRegExp(VUtils::c_fencedCodeBlockStartRegExp);
|
codeBlockStartExp = QRegExp(VUtils::c_fencedCodeBlockStartRegExp);
|
||||||
codeBlockEndExp = QRegExp(VUtils::c_fencedCodeBlockEndRegExp);
|
codeBlockEndExp = QRegExp(VUtils::c_fencedCodeBlockEndRegExp);
|
||||||
@ -541,11 +548,15 @@ void HGMarkdownHighlighter::timerTimeout()
|
|||||||
{
|
{
|
||||||
qDebug() << "HGMarkdownHighlighter start a new parse";
|
qDebug() << "HGMarkdownHighlighter start a new parse";
|
||||||
parse();
|
parse();
|
||||||
if (!updateCodeBlocks()) {
|
if (!updateCodeBlocks() || m_firstParse) {
|
||||||
rehighlight();
|
rehighlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
highlightChanged();
|
highlightChanged();
|
||||||
|
|
||||||
|
if (m_firstParse) {
|
||||||
|
m_firstParse = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HGMarkdownHighlighter::updateHighlight()
|
void HGMarkdownHighlighter::updateHighlight()
|
||||||
|
@ -190,6 +190,9 @@ private:
|
|||||||
QTimer *timer;
|
QTimer *timer;
|
||||||
int waitInterval;
|
int waitInterval;
|
||||||
|
|
||||||
|
// Whether this is the first parse.
|
||||||
|
bool m_firstParse;
|
||||||
|
|
||||||
char *content;
|
char *content;
|
||||||
int capacity;
|
int capacity;
|
||||||
pmh_element **result;
|
pmh_element **result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user