vim-mode: support cursor block

Support cursor block in Normal and Insert mode.

TODO: need more fine-grain tuning of the behaviors.
This commit is contained in:
Le Tan 2017-11-30 22:09:16 +08:00
parent b2a435297d
commit 87af770612
6 changed files with 123 additions and 0 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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;

View File

@ -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;

View File

@ -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:

View File

@ -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