瀏覽代碼

TextEditor: add config for highlighting tab and trailing space

Le Tan 4 年之前
父節點
當前提交
86df5c39a2

+ 1 - 1
libs/vtextedit

@@ -1 +1 @@
-Subproject commit 6c2ff0e78aedb6d4a107cd4825473d47813596cc
+Subproject commit 00b52913fe8f4ccf5ed5a0cbd3493b94fe354b25

+ 0 - 1
src/core/mainconfig.cpp

@@ -118,5 +118,4 @@ QString MainConfig::getVersion(const QJsonObject &p_jobj)
 void MainConfig::doVersionSpecificOverride()
 {
     // In a new version, we may want to change one value by force.
-    m_coreConfig->m_docksTabBarIconSize = 26;
 }

+ 17 - 4
src/core/texteditorconfig.cpp

@@ -44,6 +44,8 @@ void TextEditorConfig::init(const QJsonObject &p_app,
 
     m_tabStopWidth = READINT(QStringLiteral("tab_stop_width"));
 
+    m_highlightWhitespace = READBOOL(QStringLiteral("highlight_whitespace"));
+
     m_zoomDelta = READINT(QStringLiteral("zoom_delta"));
 
     m_spellCheckEnabled = READBOOL(QStringLiteral("spell_check"));
@@ -59,6 +61,7 @@ QJsonObject TextEditorConfig::toJson() const
     obj[QStringLiteral("wrap_mode")] = wrapModeToString(m_wrapMode);
     obj[QStringLiteral("expand_tab")] = m_expandTab;
     obj[QStringLiteral("tab_stop_width")] = m_tabStopWidth;
+    obj[QStringLiteral("highlight_whitespace")] = m_highlightWhitespace;
     obj[QStringLiteral("zoom_delta")] = m_zoomDelta;
     obj[QStringLiteral("spell_check")] = m_spellCheckEnabled;
     return obj;
@@ -183,9 +186,9 @@ bool TextEditorConfig::getTextFoldingEnabled() const
     return m_textFoldingEnabled;
 }
 
-void TextEditorConfig::setTextFoldingEnabled(bool p_enable)
+void TextEditorConfig::setTextFoldingEnabled(bool p_enabled)
 {
-    updateConfig(m_textFoldingEnabled, p_enable, this);
+    updateConfig(m_textFoldingEnabled, p_enabled, this);
 }
 
 TextEditorConfig::InputMode TextEditorConfig::getInputMode() const
@@ -223,9 +226,19 @@ bool TextEditorConfig::getExpandTabEnabled() const
     return m_expandTab;
 }
 
-void TextEditorConfig::setExpandTabEnabled(bool p_enable)
+void TextEditorConfig::setExpandTabEnabled(bool p_enabled)
+{
+    updateConfig(m_expandTab, p_enabled, this);
+}
+
+bool TextEditorConfig::getHighlightWhitespaceEnabled() const
+{
+    return m_highlightWhitespace;
+}
+
+void TextEditorConfig::setHighlightWhitespaceEnabled(bool p_enabled)
 {
-    updateConfig(m_expandTab, p_enable, this);
+    updateConfig(m_highlightWhitespace, p_enabled, this);
 }
 
 int TextEditorConfig::getTabStopWidth() const

+ 7 - 2
src/core/texteditorconfig.h

@@ -46,7 +46,7 @@ namespace vnotex
         void setLineNumberType(TextEditorConfig::LineNumberType p_type);
 
         bool getTextFoldingEnabled() const;
-        void setTextFoldingEnabled(bool p_enable);
+        void setTextFoldingEnabled(bool p_enabled);
 
         TextEditorConfig::InputMode getInputMode() const;
         void setInputMode(TextEditorConfig::InputMode p_mode);
@@ -58,11 +58,14 @@ namespace vnotex
         void setWrapMode(TextEditorConfig::WrapMode p_mode);
 
         bool getExpandTabEnabled() const;
