diff --git a/src/resources/docs/shortcuts_en.md b/src/resources/docs/shortcuts_en.md index 2cfe0db3..7abd6b85 100644 --- a/src/resources/docs/shortcuts_en.md +++ b/src/resources/docs/shortcuts_en.md @@ -56,8 +56,8 @@ Insert bold. Press `Ctrl+B` again to exit. Current selected text will be changed Insert italic. Press `Ctrl+I` again to exit. Current selected text will be changed to italic if exists. - `Ctrl+D` Insert strikethrought. Press `Ctrl+D` again to exit. Current selected text will be changed to strikethrough if exists. -- `Ctrl+O` -Insert inline code. Press `Ctrl+O` again to exit. Current selected text will be changed to inline code if exists. +- `Ctrl+K` +Insert inline code. Press `Ctrl+K` again to exit. Current selected text will be changed to inline code if exists. - `Ctrl+M` Insert fenced code block. Press `Ctrl+M` again to exit. Current selected text will be wrapped into a code block if exists. - `Ctrl+L` @@ -254,6 +254,7 @@ VNote supports following features of Vim: - `n` and `N` to find next or previous occurence; - `Ctrl+N` and `Ctrl+P` to navigate through the search history; - `Ctrl+R` to read the content of a register; +- `Ctrl+O` in Insert mode to enter Normal mode temporarily; For now, VNote does **NOT** support the macro and repeat(`.`) features of Vim. diff --git a/src/resources/docs/shortcuts_zh.md b/src/resources/docs/shortcuts_zh.md index 60146c69..174dfc8e 100644 --- a/src/resources/docs/shortcuts_zh.md +++ b/src/resources/docs/shortcuts_zh.md @@ -56,8 +56,8 @@ 插入斜体;再次按`Ctrl+I`退出。如果已经选择文本,则将当前选择文本改为斜体。 - `Ctrl+D` 插入删除线;再次按`Ctrl+D`退出。如果已经选择文本,则将当前选择文本改为删除线。 -- `Ctrl+O` -插入行内代码;再次按`Ctrl+O`退出。如果已经选择文本,则将当前选择文本改为行内代码。 +- `Ctrl+K` +插入行内代码;再次按`Ctrl+K`退出。如果已经选择文本,则将当前选择文本改为行内代码。 - `Ctrl+M` 插入代码块;再次按`Ctrl+M`退出。如果已经选择文本,则将当前选择文本嵌入到代码块中。 - `Ctrl+L` @@ -255,6 +255,7 @@ VNote支持以下几个Vim的特性: - `n` 和 `N` 查找下一处或上一处; - `Ctrl+N` 和 `Ctrl+P` 浏览查找历史; - `Ctrl+R` 读取指定寄存器的值; +- `Ctrl+O` 在插入模式中临时切换为正常模式; VNote目前暂时不支持Vim的宏和重复(`.`)特性。 diff --git a/src/resources/icons/inline_code.svg b/src/resources/icons/inline_code.svg index b98f898e..ea166774 100644 --- a/src/resources/icons/inline_code.svg +++ b/src/resources/icons/inline_code.svg @@ -2,6 +2,6 @@ Layer 1 - O + K - \ No newline at end of file + diff --git a/src/resources/icons/search_wrap.svg b/src/resources/icons/search_wrap.svg index f1817595..984bd7b7 100644 --- a/src/resources/icons/search_wrap.svg +++ b/src/resources/icons/search_wrap.svg @@ -4,11 +4,11 @@ - - + - diff --git a/src/utils/vvim.cpp b/src/utils/vvim.cpp index bb24ebf0..8eea6890 100644 --- a/src/utils/vvim.cpp +++ b/src/utils/vvim.cpp @@ -107,11 +107,16 @@ static QString keyToString(int p_key, int p_modifiers) } VVim::VVim(VEditor *p_editor) - : QObject(p_editor->getEditor()), m_editor(p_editor), - m_editConfig(&p_editor->getConfig()), m_mode(VimMode::Invalid), - m_resetPositionInBlock(true), m_regName(c_unnamedRegister), - m_leaderKey(Key(Qt::Key_Space)), m_replayLeaderSequence(false), - m_registerPending(false) + : QObject(p_editor->getEditor()), + m_editor(p_editor), + m_editConfig(&p_editor->getConfig()), + m_mode(VimMode::Invalid), + m_resetPositionInBlock(true), + m_regName(c_unnamedRegister), + m_leaderKey(Key(Qt::Key_Space)), + m_replayLeaderSequence(false), + m_registerPending(false), + m_insertModeAfterCommand(false) { Q_ASSERT(m_editConfig->m_enableVimMode); @@ -512,6 +517,14 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos) goto accept; } + if (key == Qt::Key_O && isControlModifier(modifiers)) { + // Ctrl+O, enter normal mode, execute one command, then return to insert mode. + m_insertModeAfterCommand = true; + clearSelection(); + setMode(VimMode::Normal); + goto accept; + } + // Let it be handled outside VVim. goto exit; } @@ -2141,6 +2154,14 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos) clear_accept: resetState(); + + if (m_insertModeAfterCommand + && !checkMode(VimMode::Visual) + && !checkMode(VimMode::VisualLine)) { + m_insertModeAfterCommand = false; + setMode(VimMode::Insert); + } + m_editor->makeBlockVisible(m_editor->textCursorW().block()); accept: diff --git a/src/utils/vvim.h b/src/utils/vvim.h index 4e14be3d..37a7c99b 100644 --- a/src/utils/vvim.h +++ b/src/utils/vvim.h @@ -842,6 +842,9 @@ private: // Whether we are expecting to read a register to insert. bool m_registerPending; + // Whether enter insert mode after a command. + bool m_insertModeAfterCommand; + static const QChar c_unnamedRegister; static const QChar c_blackHoleRegister; static const QChar c_selectionRegister; diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 804eac11..8df3bbe1 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -452,7 +452,7 @@ void VMainWindow::initEditToolBar(QSize p_iconSize) m_editToolBar->addAction(strikethroughAct); QAction *inlineCodeAct = new QAction(QIcon(":/resources/icons/inline_code.svg"), - tr("Inline Code (Ctrl+O)"), this); + tr("Inline Code (Ctrl+K)"), this); inlineCodeAct->setStatusTip(tr("Insert inline-code text or change selected text to inline-coded")); connect(inlineCodeAct, &QAction::triggered, this, [this](){ diff --git a/src/vmdeditoperations.cpp b/src/vmdeditoperations.cpp index acf261a2..b75b9f2c 100644 --- a/src/vmdeditoperations.cpp +++ b/src/vmdeditoperations.cpp @@ -302,7 +302,7 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event) break; } - case Qt::Key_O: + case Qt::Key_K: { if (modifiers == Qt::ControlModifier) { decorateInlineCode(); diff --git a/src/vnote.cpp b/src/vnote.cpp index a2f4614a..f55d4256 100644 --- a/src/vnote.cpp +++ b/src/vnote.cpp @@ -79,9 +79,9 @@ void VNote::initPalette(QPalette palette) m_palette.append(QPair("hover-color", "#42A5F5")); m_palette.append(QPair("base-color", "#BDBDBD")); m_palette.append(QPair("focus-color", "#75C5B5")); - m_palette.append(QPair("logo-base", "#D6EACE")); - m_palette.append(QPair("logo-max", "#15AE67")); - m_palette.append(QPair("logo-min", "#75C5B5")); + m_palette.append(QPair("logo-base", "#F4F4F4")); + m_palette.append(QPair("logo-max", "#4D4D4D")); + m_palette.append(QPair("logo-min", "#C69C6D")); // Material Design Colors m_palette.append(QPair("Teal0", "#E0F2F1"));