mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
PegHighlighter: bug fix for single format blocks
This commit is contained in:
parent
25ec41c3f0
commit
76554b63f4
@ -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;
|
||||
|
||||
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();
|
||||
|
@ -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,7 +116,7 @@ void PegMarkdownHighlighter::highlightBlock(const QString &p_text)
|
||||
}
|
||||
}
|
||||
|
||||
void PegMarkdownHighlighter::preHighlightMonospaceBlock(const QVector<QVector<HLUnit>> &p_highlights,
|
||||
void PegMarkdownHighlighter::preHighlightSingleFormatBlock(const QVector<QVector<HLUnit>> &p_highlights,
|
||||
int p_blockNum,
|
||||
const QString &p_text)
|
||||
{
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ private:
|
||||
int p_blockNum);
|
||||
|
||||
// To avoid line height jitter.
|
||||
void preHighlightMonospaceBlock(const QVector<QVector<HLUnit>> &p_highlights,
|
||||
void preHighlightSingleFormatBlock(const QVector<QVector<HLUnit>> &p_highlights,
|
||||
int p_blockNum,
|
||||
const QString &p_text);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user