From 4e744f30f90b26c450a0cb6fe5c9b269b267811a Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 10 May 2018 20:07:28 +0800 Subject: [PATCH] highlighter: no need to check if a header is valid It is fixed in the upstream pmh_parser. --- src/hgmarkdownhighlighter.cpp | 34 +--------------------------------- src/hgmarkdownhighlighter.h | 3 --- src/vmdeditor.cpp | 4 ++-- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/src/hgmarkdownhighlighter.cpp b/src/hgmarkdownhighlighter.cpp index 14291148..f497ea2c 100644 --- a/src/hgmarkdownhighlighter.cpp +++ b/src/hgmarkdownhighlighter.cpp @@ -271,9 +271,6 @@ void HGMarkdownHighlighter::initBlockHighlightFromResult(int nrBlocks) const HighlightingStyle &style = highlightingStyles[i]; pmh_element *elem_cursor = result[style.type]; - // pmh_H1 to pmh_H6 is continuous. - bool isHeader = style.type >= pmh_H1 && style.type <= pmh_H6; - while (elem_cursor != NULL) { // elem_cursor->pos and elem_cursor->end is the start @@ -283,13 +280,6 @@ void HGMarkdownHighlighter::initBlockHighlightFromResult(int nrBlocks) continue; } - // Check header. Skip those headers with no spaces after #s. - if (isHeader - && !isValidHeader(elem_cursor->pos, elem_cursor->end)) { - elem_cursor = elem_cursor->next; - continue; - } - initBlockHighlihgtOne(elem_cursor->pos, elem_cursor->end, i); elem_cursor = elem_cursor->next; } @@ -383,8 +373,7 @@ void HGMarkdownHighlighter::initHeaderRegionsFromResult() for (int i = 0; i < 6; ++i) { pmh_element *elem = result[hx[i]]; while (elem != NULL) { - if (elem->end <= elem->pos - || !isValidHeader(elem->pos, elem->end)) { + if (elem->end <= elem->pos) { elem = elem->next; continue; } @@ -1015,27 +1004,6 @@ void HGMarkdownHighlighter::highlightChanged() m_completeTimer->start(); } -bool HGMarkdownHighlighter::isValidHeader(unsigned long p_pos, unsigned long p_end) -{ - // There must exist spaces after #s. - // No more than 6 #s. - int nrNumberSign = 0; - for (unsigned long i = p_pos; i < p_end; ++i) { - QChar ch = document->characterAt(i); - if (ch.isSpace()) { - return nrNumberSign > 0; - } else if (ch == QChar('#')) { - if (++nrNumberSign > 6) { - return false; - } - } else { - return false; - } - } - - return false; -} - bool HGMarkdownHighlighter::isValidHeader(const QString &p_text) { // There must exist spaces after #s. diff --git a/src/hgmarkdownhighlighter.h b/src/hgmarkdownhighlighter.h index 2b61bc08..a7da3ec0 100644 --- a/src/hgmarkdownhighlighter.h +++ b/src/hgmarkdownhighlighter.h @@ -410,9 +410,6 @@ private: // Highlight color column in code block. void highlightCodeBlockColorColumn(const QString &p_text); - // Check if [p_pos, p_end) is a valid header. - bool isValidHeader(unsigned long p_pos, unsigned long p_end); - bool isValidHeader(const QString &p_text); VTextBlockData *currentBlockData() const; diff --git a/src/vmdeditor.cpp b/src/vmdeditor.cpp index 294a2994..e6125002 100644 --- a/src/vmdeditor.cpp +++ b/src/vmdeditor.cpp @@ -298,8 +298,8 @@ void VMdEditor::contextMenuEvent(QContextMenuEvent *p_event) emit m_object->discardAndRead(); }); - QAction *toggleLivePreviewAct = new QAction(tr("Toggle Live Preview"), menu.data()); - toggleLivePreviewAct->setToolTip(tr("Toggle live preview of diagrams")); + QAction *toggleLivePreviewAct = new QAction(tr("Live Preview for Diagrams"), menu.data()); + toggleLivePreviewAct->setToolTip(tr("Toggle live preview panel for diagrams")); connect(toggleLivePreviewAct, &QAction::triggered, this, [this]() { m_editTab->toggleLivePreview();