mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09: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);
|
QTextBlock block = p_doc->findBlock(p_pos);
|
||||||
int startBlockNum = block.blockNumber();
|
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()) {
|
if (endBlockNum >= p_blocksHighlights.size()) {
|
||||||
endBlockNum = p_blocksHighlights.size() - 1;
|
endBlockNum = p_blocksHighlights.size() - 1;
|
||||||
}
|
}
|
||||||
@ -144,9 +144,14 @@ void PegHighlighterResult::parseBlocksHighlightOne(QVector<QVector<HLUnit>> &p_b
|
|||||||
unit.start = 0;
|
unit.start = 0;
|
||||||
unit.length = block.length();
|
unit.length = block.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
unit.styleIndex = p_styleIndex;
|
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();
|
block = block.next();
|
||||||
}
|
}
|
||||||
@ -167,7 +172,11 @@ void PegHighlighterResult::parseBlocksElementRegionOne(QHash<int, QVector<VEleme
|
|||||||
|
|
||||||
QTextBlock block = p_doc->findBlock(p_pos);
|
QTextBlock block = p_doc->findBlock(p_pos);
|
||||||
int startBlockNum = block.blockNumber();
|
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())
|
while (block.isValid())
|
||||||
{
|
{
|
||||||
int blockNum = block.blockNumber();
|
int blockNum = block.blockNumber();
|
||||||
|
@ -92,9 +92,9 @@ void PegMarkdownHighlighter::highlightBlock(const QString &p_text)
|
|||||||
int blockNum = block.blockNumber();
|
int blockNum = block.blockNumber();
|
||||||
|
|
||||||
if (result->matched(m_timeStamp)) {
|
if (result->matched(m_timeStamp)) {
|
||||||
preHighlightMonospaceBlock(result->m_blocksHighlights, blockNum, p_text);
|
preHighlightSingleFormatBlock(result->m_blocksHighlights, blockNum, p_text);
|
||||||
} else {
|
} else {
|
||||||
preHighlightMonospaceBlock(m_fastResult->m_blocksHighlights, blockNum, p_text);
|
preHighlightSingleFormatBlock(m_fastResult->m_blocksHighlights, blockNum, p_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
highlightBlockOne(result->m_blocksHighlights, blockNum);
|
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,
|
void PegMarkdownHighlighter::preHighlightSingleFormatBlock(const QVector<QVector<HLUnit>> &p_highlights,
|
||||||
int p_blockNum,
|
int p_blockNum,
|
||||||
const QString &p_text)
|
const QString &p_text)
|
||||||
{
|
{
|
||||||
int sz = p_text.size();
|
int sz = p_text.size();
|
||||||
if (sz == 0) {
|
if (sz == 0) {
|
||||||
@ -210,7 +210,7 @@ void PegMarkdownHighlighter::startFastParse(int p_position, int p_charsRemoved,
|
|||||||
int firstBlockNum, lastBlockNum;
|
int firstBlockNum, lastBlockNum;
|
||||||
getFastParseBlockRange(p_position, p_charsRemoved, p_charsAdded, firstBlockNum, lastBlockNum);
|
getFastParseBlockRange(p_position, p_charsRemoved, p_charsAdded, firstBlockNum, lastBlockNum);
|
||||||
if (firstBlockNum == -1) {
|
if (firstBlockNum == -1) {
|
||||||
m_fastResult.reset();
|
// We could not let m_fastResult NULL here.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +378,7 @@ void PegMarkdownHighlighter::updateSingleFormatBlocks(const QVector<QVector<HLUn
|
|||||||
const HLUnit &unit = units[0];
|
const HLUnit &unit = units[0];
|
||||||
if (unit.start == 0 && unit.length > 0) {
|
if (unit.start == 0 && unit.length > 0) {
|
||||||
QTextBlock block = m_doc->findBlockByNumber(i);
|
QTextBlock block = m_doc->findBlockByNumber(i);
|
||||||
if (block.length() - 1 == (int)unit.length) {
|
if (block.length() - 1 <= (int)unit.length) {
|
||||||
m_singleFormatBlocks.insert(i);
|
m_singleFormatBlocks.insert(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,9 +113,9 @@ private:
|
|||||||
int p_blockNum);
|
int p_blockNum);
|
||||||
|
|
||||||
// To avoid line height jitter.
|
// To avoid line height jitter.
|
||||||
void preHighlightMonospaceBlock(const QVector<QVector<HLUnit>> &p_highlights,
|
void preHighlightSingleFormatBlock(const QVector<QVector<HLUnit>> &p_highlights,
|
||||||
int p_blockNum,
|
int p_blockNum,
|
||||||
const QString &p_text);
|
const QString &p_text);
|
||||||
|
|
||||||
void updateSingleFormatBlocks(const QVector<QVector<HLUnit>> &p_highlights);
|
void updateSingleFormatBlocks(const QVector<QVector<HLUnit>> &p_highlights);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user