Skip to content

Feat vim mode#1095

Draft
rileyhawk1417 wants to merge 62 commits intoAppFlowy-IO:mainfrom
rileyhawk1417:feat_vim_mode
Draft

Feat vim mode#1095
rileyhawk1417 wants to merge 62 commits intoAppFlowy-IO:mainfrom
rileyhawk1417:feat_vim_mode

Conversation

@rileyhawk1417
Copy link
Contributor

@rileyhawk1417 rileyhawk1417 commented Apr 13, 2025

This PR is meant to support Vim Mode in the main AppFlowy app. It does not conflict with the main editor and can be toggled on/off easily.

The documentation for it is a WIP and can be found at here.

Checklist:

  • Support basic keys [h, j, k, l]
    • Test Written
  • Support line jumping (e.g 4j, 10l)
    • Test Written
  • Undo & Redo
    • Test Written
  • Exit to Normal Mode and Insert Mode
    • Test Written
  • Text selection

- The initial start of developing the vim mode key bindings
Enable 'o', 'a', 'i' for insert mode with vim
- Allow h, j, k, l, keys for vim like movement in normal mode.
- Update cursor on vim movement.
- Display block style cursor when in normal mode.
- Allow block cursor selection with mouse.
- Ensure insert works with the current selection
- Add half page down command.
- Add page down command.
- Add move to start of the line command.
- Add move to end of the line command.

**Other features are there but still have bugs so they are commented out**
- Add extra checks to determine if vim mode is on or is in insertMode
- If vim mode is on all the other keybindings will listen in.
- If not they will be ignored.
- There are some bugs in it like deleting on an empty space will make the widget tree panic.
- The checks for vimMode all over files ensure that if the vim option is off.
- The user won't be affected with normal text.
- Ctrl+b for bold is a shortcut in vim to scroll a page for example
- Update keyboard shortcuts to work with current changes.
- The idea is to bind catch key events within the shortcuts layer
- The '0' key shortcut was conflicting with vim_fsm logic. Moved it from
vim.dart into vim_fsm to handle key behavior directly.
- In escape_command only set vim.NormalMode if Vim mode is enabled.
- State was becoming difficult to track in vim.dart
- This test is for 'move cursor to start' in vim mode
- Most of the keys in vim.dart were relying on the ShortcutEvents main
loop. Which resulted in accidental text edits.
- Removing the vim.dart from the shortcuts file, allowed vim_fsm.dart to
work properly.
- Any other key that is not listed or captured in vim_fsm.dart is
ignored.
- Since keys are being intercepted directly best to move them in one
location.
- These keys '0' is similar to 'Home' & '$' is similar to 'End'
- In previous commits spamming the 'escape' key resulted in the cursor
  disappearing from the screen.
- Handle 'o' in Normal Mode which creates a new line and allows input.
- Handle 'a' in Normal Mode which allows insert on next character in the
same line.
- Handle 'w' which navigates the cursor forward by a 'word'.
- By using the vim state class we can ensure that no key sequence is
missed by both the user and flutter tests.
- Also makes it easier to add/remove key handlers.
- The redo only happens for 1 step. It would require looking into
enhancing it.
- Removed some keys from vim.dart and put them in vim_fsm.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant