mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
bug-fix: merge the code block base format when highlighting code block in edit mode
This commit is contained in:
parent
a32fb015e1
commit
117b5471fd
@ -42,11 +42,11 @@ HGMarkdownHighlighter::HGMarkdownHighlighter(const QVector<HighlightingStyle> &s
|
|||||||
codeBlockStartExp = QRegExp(VUtils::c_fencedCodeBlockStartRegExp);
|
codeBlockStartExp = QRegExp(VUtils::c_fencedCodeBlockStartRegExp);
|
||||||
codeBlockEndExp = QRegExp(VUtils::c_fencedCodeBlockEndRegExp);
|
codeBlockEndExp = QRegExp(VUtils::c_fencedCodeBlockEndRegExp);
|
||||||
|
|
||||||
codeBlockFormat.setForeground(QBrush(Qt::darkYellow));
|
m_codeBlockFormat.setForeground(QBrush(Qt::darkYellow));
|
||||||
for (int index = 0; index < styles.size(); ++index) {
|
for (int index = 0; index < styles.size(); ++index) {
|
||||||
const pmh_element_type &eleType = styles[index].type;
|
const pmh_element_type &eleType = styles[index].type;
|
||||||
if (eleType == pmh_VERBATIM) {
|
if (eleType == pmh_VERBATIM) {
|
||||||
codeBlockFormat = styles[index].format;
|
m_codeBlockFormat = styles[index].format;
|
||||||
} else if (eleType == pmh_LINK) {
|
} else if (eleType == pmh_LINK) {
|
||||||
m_linkFormat = styles[index].format;
|
m_linkFormat = styles[index].format;
|
||||||
} else if (eleType == pmh_IMAGE) {
|
} else if (eleType == pmh_IMAGE) {
|
||||||
@ -54,7 +54,7 @@ HGMarkdownHighlighter::HGMarkdownHighlighter(const QVector<HighlightingStyle> &s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_colorColumnFormat = codeBlockFormat;
|
m_colorColumnFormat = m_codeBlockFormat;
|
||||||
m_colorColumnFormat.setForeground(QColor(g_config->getEditorColorColumnFg()));
|
m_colorColumnFormat.setForeground(QColor(g_config->getEditorColorColumnFg()));
|
||||||
m_colorColumnFormat.setBackground(QColor(g_config->getEditorColorColumnBg()));
|
m_colorColumnFormat.setBackground(QColor(g_config->getEditorColorColumnBg()));
|
||||||
|
|
||||||
@ -191,28 +191,24 @@ void HGMarkdownHighlighter::highlightBlock(const QString &text)
|
|||||||
|
|
||||||
formats[i] = &(*it);
|
formats[i] = &(*it);
|
||||||
|
|
||||||
if (i == 0) {
|
QTextCharFormat newFormat = m_codeBlockFormat;
|
||||||
// No need to merge format.
|
newFormat.merge(*it);
|
||||||
setFormat(unit.start, unit.length, *it);
|
for (int j = i - 1; j >= 0; --j) {
|
||||||
} else {
|
if (units[j].start + units[j].length <= unit.start) {
|
||||||
QTextCharFormat newFormat = *it;
|
// It won't affect current unit.
|
||||||
for (int j = i - 1; j >= 0; --j) {
|
continue;
|
||||||
if (units[j].start + units[j].length <= unit.start) {
|
} else {
|
||||||
// It won't affect current unit.
|
// Merge the format.
|
||||||
continue;
|
if (formats[j]) {
|
||||||
} else {
|
QTextCharFormat tmpFormat(newFormat);
|
||||||
// Merge the format.
|
newFormat = *(formats[j]);
|
||||||
if (formats[j]) {
|
// tmpFormat takes precedence.
|
||||||
QTextCharFormat tmpFormat(newFormat);
|
newFormat.merge(tmpFormat);
|
||||||
newFormat = *(formats[j]);
|
|
||||||
// tmpFormat takes precedence.
|
|
||||||
newFormat.merge(tmpFormat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setFormat(unit.start, unit.length, newFormat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFormat(unit.start, unit.length, newFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -462,7 +458,7 @@ void HGMarkdownHighlighter::highlightCodeBlock(const QString &text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
setCurrentBlockState(state);
|
setCurrentBlockState(state);
|
||||||
setFormat(index, length, codeBlockFormat);
|
setFormat(index, length, m_codeBlockFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HGMarkdownHighlighter::highlightCodeBlockColorColumn(const QString &p_text)
|
void HGMarkdownHighlighter::highlightCodeBlockColorColumn(const QString &p_text)
|
||||||
|
@ -180,7 +180,7 @@ private:
|
|||||||
|
|
||||||
QRegExp codeBlockStartExp;
|
QRegExp codeBlockStartExp;
|
||||||
QRegExp codeBlockEndExp;
|
QRegExp codeBlockEndExp;
|
||||||
QTextCharFormat codeBlockFormat;
|
QTextCharFormat m_codeBlockFormat;
|
||||||
QTextCharFormat m_linkFormat;
|
QTextCharFormat m_linkFormat;
|
||||||
QTextCharFormat m_imageFormat;
|
QTextCharFormat m_imageFormat;
|
||||||
QTextCharFormat m_colorColumnFormat;
|
QTextCharFormat m_colorColumnFormat;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user