vim-mode: support Ctrl+O in Insert mode

- Support Ctrl+O in Insert mode to enter Normal mode temporarily;
- Use Ctrl+K instead of Ctrl+O to insert inline code;
This commit is contained in:
Le Tan 2017-11-07 19:52:36 +08:00
parent 93ba677116
commit 1e15b37a83
9 changed files with 45 additions and 19 deletions

View File

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

View File

@ -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的宏和重复(`.`)特性。

View File

@ -2,6 +2,6 @@
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
<g>
<title>Layer 1</title>
<text style="cursor: move;" fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">O</text>
<text style="cursor: move;" fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">K</text>
</g>
</svg>
</svg>

Before

Width:  |  Height:  |  Size: 515 B

After

Width:  |  Height:  |  Size: 516 B

View File

@ -4,11 +4,11 @@
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<g>
<rect width="512px" height="512px" fill="#D6EACE"/>
<path style="fill:#15AE67" d="M273.4,300.5l-0.3,58c48.9-8.2,86.3-51,86.3-102.5c0-15.9-3.6-31-10-44.5c-2.8-5.8-6-11.3-9.8-16.5l47.1-43.5
<rect width="512px" height="512px" fill="#F4F4F4"/>
<path style="fill:#4D4D4D" d="M273.4,300.5l-0.3,58c48.9-8.2,86.3-51,86.3-102.5c0-15.9-3.6-31-10-44.5c-2.8-5.8-6-11.3-9.8-16.5l47.1-43.5
c1.1,1.3,2.1,2.7,3.1,4c20.9,28,33.2,62.8,33.2,100.5c0,1.2,0,2.5,0,3.7c-1.5,71.5-47.6,132-111.4,154.6
c-12.3,4.3-25.2,7.3-38.5,8.7l-0.1,57l-76.2-67L170.6,390l44.4-38.7L273.4,300.5z"/>
<path style="fill:#15AE67" d="M89,252.3c1.6-72.1,48.3-133,112.9-155.2c11.7-4,24-6.8,36.8-8.1l0.1-57l76.1,66.9l26.2,23.1l-44.3,38.6l-58.4,50.9
<path style="fill:#4D4D4D" d="M89,252.3c1.6-72.1,48.3-133,112.9-155.2c11.7-4,24-6.8,36.8-8.1l0.1-57l76.1,66.9l26.2,23.1l-44.3,38.6l-58.4,50.9
l0.2-57.9c-48.8,8.3-86,51.1-86,102.4c0,16,3.6,31.1,10.1,44.7c2.7,5.8,6,11.2,9.7,16.3l-47,43.6c-1.3-1.6-2.6-3.3-3.8-5
C101.1,327.7,89,293.3,89,256C89,254.8,89,253.5,89,252.3z"/>
</g>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

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

View File

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

View File

@ -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](){

View File

@ -302,7 +302,7 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
break;
}
case Qt::Key_O:
case Qt::Key_K:
{
if (modifiers == Qt::ControlModifier) {
decorateInlineCode();

View File

@ -79,9 +79,9 @@ void VNote::initPalette(QPalette palette)
m_palette.append(QPair<QString, QString>("hover-color", "#42A5F5"));
m_palette.append(QPair<QString, QString>("base-color", "#BDBDBD"));
m_palette.append(QPair<QString, QString>("focus-color", "#75C5B5"));
m_palette.append(QPair<QString, QString>("logo-base", "#D6EACE"));
m_palette.append(QPair<QString, QString>("logo-max", "#15AE67"));
m_palette.append(QPair<QString, QString>("logo-min", "#75C5B5"));
m_palette.append(QPair<QString, QString>("logo-base", "#F4F4F4"));
m_palette.append(QPair<QString, QString>("logo-max", "#4D4D4D"));
m_palette.append(QPair<QString, QString>("logo-min", "#C69C6D"));
// Material Design Colors
m_palette.append(QPair<QString, QString>("Teal0", "#E0F2F1"));