mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
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:
parent
b2a435297d
commit
87af770612
@ -41,8 +41,16 @@ editor-current-line
|
|||||||
background: c5cae9
|
background: c5cae9
|
||||||
# [VNote] Vim insert mode cursor line background
|
# [VNote] Vim insert mode cursor line background
|
||||||
vim-insert-background: c5cae9
|
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
|
# [VNote] Vim normal mode cursor line background
|
||||||
vim-normal-background: bcbcbc
|
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
|
# [VNote] Vim visual mode cursor line background
|
||||||
vim-visual-background: 90caf9
|
vim-visual-background: 90caf9
|
||||||
# [VNote] Vim replace mode cursor line background
|
# [VNote] Vim replace mode cursor line background
|
||||||
|
@ -2240,6 +2240,26 @@ void VVim::setMode(VimMode p_mode, bool p_clearSelection)
|
|||||||
m_mode = p_mode;
|
m_mode = p_mode;
|
||||||
resetState();
|
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 modeChanged(m_mode);
|
||||||
emit vimStatusUpdated(this);
|
emit vimStatusUpdated(this);
|
||||||
}
|
}
|
||||||
|
@ -543,10 +543,18 @@ QString VConfigManager::getLogFilePath() const
|
|||||||
void VConfigManager::updateMarkdownEditStyle()
|
void VConfigManager::updateMarkdownEditStyle()
|
||||||
{
|
{
|
||||||
static const QString defaultCurrentLineBackground = "#C5CAE9";
|
static const QString defaultCurrentLineBackground = "#C5CAE9";
|
||||||
|
|
||||||
static const QString defaultVimNormalBg = "#BCBCBC";
|
static const QString defaultVimNormalBg = "#BCBCBC";
|
||||||
|
static const QString defaultVimNormalCursorBg = "#3E3E3E";
|
||||||
|
static const QString defaultVimNormalCursorFg = "#EEEEEE";
|
||||||
|
|
||||||
static const QString defaultVimInsertBg = "#C5CAE9";
|
static const QString defaultVimInsertBg = "#C5CAE9";
|
||||||
|
static const QString defaultVimInsertCursorBg = "#4359E8";
|
||||||
|
static const QString defaultVimInsertCursorFg = "#EEEEEE";
|
||||||
|
|
||||||
static const QString defaultVimVisualBg = "#90CAF9";
|
static const QString defaultVimVisualBg = "#90CAF9";
|
||||||
static const QString defaultVimReplaceBg = "#F8BBD0";
|
static const QString defaultVimReplaceBg = "#F8BBD0";
|
||||||
|
|
||||||
static const QString defaultTrailingSpaceBg = "#A8A8A8";
|
static const QString defaultTrailingSpaceBg = "#A8A8A8";
|
||||||
static const QString defaultSelectedWordBg = "#DFDF00";
|
static const QString defaultSelectedWordBg = "#DFDF00";
|
||||||
static const QString defaultSearchedWordBg = "#81C784";
|
static const QString defaultSearchedWordBg = "#81C784";
|
||||||
@ -579,8 +587,15 @@ void VConfigManager::updateMarkdownEditStyle()
|
|||||||
m_codeBlockStyles = parser.fetchCodeBlockStyles(mdEditFont);
|
m_codeBlockStyles = parser.fetchCodeBlockStyles(mdEditFont);
|
||||||
|
|
||||||
m_editorCurrentLineBg = defaultCurrentLineBackground;
|
m_editorCurrentLineBg = defaultCurrentLineBackground;
|
||||||
|
|
||||||
m_editorVimInsertBg = defaultVimInsertBg;
|
m_editorVimInsertBg = defaultVimInsertBg;
|
||||||
|
m_editorVimInsertCursorBg = defaultVimInsertCursorBg;
|
||||||
|
m_editorVimInsertCursorFg = defaultVimInsertCursorFg;
|
||||||
|
|
||||||
m_editorVimNormalBg = defaultVimNormalBg;
|
m_editorVimNormalBg = defaultVimNormalBg;
|
||||||
|
m_editorVimNormalCursorBg = defaultVimNormalCursorBg;
|
||||||
|
m_editorVimNormalCursorFg = defaultVimNormalCursorFg;
|
||||||
|
|
||||||
m_editorVimVisualBg = defaultVimVisualBg;
|
m_editorVimVisualBg = defaultVimVisualBg;
|
||||||
m_editorVimReplaceBg = defaultVimReplaceBg;
|
m_editorVimReplaceBg = defaultVimReplaceBg;
|
||||||
auto editorCurrentLineIt = styles.find("editor-current-line");
|
auto editorCurrentLineIt = styles.find("editor-current-line");
|
||||||
@ -596,11 +611,31 @@ void VConfigManager::updateMarkdownEditStyle()
|
|||||||
m_editorVimInsertBg = "#" + *vimBgIt;
|
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");
|
vimBgIt = editorCurrentLineIt->find("vim-normal-background");
|
||||||
if (vimBgIt != editorCurrentLineIt->end()) {
|
if (vimBgIt != editorCurrentLineIt->end()) {
|
||||||
m_editorVimNormalBg = "#" + *vimBgIt;
|
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");
|
vimBgIt = editorCurrentLineIt->find("vim-visual-background");
|
||||||
if (vimBgIt != editorCurrentLineIt->end()) {
|
if (vimBgIt != editorCurrentLineIt->end()) {
|
||||||
m_editorVimVisualBg = "#" + *vimBgIt;
|
m_editorVimVisualBg = "#" + *vimBgIt;
|
||||||
|
@ -210,7 +210,13 @@ public:
|
|||||||
const QString &getEditorIncrementalSearchedWordBg() const;
|
const QString &getEditorIncrementalSearchedWordBg() const;
|
||||||
|
|
||||||
const QString &getEditorVimNormalBg() const;
|
const QString &getEditorVimNormalBg() const;
|
||||||
|
const QString &getEditorVimNormalCursorBg() const;
|
||||||
|
const QString &getEditorVimNormalCursorFg() const;
|
||||||
|
|
||||||
const QString &getEditorVimInsertBg() const;
|
const QString &getEditorVimInsertBg() const;
|
||||||
|
const QString &getEditorVimInsertCursorBg() const;
|
||||||
|
const QString &getEditorVimInsertCursorFg() const;
|
||||||
|
|
||||||
const QString &getEditorVimVisualBg() const;
|
const QString &getEditorVimVisualBg() const;
|
||||||
const QString &getEditorVimReplaceBg() const;
|
const QString &getEditorVimReplaceBg() const;
|
||||||
|
|
||||||
@ -563,9 +569,21 @@ private:
|
|||||||
// Current line background color in editor in Vim normal mode.
|
// Current line background color in editor in Vim normal mode.
|
||||||
QString m_editorVimNormalBg;
|
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.
|
// Current line background color in editor in Vim insert mode.
|
||||||
QString m_editorVimInsertBg;
|
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.
|
// Current line background color in editor in Vim visual mode.
|
||||||
QString m_editorVimVisualBg;
|
QString m_editorVimVisualBg;
|
||||||
|
|
||||||
@ -1259,11 +1277,31 @@ inline const QString &VConfigManager::getEditorVimNormalBg() const
|
|||||||
return m_editorVimNormalBg;
|
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
|
inline const QString &VConfigManager::getEditorVimInsertBg() const
|
||||||
{
|
{
|
||||||
return m_editorVimInsertBg;
|
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
|
inline const QString &VConfigManager::getEditorVimVisualBg() const
|
||||||
{
|
{
|
||||||
return m_editorVimVisualBg;
|
return m_editorVimVisualBg;
|
||||||
|
@ -144,6 +144,12 @@ public:
|
|||||||
// @p_modified: if true, delete the whole content and insert the new content.
|
// @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;
|
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.
|
// Wrapper functions for QPlainTextEdit/QTextEdit.
|
||||||
// Ends with W to distinguish it from the original interfaces.
|
// Ends with W to distinguish it from the original interfaces.
|
||||||
public:
|
public:
|
||||||
|
@ -59,6 +59,12 @@ public:
|
|||||||
|
|
||||||
void setContent(const QString &p_content, bool p_modified = false) Q_DECL_OVERRIDE;
|
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:
|
public slots:
|
||||||
bool jumpTitle(bool p_forward, int p_relativeLevel, int p_repeat) Q_DECL_OVERRIDE;
|
bool jumpTitle(bool p_forward, int p_relativeLevel, int p_repeat) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
@ -212,4 +218,14 @@ private:
|
|||||||
bool m_freshEdit;
|
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
|
#endif // VMDEDITOR_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user