support Vim command mode in read mode

This commit is contained in:
Le Tan 2018-01-21 14:27:10 +08:00
parent 5d672e7fc6
commit 06cac36412
7 changed files with 97 additions and 35 deletions

6
.gitignore vendored
View File

@ -1,6 +0,0 @@
.DS_Store
.idea
VNote.pro.user
VNote.pro.user.*

View File

@ -38,18 +38,30 @@ Zoom in/out the page through the mouse scroll.
- `Ctrl+0`
Recover the page zoom factor to 100%.
- Jump between titles
- `[[`: jump to previous title;
- `]]`: jump to next title;
- `[]`: jump to previous title at the same level;
- `][`: jump to next title at the same level;
- `[{`: jump to previous title at a higher level;
- `]}`: jump to next title at a higher level;
- `<N>[[`: jump to previous `N` title;
- `<N>]]`: jump to next `N` title;
- `<N>[]`: jump to previous `N` title at the same level;
- `<N>][`: jump to next `N` title at the same level;
- `<N>[{`: jump to previous `N` title at a higher level;
- `<N>]}`: jump to next `N` title at a higher level;
- `/` or `?` to search forward or backward
- `N`: find next match;
- `Shift+N`: find previous match;
- `:` for Vim command
- `:q`: close current note;
- `:noh[lsearch]`: clear search highlights;
### Edit Mode
- `Ctrl+S`
Save current changes.
- `Ctrl+T`
Save current changes and exit edit mode.
- `Ctrl + +/-`
Zoom in/out the page.
- `Ctrl+Wheel`
Zoom in/out the page through the mouse scroll.
- `Ctrl+0`
Recover the page zoom factor to 100%.
#### Text Editing
- `Ctrl+B`
@ -252,7 +264,7 @@ VNote supports following features of Vim:
- `zz`, `zb`, `zt`;
- `u` and `Ctrl+R` for undo and redo;
- Text objects `i/a`: word, WORD, `''`, `""`, `` ` ` ``, `()`, `[]`, `<>`, and `{}`;
- Command line `:w`, `:wq`, `:x`, `:q`, `:q!`, and `:nohlsearch`;
- Command line `:w`, `:wq`, `:x`, `:q`, `:q!`, and `:noh[lsearch]`;
- Jump between titles
- `[[`: jump to previous title;
- `]]`: jump to next title;

View File

@ -38,18 +38,30 @@
- `Ctrl+0`
恢复页面大小为100%。
- 标题跳转
- `[[`:跳转到上一个标题;
- `]]`: 跳转到下一个标题;
- `[]`:跳转到上一个同层级的标题;
- `][`:跳转到下一个同层级的标题;
- `[{`:跳转到上一个高一层级的标题;
- `]}`:跳转到下一个高一层级的标题;
- `<N>[[`:跳转到上`N`个标题;
- `<N>]]`: 跳转到下`N`个标题;
- `<N>[]`:跳转到上`N`个同层级的标题;
- `<N>][`:跳转到下`N`个同层级的标题;
- `<N>[{`:跳转到上`N`个高一层级的标题;
- `<N>]}`:跳转到下`N`个高一层级的标题;
- `/``?`向前或向后查找
- `N`:查找下一个匹配;
- `Shift+N`:查找上一个匹配;
- `:`执行Vim命令
- `:q`:关闭当前笔记;
- `:noh[lsearch]`:清空查找高亮;
### 编辑模式
- `Ctrl+S`
保存当前更改。
- `Ctrl+T`
保存当前更改并退出编辑模式。
- `Ctrl + +/-`
放大/缩小页面。
- `Ctrl+Wheel`
鼠标滚轮实现放大/缩小页面。
- `Ctrl+0`
恢复页面大小为100%。
#### 文本编辑
- `Ctrl+B`
@ -253,7 +265,7 @@ VNote支持以下几个Vim的特性
- `zz`, `zb`, `zt`;
- `u``Ctrl+R` 撤销和重做;
- 文本对象 `i/a`word, WORD, `''`, `""`, `` ` ` ``, `()`, `[]`, `<>`, `{}`;
- 命令行 `:w`, `:wq`, `:x`, `:q`, `:q!`, `:nohlsearch`;
- 命令行 `:w`, `:wq`, `:x`, `:q`, `:q!`, `:noh[lsearch]`;
- 标题跳转
- `[[`:跳转到上一个标题;
- `]]`: 跳转到下一个标题;
@ -266,6 +278,7 @@ VNote支持以下几个Vim的特性
- `Ctrl+N``Ctrl+P` 浏览查找历史;
- `Ctrl+R` 读取指定寄存器的值;
- `Ctrl+O` 在插入模式中临时切换为正常模式;
- `/`
VNote目前暂时不支持Vim的宏和重复(`.`)特性。

