PegHighlighter: bug fix for single format blocks

This commit is contained in:
Le Tan 2018-07-20 20:07:07 +08:00
parent 25ec41c3f0
commit 76554b63f4
3 changed files with 22 additions and 13 deletions

View File

@ -119,7 +119,7 @@ void PegHighlighterResult::parseBlocksHighlightOne(QVector<QVector<HLUnit>> &p_b
QTextBlock block = p_doc->findBlock(p_pos);
int startBlockNum = block.blockNumber();
int endBlockNum = p_doc->findBlock(p_end).blockNumber();
int endBlockNum = p_doc->findBlock(p_end - 1).blockNumber();
if (endBlockNum >= p_blocksHighlights.size()) {
endBlockNum = p_blocksHighlights.size() - 1;
}
@ -144,9 +144,14 @@ void PegHighlighterResult::parseBlocksHighlightOne(QVector<QVector<HLUnit>> &p_b
unit.start = 0;
unit.length = block.length();
}
unit.styleIndex = p_styleIndex;
p_blocksHighlights[blockNum].append(unit);
Q_ASSERT(unit.length > 0);
if (unit.length > 0) {
p_blocksHighlights[blockNum].append(unit);
}
block = block.next();
}
@ -167,7 +172,11 @@ void PegHighlighterResult::parseBlocksElementRegionOne(QHash<int, QVector<VEleme
QTextBlock block = p_doc->findBlock(p_pos);
int startBlockNum = block.blockNumber();
int endBlockNum = p_doc->findBlock(p_end).blockNumber();
int endBlockNum = p_doc->findBlock(p_end - 1).blockNumber();
if (endBlockNum >= p_regs.size()) {
endBlockNum = p_regs.size() - 1;
}
while (block.isValid())
{
int blockNum = block.blockNumber();

View File

@ -92,9 +92,9 @@ void PegMarkdownHighlighter::highlightBlock(const QString &p_text)
int blockNum = block.blockNumber();
if (result->matched(m_timeStamp)) {
preHighlightMonospaceBlock(result->m_blocksHighlights, blockNum, p_text);
preHighlightSingleFormatBlock(result->m_blocksHighlights, blockNum, p_text);
} else {
preHighlightMonospaceBlock(m_fastResult->m_blocksHighlights, blockNum, p_text);
preHighlightSingleFormatBlock(m_fastResult->m_blocksHighlights, blockNum, p_text);
}
highlightBlockOne(result->m_blocksHighlights, blockNum);
@ -116,9 +116,9 @@ void PegMarkdownHighlighter::highlightBlock(const QString &p_text)
}
}
void PegMarkdownHighlighter::preHighlightMonospaceBlock(const QVector<QVector<HLUnit>> &p_highlights,
int p_blockNum,
const QString &p_text)
void PegMarkdownHighlighter::preHighlightSingleFormatBlock(const QVector<QVector<HLUnit>> &p_highlights,
int p_blockNum,
const QString &p_text)
{
int sz = p_text.size();
if (sz == 0) {
@ -210,7 +210,7 @@ void PegMarkdownHighlighter::startFastParse(int p_position, int p_charsRemoved,
int firstBlockNum, lastBlockNum;
getFastParseBlockRange(p_position, p_charsRemoved, p_charsAdded, firstBlockNum, lastBlockNum);
if (firstBlockNum == -1) {
m_fastResult.reset();
// We could not let m_fastResult NULL here.
return;
}
@ -378,7 +378,7 @@ void PegMarkdownHighlighter::updateSingleFormatBlocks(const QVector<QVector<HLUn
const HLUnit &unit = units[0];
if (unit.start == 0 && unit.length > 0) {
QTextBlock block = m_doc->findBlockByNumber(i);
if (block.length() - 1 == (int)unit.length) {
if (block.length() - 1 <= (int)unit.length) {
m_singleFormatBlocks.insert(i);
}
}

View File

@ -113,9 +113,9 @@ private:
int p_blockNum);
// To avoid line height jitter.
void preHighlightMonospaceBlock(const QVector<QVector<HLUnit>> &p_highlights,
int p_blockNum,
const QString &p_text);
void preHighlightSingleFormatBlock(const QVector<QVector<HLUnit>> &p_highlights,
int p_blockNum,
const QString &p_text);
void updateSingleFormatBlocks(const QVector<QVector<HLUnit>> &p_highlights);