浏览代码

vim-mode: support g0 (start of visual line)

Le Tan 8 年之前
父节点
当前提交
2c1e8e33fe
共有 4 个文件被更改,包括 29 次插入12 次删除
  1. 3 1
      src/resources/docs/shortcuts_en.md
  2. 3 1
      src/resources/docs/shortcuts_zh.md
  3. 22 10
      src/utils/vvim.cpp
  4. 1 0
      src/utils/vvim.h

+ 3 - 1
src/resources/docs/shortcuts_en.md

@@ -64,6 +64,8 @@ Insert inline code. Press `Ctrl+K` again to exit. Current selected text will be
 Insert fenced code block. Press `Ctrl+M` again to exit. Current selected text will be wrapped into a code block if exists.
 - `Ctrl+L`  
 Insert link.
+- `Ctrl+'`  
+Insert image.
 - `Ctrl+H`  
 Backspace. Delete a character backward.
 - `Ctrl+W`  
@@ -239,7 +241,7 @@ VNote supports following features of Vim:
 
 - `r`, `s`, `S`, `i`, `I`, `a`, `A`, `c`, `C`, `o`, and `O`;
 - Actions `d`, `c`, `y`, `p`, `<`, `>`, `gu`, `gU`, `J`, `gJ`, and `~`;
-- Movements `h/j/k/l`, `gj/gk`, `Ctrl+U`, `Ctrl+D`, `gg`, `G`, `0`, `^`, `{`, `}`, and `$`;
+- Movements `h/j/k/l`, `gj/gk/g0`, `Ctrl+U`, `Ctrl+D`, `gg`, `G`, `0`, `^`, `{`, `}`, and `$`;
 - Marks `a-z`;
 - Registers `"`, `_`, `+`, `a-z`(`A-Z`);
 - Jump locations list (`Ctrl+O` and `Ctrl+I`);

+ 3 - 1
src/resources/docs/shortcuts_zh.md

@@ -64,6 +64,8 @@
 插入代码块;再次按`Ctrl+M`退出。如果已经选择文本,则将当前选择文本嵌入到代码块中。
 - `Ctrl+L`  
 插入链接。
+- `Ctrl+'`  
+插入图片。
 - `Ctrl+H`  
 退格键,向前删除一个字符。
 - `Ctrl+W`  
@@ -240,7 +242,7 @@ VNote支持以下几个Vim的特性:
 
 - `r`, `s`, `S`, `i`, `I`, `a`, `A`, `c`, `C`, `o`, `O`;
 - 操作 `d`, `c`, `y`, `p`, `<`, `>`, `gu`, `gU`, `J`, `gJ`, `~`;
-- 移动 `h/j/k/l`, `gj/gk`, `Ctrl+U`, `Ctrl+D`, `gg`, `G`, `0`, `^`, `{`, `}`, `$`;
+- 移动 `h/j/k/l`, `gj/gk/g0`, `Ctrl+U`, `Ctrl+D`, `gg`, `G`, `0`, `^`, `{`, `}`, `$`;
 - 标记 `a-z`;
 - 寄存器 `"`, `_`, `+`, `a-z`(`A-Z`);
 - 跳转位置列表 (`Ctrl+O` and `Ctrl+I`);

+ 22 - 10
src/utils/vvim.cpp

@@ -647,20 +647,21 @@ bool VVim::handleKeyPressEvent(int key, int modifiers, int *p_autoIndentPos)
     {
         if (modifiers == Qt::NoModifier
             || modifiers == Qt::KeypadModifier) {
-            if (!m_keys.isEmpty()) {
-                // Repeat.
-                V_ASSERT(m_keys.last().isDigit());
-
-                m_keys.append(keyInfo);
-                resetPositionInBlock = false;
-                goto accept;
-            } else {
+            if (checkPendingKey(Key(Qt::Key_G))) {
+                // StartOfVisualLine.
+                tryAddMoveAction();
+                m_tokens.append(Token(Movement::StartOfVisualLine));
+                processCommand(m_tokens);
+            } else if (m_keys.isEmpty()) {
                 // StartOfLine.
                 tryAddMoveAction();
-
                 m_tokens.append(Token(Movement::StartOfLine));
-
                 processCommand(m_tokens);
+            } else if (m_keys.last().isDigit()) {
+                // Repeat.
+                m_keys.append(keyInfo);
+                resetPositionInBlock = false;
+                goto accept;
             }
         }
 
@@ -2694,6 +2695,17 @@ bool VVim::processMovement(QTextCursor &p_cursor,
         break;
     }
 
+    case Movement::StartOfVisualLine:
+    {
+        // Start of the visual line.
+        if (!p_cursor.atBlockStart()) {
+            p_cursor.movePosition(QTextCursor::StartOfLine, p_moveMode, 1);
+            hasMoved = true;
+        }
+
+        break;
+    }
+
     case Movement::EndOfLine:
     {
         // End of line (block).

+ 1 - 0
src/utils/vvim.h

@@ -396,6 +396,7 @@ private:
         PageDown,
         HalfPageUp,
         HalfPageDown,
+        StartOfVisualLine,
         StartOfLine,
         EndOfLine,
         FirstCharacter,