mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
bug-fix: sort comparator should be irreflexive
This commit is contained in:
parent
77c664b773
commit
17b5ac5f66
@ -228,7 +228,7 @@ static bool compHLUnit(const HLUnit &p_a, const HLUnit &p_b)
|
|||||||
if (p_a.start < p_b.start) {
|
if (p_a.start < p_b.start) {
|
||||||
return true;
|
return true;
|
||||||
} else if (p_a.start == p_b.start) {
|
} else if (p_a.start == p_b.start) {
|
||||||
return p_a.length >= p_b.length;
|
return p_a.length > p_b.length;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -308,15 +308,14 @@ void HGMarkdownHighlighter::initHtmlCommentRegionsFromResult()
|
|||||||
|
|
||||||
void HGMarkdownHighlighter::initImageRegionsFromResult()
|
void HGMarkdownHighlighter::initImageRegionsFromResult()
|
||||||
{
|
{
|
||||||
if (!result) {
|
|
||||||
// From Qt5.7, the capacity is preserved.
|
// From Qt5.7, the capacity is preserved.
|
||||||
m_imageRegions.clear();
|
m_imageRegions.clear();
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
emit imageLinksUpdated(m_imageRegions);
|
emit imageLinksUpdated(m_imageRegions);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = 0;
|
|
||||||
int oriSize = m_imageRegions.size();
|
|
||||||
pmh_element *elem = result[pmh_IMAGE];
|
pmh_element *elem = result[pmh_IMAGE];
|
||||||
while (elem != NULL) {
|
while (elem != NULL) {
|
||||||
if (elem->end <= elem->pos) {
|
if (elem->end <= elem->pos) {
|
||||||
@ -324,25 +323,10 @@ void HGMarkdownHighlighter::initImageRegionsFromResult()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx < oriSize) {
|
|
||||||
// Try to reuse the original element.
|
|
||||||
VElementRegion ® = m_imageRegions[idx];
|
|
||||||
if ((int)elem->pos != reg.m_startPos || (int)elem->end != reg.m_endPos) {
|
|
||||||
reg.m_startPos = (int)elem->pos;
|
|
||||||
reg.m_endPos = (int)elem->end;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_imageRegions.push_back(VElementRegion(elem->pos, elem->end));
|
m_imageRegions.push_back(VElementRegion(elem->pos, elem->end));
|
||||||
}
|
|
||||||
|
|
||||||
++idx;
|
|
||||||
elem = elem->next;
|
elem = elem->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx < oriSize) {
|
|
||||||
m_imageRegions.resize(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "highlighter: parse" << m_imageRegions.size() << "image regions";
|
qDebug() << "highlighter: parse" << m_imageRegions.size() << "image regions";
|
||||||
|
|
||||||
emit imageLinksUpdated(m_imageRegions);
|
emit imageLinksUpdated(m_imageRegions);
|
||||||
@ -350,17 +334,15 @@ void HGMarkdownHighlighter::initImageRegionsFromResult()
|
|||||||
|
|
||||||
void HGMarkdownHighlighter::initHeaderRegionsFromResult()
|
void HGMarkdownHighlighter::initHeaderRegionsFromResult()
|
||||||
{
|
{
|
||||||
|
// From Qt5.7, the capacity is preserved.
|
||||||
m_headerBlocks.clear();
|
m_headerBlocks.clear();
|
||||||
|
m_headerRegions.clear();
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// From Qt5.7, the capacity is preserved.
|
|
||||||
m_headerRegions.clear();
|
|
||||||
emit headersUpdated(m_headerRegions);
|
emit headersUpdated(m_headerRegions);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idx = 0;
|
|
||||||
int oriSize = m_headerRegions.size();
|
|
||||||
pmh_element_type hx[6] = {pmh_H1, pmh_H2, pmh_H3, pmh_H4, pmh_H5, pmh_H6};
|
pmh_element_type hx[6] = {pmh_H1, pmh_H2, pmh_H3, pmh_H4, pmh_H5, pmh_H6};
|
||||||
for (int i = 0; i < 6; ++i) {
|
for (int i = 0; i < 6; ++i) {
|
||||||
pmh_element *elem = result[hx[i]];
|
pmh_element *elem = result[hx[i]];
|
||||||
@ -371,16 +353,7 @@ void HGMarkdownHighlighter::initHeaderRegionsFromResult()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx < oriSize) {
|
|
||||||
// Try to reuse the original element.
|
|
||||||
VElementRegion ® = m_headerRegions[idx];
|
|
||||||
if ((int)elem->pos != reg.m_startPos || (int)elem->end != reg.m_endPos) {
|
|
||||||
reg.m_startPos = (int)elem->pos;
|
|
||||||
reg.m_endPos = (int)elem->end;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_headerRegions.push_back(VElementRegion(elem->pos, elem->end));
|
m_headerRegions.push_back(VElementRegion(elem->pos, elem->end));
|
||||||
}
|
|
||||||
|
|
||||||
QTextBlock block = document->findBlock(elem->pos);
|
QTextBlock block = document->findBlock(elem->pos);
|
||||||
if (block.isValid()) {
|
if (block.isValid()) {
|
||||||
@ -388,15 +361,10 @@ void HGMarkdownHighlighter::initHeaderRegionsFromResult()
|
|||||||
m_headerBlocks.insert(block.blockNumber(), HeaderBlockInfo(i, elem->end - elem->pos - 1));
|
m_headerBlocks.insert(block.blockNumber(), HeaderBlockInfo(i, elem->end - elem->pos - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
++idx;
|
|
||||||
elem = elem->next;
|
elem = elem->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx < oriSize) {
|
|
||||||
m_headerRegions.resize(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::sort(m_headerRegions.begin(), m_headerRegions.end());
|
std::sort(m_headerRegions.begin(), m_headerRegions.end());
|
||||||
|
|
||||||
qDebug() << "highlighter: parse" << m_headerRegions.size() << "header regions";
|
qDebug() << "highlighter: parse" << m_headerRegions.size() << "header regions";
|
||||||
@ -714,7 +682,7 @@ static bool compHLUnitStyle(const HLUnitStyle &a, const HLUnitStyle &b)
|
|||||||
if (a.start < b.start) {
|
if (a.start < b.start) {
|
||||||
return true;
|
return true;
|
||||||
} else if (a.start == b.start) {
|
} else if (a.start == b.start) {
|
||||||
return a.length >= b.length;
|
return a.length > b.length;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,8 @@ struct VElementRegion
|
|||||||
if (m_startPos < p_other.m_startPos) {
|
if (m_startPos < p_other.m_startPos) {
|
||||||
return true;
|
return true;
|
||||||
} else if (m_startPos == p_other.m_startPos) {
|
} else if (m_startPos == p_other.m_startPos) {
|
||||||
return m_endPos <= p_other.m_endPos;
|
// If a < b is true, then b < a must be false.
|
||||||
|
return m_endPos < p_other.m_endPos;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user