-        void setExpandTabEnabled(bool p_enable);
+        void setExpandTabEnabled(bool p_enabled);
 
         int getTabStopWidth() const;
         void setTabStopWidth(int p_width);
 
+        bool getHighlightWhitespaceEnabled() const;
+        void setHighlightWhitespaceEnabled(bool p_enabled);
+
         int getZoomDelta() const;
         void setZoomDelta(int p_delta);
 
@@ -96,6 +99,8 @@ namespace vnotex
 
         int m_tabStopWidth = 4;
 
+        bool m_highlightWhitespace = true;
+
         int m_zoomDelta = 0;
 
         bool m_spellCheckEnabled = false;

+ 1 - 0
src/data/core/vnotex.json

@@ -140,6 +140,7 @@
             "wrap_mode": "word_anywhere",
             "expand_tab": true,
             "tab_stop_width": 4,
+            "highlight_whitespace": true,
             "//comment" : "Positive to zoom in and negative to zoom out",
             "zoom_delta": 0,
             "spell_check": false

+ 14 - 0
src/widgets/dialogs/settings/texteditorpage.cpp

@@ -119,6 +119,16 @@ void TextEditorPage::setupUI()
                 this, &TextEditorPage::pageIsChanged);
     }
 
+    {
+        const QString label(tr("Highlight whitespace"));
+        m_highlightWhitespaceCheckBox = WidgetsFactory::createCheckBox(label, this);
+        m_highlightWhitespaceCheckBox->setToolTip(tr("Highlight Tab and trailing space"));
+        mainLayout->addRow(m_highlightWhitespaceCheckBox);
+        addSearchItem(label, m_highlightWhitespaceCheckBox->toolTip(), m_highlightWhitespaceCheckBox);
+        connect(m_highlightWhitespaceCheckBox, &QCheckBox::stateChanged,
+                this, &TextEditorPage::pageIsChanged);
+    }
+
     {
         m_zoomDeltaSpinBox = WidgetsFactory::createSpinBox(this);
         m_zoomDeltaSpinBox->setToolTip(tr("Zoom delta of the basic font size"));
@@ -178,6 +188,8 @@ void TextEditorPage::loadInternal()
 
     m_tabStopWidthSpinBox->setValue(textConfig.getTabStopWidth());
 
+    m_highlightWhitespaceCheckBox->setChecked(textConfig.getHighlightWhitespaceEnabled());
+
     m_zoomDeltaSpinBox->setValue(textConfig.getZoomDelta());
 
     m_spellCheckCheckBox->setChecked(textConfig.isSpellCheckEnabled());
@@ -213,6 +225,8 @@ bool TextEditorPage::saveInternal()
 
     textConfig.setTabStopWidth(m_tabStopWidthSpinBox->value());
 
+    textConfig.setHighlightWhitespaceEnabled(m_highlightWhitespaceCheckBox->isChecked());
+
     textConfig.setZoomDelta(m_zoomDeltaSpinBox->value());
 
     textConfig.setSpellCheckEnabled(m_spellCheckCheckBox->isChecked());

+ 2 - 0
src/widgets/dialogs/settings/texteditorpage.h

@@ -39,6 +39,8 @@ namespace vnotex
 
         QSpinBox *m_tabStopWidthSpinBox = nullptr;
 
+        QCheckBox *m_highlightWhitespaceCheckBox = nullptr;
+
         QSpinBox *m_zoomDeltaSpinBox = nullptr;
 
         QCheckBox *m_spellCheckCheckBox = nullptr;

+ 2 - 0
src/widgets/textviewwindowhelper.h

@@ -142,6 +142,8 @@ namespace vnotex
             editorConfig->m_expandTab = p_config.getExpandTabEnabled();
             editorConfig->m_tabStopWidth = p_config.getTabStopWidth();
 
+            editorConfig->m_highlightWhitespace = p_config.getHighlightWhitespaceEnabled();
+
             switch (p_lineEndingPolicy) {
             case LineEndingPolicy::Platform:
                 editorConfig->m_lineEndingPolicy = vte::LineEndingPolicy::Platform;