View File

@ -5835,7 +5835,7 @@ bool VVim::executeCommand(const QString &p_cmd)
Q_ASSERT(m_tokens.isEmpty() && m_keys.isEmpty());
if (p_cmd.isEmpty()) {
return true;
}else if (p_cmd.size() == 1) {
} else if (p_cmd.size() == 1) {
if (p_cmd == "w") {
// :w, save current file.
emit m_editor->object()->saveNote();
@ -5864,7 +5864,7 @@ bool VVim::executeCommand(const QString &p_cmd)
} else {
validCommand = false;
}
} else if (p_cmd == "nohlsearch") {
} else if (p_cmd == "nohlsearch" || p_cmd == "noh") {
// :nohlsearch, clear highlight search.
clearSearchHighlight();
} else {

View File

@ -285,7 +285,9 @@ void VEditWindow::removeEditTab(int p_index)
Q_ASSERT(p_index > -1 && p_index < tabBar()->count());
VEditTab *editor = getTab(p_index);
removeTab(p_index);
delete editor;
}

View File

@ -696,6 +696,16 @@ void VMdTab::handleWebKeyPressed(int p_key, bool p_ctrl, bool p_shift)
break;
// :
case 186:
if (!p_ctrl && p_shift) {
VVim::CommandLineType type = VVim::CommandLineType::Command;
emit triggerVimCmd(type);
}
break;
// n or N
case 78:
if (!p_ctrl) {
@ -1078,8 +1088,6 @@ void VMdTab::handleVimCmdCommandCancelled()
if (vim) {
vim->processCommandLineCancelled();
}
} else {
m_webViewer->findText("");
}
}
@ -1091,13 +1099,16 @@ void VMdTab::handleVimCmdCommandFinished(VVim::CommandLineType p_type, const QSt
vim->processCommandLine(p_type, p_cmd);
}
} else {
Q_ASSERT(p_type == VVim::CommandLineType::SearchForward
|| p_type == VVim::CommandLineType::SearchBackward);
m_lastSearchItem = VVim::fetchSearchItem(p_type, p_cmd);
findTextInWebView(m_lastSearchItem.m_text,
m_lastSearchItem.m_options,
false,
m_lastSearchItem.m_forward);
if (p_type == VVim::CommandLineType::SearchForward
|| p_type == VVim::CommandLineType::SearchBackward) {
m_lastSearchItem = VVim::fetchSearchItem(p_type, p_cmd);
findTextInWebView(m_lastSearchItem.m_text,
m_lastSearchItem.m_options,
false,
m_lastSearchItem.m_forward);
} else {
executeVimCommandInWebView(p_cmd);
}
}
}
@ -1111,10 +1122,11 @@ void VMdTab::handleVimCmdCommandChanged(VVim::CommandLineType p_type, const QStr
vim->processCommandLineChanged(p_type, p_cmd);
}
} else {
Q_ASSERT(p_type == VVim::CommandLineType::SearchForward
|| p_type == VVim::CommandLineType::SearchBackward);
VVim::SearchItem item = VVim::fetchSearchItem(p_type, p_cmd);
findTextInWebView(item.m_text, item.m_options, true, item.m_forward);
if (p_type == VVim::CommandLineType::SearchForward
|| p_type == VVim::CommandLineType::SearchBackward) {
VVim::SearchItem item = VVim::fetchSearchItem(p_type, p_cmd);
findTextInWebView(item.m_text, item.m_options, true, item.m_forward);
}
}
}
@ -1159,3 +1171,30 @@ QString VMdTab::handleVimCmdRequestRegister(int p_key, int p_modifiers)
return QString();
}
bool VMdTab::executeVimCommandInWebView(const QString &p_cmd)
{
bool validCommand = true;
QString msg;
if (p_cmd.isEmpty()) {
return true;
} else if (p_cmd == "q") {
// :q, close the note.
emit closeRequested(this);
msg = tr("Quit");
} else if (p_cmd == "nohlsearch" || p_cmd == "noh") {
// :nohlsearch, clear highlight search.
m_webViewer->findText("");
} else {
validCommand = false;
}
if (!validCommand) {
g_mainWin->showStatusMessage(tr("Not an editor command: %1").arg(p_cmd));
} else {
g_mainWin->showStatusMessage(msg);
}
return validCommand;
}

View File

@ -198,6 +198,8 @@ private:
void textToHtmlViaWebView(const QString &p_text);
bool executeVimCommandInWebView(const QString &p_cmd);
VMdEditor *m_editor;
VWebView *m_webViewer;
VDocument *m_document;