diff --git a/src/resources/styles/default.mdhl b/src/resources/styles/default.mdhl index 561fed3d..5ddae6a8 100644 --- a/src/resources/styles/default.mdhl +++ b/src/resources/styles/default.mdhl @@ -41,8 +41,16 @@ editor-current-line background: c5cae9 # [VNote] Vim insert mode cursor line background vim-insert-background: c5cae9 +# [VNote] Vim insert mode cursor block background +vim-insert-cursor-background: 4359e8 +# [VNote] Vim insert mode cursor block foreground +vim-insert-cursor-foreground: eeeeee # [VNote] Vim normal mode cursor line background vim-normal-background: bcbcbc +# [VNote] Vim normal mode cursor block background +vim-normal-cursor-background: 3e3e3e +# [VNote] Vim normal mode cursor block foreground +vim-normal-cursor-foreground: eeeeee # [VNote] Vim visual mode cursor line background vim-visual-background: 90caf9 # [VNote] Vim replace mode cursor line background diff --git a/src/utils/vvim.cpp b/src/utils/vvim.cpp index d575c0c1..e0c1e195 100644 --- a/src/utils/vvim.cpp +++ b/src/utils/vvim.cpp @@ -2240,6 +2240,26 @@ void VVim::setMode(VimMode p_mode, bool p_clearSelection) m_mode = p_mode; resetState(); + bool cursorBlock = false; + switch (m_mode) { + case VimMode::Insert: + cursorBlock = true; + m_editor->setCursorBlockColor(g_config->getEditorVimInsertCursorBg(), + g_config->getEditorVimInsertCursorFg()); + break; + + case VimMode::Normal: + cursorBlock = true; + m_editor->setCursorBlockColor(g_config->getEditorVimNormalCursorBg(), + g_config->getEditorVimNormalCursorFg()); + break; + + default: + break; + } + + m_editor->setCursorBlockEnabled(cursorBlock); + emit modeChanged(m_mode); emit vimStatusUpdated(this); } diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index cbe27894..2c23cc43 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -543,10 +543,18 @@ QString VConfigManager::getLogFilePath() const void VConfigManager::updateMarkdownEditStyle() { static const QString defaultCurrentLineBackground = "#C5CAE9"; + static const QString defaultVimNormalBg = "#BCBCBC"; + static const QString defaultVimNormalCursorBg = "#3E3E3E"; + static const QString defaultVimNormalCursorFg = "#EEEEEE"; + static const QString defaultVimInsertBg = "#C5CAE9"; + static const QString defaultVimInsertCursorBg = "#4359E8"; + static const QString defaultVimInsertCursorFg = "#EEEEEE"; + static const QString defaultVimVisualBg = "#90CAF9"; static const QString defaultVimReplaceBg = "#F8BBD0"; + static const QString defaultTrailingSpaceBg = "#A8A8A8"; static const QString defaultSelectedWordBg = "#DFDF00"; static const QString defaultSearchedWordBg = "#81C784"; @@ -579,8 +587,15 @@ void VConfigManager::updateMarkdownEditStyle() m_codeBlockStyles = parser.fetchCodeBlockStyles(mdEditFont); m_editorCurrentLineBg = defaultCurrentLineBackground; + m_editorVimInsertBg = defaultVimInsertBg; + m_editorVimInsertCursorBg = defaultVimInsertCursorBg; + m_editorVimInsertCursorFg = defaultVimInsertCursorFg; + m_editorVimNormalBg = defaultVimNormalBg; + m_editorVimNormalCursorBg = defaultVimNormalCursorBg; + m_editorVimNormalCursorFg = defaultVimNormalCursorFg; + m_editorVimVisualBg = defaultVimVisualBg; m_editorVimReplaceBg = defaultVimReplaceBg; auto editorCurrentLineIt = styles.find("editor-current-line"); @@ -596,11 +611,31 @@ void VConfigManager::updateMarkdownEditStyle() m_editorVimInsertBg = "#" + *vimBgIt; } + vimBgIt = editorCurrentLineIt->find("vim-insert-cursor-background"); + if (vimBgIt != editorCurrentLineIt->end()) { + m_editorVimInsertCursorBg = "#" + *vimBgIt; + } + + vimBgIt = editorCurrentLineIt->find("vim-insert-cursor-foreground"); + if (vimBgIt != editorCurrentLineIt->end()) { + m_editorVimInsertCursorFg = "#" + *vimBgIt; + } + vimBgIt = editorCurrentLineIt->find("vim-normal-background"); if (vimBgIt != editorCurrentLineIt->end()) { m_editorVimNormalBg = "#" + *vimBgIt; } + vimBgIt = editorCurrentLineIt->find("vim-normal-cursor-background"); + if (vimBgIt != editorCurrentLineIt->end()) { + m_editorVimNormalCursorBg = "#" + *vimBgIt; + } + + vimBgIt = editorCurrentLineIt->find("vim-normal-cursor-foreground"); + if (vimBgIt != editorCurrentLineIt->end()) { + m_editorVimNormalCursorFg = "#" + *vimBgIt; + } + vimBgIt = editorCurrentLineIt->find("vim-visual-background"); if (vimBgIt != editorCurrentLineIt->end()) { m_editorVimVisualBg = "#" + *vimBgIt; diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index bf291299..a711542d 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -210,7 +210,13 @@ public: const QString &getEditorIncrementalSearchedWordBg() const; const QString &getEditorVimNormalBg() const; + const QString &getEditorVimNormalCursorBg() const; + const QString &getEditorVimNormalCursorFg() const; + const QString &getEditorVimInsertBg() const; + const QString &getEditorVimInsertCursorBg() const; + const QString &getEditorVimInsertCursorFg() const; + const QString &getEditorVimVisualBg() const; const QString &getEditorVimReplaceBg() const; @@ -563,9 +569,21 @@ private: // Current line background color in editor in Vim normal mode. QString m_editorVimNormalBg; + // Cursour block background color in editor in Vim normal mode. + QString m_editorVimNormalCursorBg; + + // Cursour block foreground color in editor in Vim normal mode. + QString m_editorVimNormalCursorFg; + // Current line background color in editor in Vim insert mode. QString m_editorVimInsertBg; + // Cursour block background color in editor in Vim insert mode. + QString m_editorVimInsertCursorBg; + + // Cursour block foreground color in editor in Vim insert mode. + QString m_editorVimInsertCursorFg; + // Current line background color in editor in Vim visual mode. QString m_editorVimVisualBg; @@ -1259,11 +1277,31 @@ inline const QString &VConfigManager::getEditorVimNormalBg() const return m_editorVimNormalBg; } +inline const QString &VConfigManager::getEditorVimNormalCursorBg() const +{ + return m_editorVimNormalCursorBg; +} + +inline const QString &VConfigManager::getEditorVimNormalCursorFg() const +{ + return m_editorVimNormalCursorFg; +} + inline const QString &VConfigManager::getEditorVimInsertBg() const { return m_editorVimInsertBg; } +inline const QString &VConfigManager::getEditorVimInsertCursorBg() const +{ + return m_editorVimInsertCursorBg; +} + +inline const QString &VConfigManager::getEditorVimInsertCursorFg() const +{ + return m_editorVimInsertCursorFg; +} + inline const QString &VConfigManager::getEditorVimVisualBg() const { return m_editorVimVisualBg; diff --git a/src/veditor.h b/src/veditor.h index a6a1ac35..94830bfb 100644 --- a/src/veditor.h +++ b/src/veditor.h @@ -144,6 +144,12 @@ public: // @p_modified: if true, delete the whole content and insert the new content. virtual void setContent(const QString &p_content, bool p_modified = false) = 0; + // Whether display cursor as block. + virtual void setCursorBlockEnabled(bool p_enabled) = 0; + + // Set the cursor block's background and foreground. + virtual void setCursorBlockColor(const QColor &p_bg, const QColor &p_fg) = 0; + // Wrapper functions for QPlainTextEdit/QTextEdit. // Ends with W to distinguish it from the original interfaces. public: diff --git a/src/vmdeditor.h b/src/vmdeditor.h index b8f0254d..faf0b2dd 100644 --- a/src/vmdeditor.h +++ b/src/vmdeditor.h @@ -59,6 +59,12 @@ public: void setContent(const QString &p_content, bool p_modified = false) Q_DECL_OVERRIDE; + // Whether display cursor as block. + void setCursorBlockEnabled(bool p_enabled) Q_DECL_OVERRIDE; + + // Set the cursor block's background and foreground. + void setCursorBlockColor(const QColor &p_bg, const QColor &p_fg) Q_DECL_OVERRIDE; + public slots: bool jumpTitle(bool p_forward, int p_relativeLevel, int p_repeat) Q_DECL_OVERRIDE; @@ -212,4 +218,14 @@ private: bool m_freshEdit; }; +inline void VMdEditor::setCursorBlockEnabled(bool p_enabled) +{ + setCursorBlockMode(p_enabled); +} + +inline void VMdEditor::setCursorBlockColor(const QColor &p_bg, const QColor &p_fg) +{ + setCursorBlockBg(p_bg); + setCursorBlockFg(p_fg); +} #endif // VMDEDITOR_H