bug-fix: merge the code block base format when highlighting code block in edit mode

This commit is contained in:
Le Tan 2018-02-04 13:02:55 +08:00
parent a32fb015e1
commit 117b5471fd
2 changed files with 20 additions and 24 deletions

View File

@ -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,11 +191,8 @@ 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);
} else {
QTextCharFormat newFormat = *it;
for (int j = i - 1; j >= 0; --j) { for (int j = i - 1; j >= 0; --j) {
if (units[j].start + units[j].length <= unit.start) { if (units[j].start + units[j].length <= unit.start) {
// It won't affect current unit. // It won't affect current unit.
@ -215,7 +212,6 @@ void HGMarkdownHighlighter::highlightBlock(const QString &text)
} }
} }
} }
}
highlightCodeBlockColorColumn(text); highlightCodeBlockColorColumn(text);
@ -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)

View File

@ -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;