Browse Source

make markdown highlight interval configurable via markdown_highlight_interval

Le Tan 8 years ago
parent
commit
bb7e6e196c
5 changed files with 21 additions and 1 deletions
  1. 2 0
      src/hgmarkdownhighlighter.cpp
  2. 3 0
      src/resources/vnote.ini
  3. 3 0
      src/vconfigmanager.cpp
  4. 11 0
      src/vconfigmanager.h
  5. 2 1
      src/vmdedit.cpp

+ 2 - 0
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();

+ 3 - 0
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
 

+ 3 - 0
src/vconfigmanager.cpp

@@ -157,6 +157,9 @@ void VConfigManager::initialize()
     readShortcutsFromSettings();
 
     initDocSuffixes();
+
+    m_markdownHighlightInterval = getConfigFromSettings("global",
+                                                        "markdown_highlight_interval").toInt();
 }
 
 void VConfigManager::readPredefinedColorsFromSettings()

+ 11 - 0
src/vconfigmanager.h

@@ -221,6 +221,8 @@ public:
     void initDocSuffixes();
     const QHash<int, QList<QString>> &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<int, QList<QString>> 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<int, QList<QString>> &VConfigManager::getDocSuffixes() const
 {
     return m_docSuffixes;
 }
+
+inline int VConfigManager::getMarkdownHighlightInterval() const
+{
+    return m_markdownHighlightInterval;
+}
+
 #endif // VCONFIGMANAGER_H

+ 2 - 1
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);