From bb7e6e196cf981c3224d1b3277cf3dafa683cda1 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 2 Sep 2017 18:47:03 +0800 Subject: [PATCH] make markdown highlight interval configurable via markdown_highlight_interval --- src/hgmarkdownhighlighter.cpp | 2 ++ src/resources/vnote.ini | 3 +++ src/vconfigmanager.cpp | 3 +++ src/vconfigmanager.h | 11 +++++++++++ src/vmdedit.cpp | 3 ++- 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/hgmarkdownhighlighter.cpp b/src/hgmarkdownhighlighter.cpp index 98a85920..c07827d5 100644 --- a/src/hgmarkdownhighlighter.cpp +++ b/src/hgmarkdownhighlighter.cpp @@ -414,12 +414,14 @@ void HGMarkdownHighlighter::handleContentChange(int /* position */, int charsRem if (charsRemoved == 0 && charsAdded == 0) { return; } + timer->stop(); timer->start(); } void HGMarkdownHighlighter::timerTimeout() { + qDebug() << "HGMarkdownHighlighter start a new parse"; parse(); if (!updateCodeBlocks()) { rehighlight(); diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index 5a94f043..0fa10486 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -70,6 +70,9 @@ minimize_to_system_tray=-1 ; Case-insensitive markdown_suffix=md:markdown:mkd +; Markdown highlight timer interval (milliseconds) +markdown_highlight_interval=400 + [session] tools_dock_checked=true diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index afb9bae2..e04d0202 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -157,6 +157,9 @@ void VConfigManager::initialize() readShortcutsFromSettings(); initDocSuffixes(); + + m_markdownHighlightInterval = getConfigFromSettings("global", + "markdown_highlight_interval").toInt(); } void VConfigManager::readPredefinedColorsFromSettings() diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index 85c74261..7c8c9dff 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -221,6 +221,8 @@ public: void initDocSuffixes(); const QHash> &getDocSuffixes() const; + int getMarkdownHighlightInterval() const; + // Return the configured key sequence of @p_operation. // Return empty if there is no corresponding config. QString getShortcutKeySequence(const QString &p_operation) const; @@ -446,6 +448,9 @@ private: // [DocType] -> { Suffixes }. QHash> m_docSuffixes; + // Interval for HGMarkdownHighlighter highlight timer (milliseconds). + int m_markdownHighlightInterval; + // The name of the config file in each directory, obsolete. // Use c_dirConfigFile instead. static const QString c_obsoleteDirConfigFile; @@ -1138,4 +1143,10 @@ inline const QHash> &VConfigManager::getDocSuffixes() const { return m_docSuffixes; } + +inline int VConfigManager::getMarkdownHighlightInterval() const +{ + return m_markdownHighlightInterval; +} + #endif // VCONFIGMANAGER_H diff --git a/src/vmdedit.cpp b/src/vmdedit.cpp index 5c017c8e..505d98a2 100644 --- a/src/vmdedit.cpp +++ b/src/vmdedit.cpp @@ -25,7 +25,8 @@ VMdEdit::VMdEdit(VFile *p_file, VDocument *p_vdoc, MarkdownConverterType p_type, setAcceptRichText(false); m_mdHighlighter = new HGMarkdownHighlighter(g_config->getMdHighlightingStyles(), g_config->getCodeBlockStyles(), - 700, document()); + g_config->getMarkdownHighlightInterval(), + document()); connect(m_mdHighlighter, &HGMarkdownHighlighter::highlightCompleted, this, &VMdEdit::generateEditOutline);