vimamsa 0.1.26 → 0.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +93 -0
- data/.gitignore +4 -1
- data/Dockerfile +7 -4
- data/README.md +195 -99
- data/custom_example.rb +59 -17
- data/doc/TODO.md +678 -0
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +570 -0
- data/doc/delta_syntax_plan.md +293 -0
- data/doc/demo_recording_plan.md +288 -0
- data/doc/design_goals.md +27 -0
- data/doc/intro_page_plan.md +266 -0
- data/doc/key_bindings_report_plan.md +213 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +61 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +451 -0
- data/doc/vimlike_vim_conflicts.md +262 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/doc/wysiwyg_plan.md +231 -0
- data/exe/run_tests.rb +124 -3
- data/exe/vimamsa +68 -5
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +7 -1
- data/lib/vimamsa/ack.rb +13 -1
- data/lib/vimamsa/actions.rb +385 -37
- data/lib/vimamsa/appimage_env.rb +35 -0
- data/lib/vimamsa/audio.rb +2 -5
- data/lib/vimamsa/bookmarks.rb +302 -0
- data/lib/vimamsa/buffer.rb +675 -118
- data/lib/vimamsa/buffer_changetext.rb +150 -68
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +6 -2
- data/lib/vimamsa/buffer_manager.rb +10 -7
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +9 -3
- data/lib/vimamsa/conf.rb +68 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +6 -3
- data/lib/vimamsa/demo_player.rb +458 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +40 -11
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +57 -3
- data/lib/vimamsa/editor.rb +327 -78
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +4 -1
- data/lib/vimamsa/file_manager.rb +46 -31
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +603 -119
- data/lib/vimamsa/gui_command_line.rb +247 -0
- data/lib/vimamsa/gui_dialog.rb +94 -42
- data/lib/vimamsa/gui_file_panel.rb +356 -25
- data/lib/vimamsa/gui_form_generator.rb +75 -40
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +408 -0
- data/lib/vimamsa/gui_menu.rb +84 -53
- data/lib/vimamsa/gui_select_window.rb +80 -75
- data/lib/vimamsa/gui_settings.rb +86 -41
- data/lib/vimamsa/gui_sourceview.rb +280 -92
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +615 -0
- data/lib/vimamsa/hook.rb +5 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/intro_page.rb +368 -0
- data/lib/vimamsa/key_actions.rb +382 -193
- data/lib/vimamsa/key_binding_tree.rb +467 -273
- data/lib/vimamsa/key_bindings_notepad.rb +45 -0
- data/lib/vimamsa/key_bindings_report.rb +484 -0
- data/lib/vimamsa/key_bindings_vim.rb +104 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +23 -3
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +41 -1
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +15 -14
- data/lib/vimamsa/string_util.rb +134 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +11 -8
- data/lib/vimamsa/text_objects.rb +310 -0
- data/lib/vimamsa/text_transforms.rb +18 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_core.rb +355 -0
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/lib/vimamsa.rb +0 -1
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +118 -0
- data/modules/color_highlight/color_highlight_info.rb +3 -0
- data/modules/dictation/dictation.rb +1054 -0
- data/modules/dictation/dictation_info.rb +3 -0
- data/modules/dictation/whisper_worker.py +273 -0
- data/modules/ollama/ollama.rb +107 -0
- data/modules/ollama/ollama_info.rb +3 -0
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.rb +138 -0
- data/scripts/appimage/AppRun +54 -0
- data/scripts/appimage/Dockerfile +18 -0
- data/scripts/appimage/build.sh +19 -0
- data/scripts/appimage/build_in_container.sh +192 -0
- data/scripts/appimage/smoke_test.sh +27 -0
- data/scripts/demo/demo_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +67 -0
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +156 -0
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +29 -0
- data/scripts/demo/square/shapes.rb +29 -0
- data/scripts/demo/square/steps.txt +185 -0
- data/scripts/lib/perf_startup.rb +138 -0
- data/scripts/lib/script_helpers.rb +53 -0
- data/scripts/perf_compare.rb +34 -0
- data/scripts/profile_startup.rb +72 -0
- data/styles/134272-molokai.xml +3 -0
- data/styles/molokai_cyber.xml +48 -0
- data/styles/molokai_edit.xml +1 -0
- data/tests/support/virtual_keyboard.rb +254 -0
- data/tests/support/virtual_mic.rb +67 -0
- data/tests/test_ack.rb +22 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +122 -0
- data/tests/test_autocomplete.rb +211 -0
- data/tests/test_autosave.rb +145 -0
- data/tests/test_basic_editing.rb +46 -16
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +88 -0
- data/tests/test_bundling.rb +92 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +92 -0
- data/tests/test_command_line.rb +79 -0
- data/tests/test_command_line_file.rb +27 -0
- data/tests/test_context_menu_file.rb +147 -0
- data/tests/test_copy_paste.rb +106 -26
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -0
- data/tests/test_demo_player.rb +301 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dialog_callback_errors.rb +44 -0
- data/tests/test_dictation.rb +294 -0
- data/tests/test_diff_buffer_name.rb +51 -0
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_double_click.rb +41 -0
- data/tests/test_drag_selection.rb +125 -0
- data/tests/test_e2e_cmdline.rb +116 -0
- data/tests/test_e2e_dictation.rb +98 -0
- data/tests/test_e2e_replace_char.rb +58 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +55 -0
- data/tests/test_file_format.rb +217 -0
- data/tests/test_file_manager.rb +72 -0
- data/tests/test_file_panel.rb +269 -0
- data/tests/test_flash.rb +78 -0
- data/tests/test_fold.rb +111 -0
- data/tests/test_font_refresh.rb +56 -0
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +68 -0
- data/tests/test_grep_apply.rb +46 -0
- data/tests/test_gtk_sync.rb +126 -0
- data/tests/test_hpt_highlight_visible.rb +75 -0
- data/tests/test_hpt_link_highlight.rb +82 -0
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +261 -0
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +281 -0
- data/tests/test_lsp_jump.rb +87 -0
- data/tests/test_lsp_position_encoding.rb +49 -0
- data/tests/test_lsp_symbols.rb +68 -0
- data/tests/test_macro.rb +137 -0
- data/tests/test_markdown_highlight.rb +57 -0
- data/tests/test_mode_badge.rb +41 -0
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +67 -0
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_registers.rb +122 -0
- data/tests/test_revert.rb +127 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +58 -0
- data/tests/test_status_area.rb +50 -0
- data/tests/test_text_objects.rb +163 -0
- data/tests/test_text_transforms.rb +341 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +353 -0
- data/tests/test_vim_conflicts.rb +100 -0
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +302 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +129 -0
- metadata +167 -10
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# Plan: introduction page for first-time users
|
|
2
|
+
|
|
3
|
+
Done (2026-11-21, `6448bb9`). See DONE.
|
|
4
|
+
|
|
5
|
+
## Context
|
|
6
|
+
|
|
7
|
+
A new user starts with an empty buffer and no hint of where to begin. The demos
|
|
8
|
+
(basic editing, easy jump, switching files) show the editor well, but they're three
|
|
9
|
+
levels deep in the menu (Help ▸ Demos ▸ …), so most people won't find them. The key
|
|
10
|
+
bindings page is complete but long.
|
|
11
|
+
|
|
12
|
+
An introduction page opens automatically on the first start and is always available
|
|
13
|
+
as Help ▸ Introduction. It's a short text page with buttons that start the
|
|
14
|
+
recommended demos and open the other help pages.
|
|
15
|
+
|
|
16
|
+
## What exists to build on
|
|
17
|
+
|
|
18
|
+
- **Hyperplaintext** (`lang/hyperplaintext.lang`, `hyper_plain_text.rb`): `❙title❙`,
|
|
19
|
+
`◼ heading`, `⦁key⦁`, and links `⟦file⟧` / `⟦help:keybindings⟧`, which open with
|
|
20
|
+
enter or the context menu (`Buffer#handle_word`, `wtype == :help`,
|
|
21
|
+
`gui_sourceview.rb` `ctx_open_link`). The key bindings page and `demo.txt` use it.
|
|
22
|
+
- **Widgets embedded in the text:** the image code (`buffer.rb`, the
|
|
23
|
+
`create_child_anchor` / `add_child_at_anchor` calls) puts GTK widgets into the
|
|
24
|
+
text. Buttons can work the same way. (Audio widgets use this too, but audio is
|
|
25
|
+
experimental: the intro page doesn't use or mention it.)
|
|
26
|
+
- **Demos:** `DemoPlayer.toggle(name)`, the actions `help.demo`,
|
|
27
|
+
`help.demo.easyjump` and `help.demo.files`, and `DemoPlayer::DEMOS`.
|
|
28
|
+
- **Bindings generated from the live tree:** `key_bindings_page` uses `BASIC_ACTIONS`
|
|
29
|
+
and `vma.kbd.bindings`, so the keys it shows are right for the current scheme.
|
|
30
|
+
- **Vim differences:** `doc/vimlike_vim_conflicts.md` and the `help.vim_conflicts`
|
|
31
|
+
page list every key that differs, and `doc/missing_vim_bindings.md` lists what is
|
|
32
|
+
missing. Both are complete but long; the intro page links to a short summary (see
|
|
33
|
+
"For Vim users").
|
|
34
|
+
- **First run:** `Editor#start` already creates `custom.rb` from `custom_example.rb`
|
|
35
|
+
when it doesn't exist.
|
|
36
|
+
|
|
37
|
+
## Design
|
|
38
|
+
|
|
39
|
+
### Format: a hyperplaintext page in a read-only buffer, with buttons
|
|
40
|
+
|
|
41
|
+
The page is a template, `intro.txt` (next to `demo.txt`, shipped in the gem). It
|
|
42
|
+
opens in a buffer named `intro` with the hyperplaintext language, like the key
|
|
43
|
+
bindings page. Reasons:
|
|
44
|
+
|
|
45
|
+
- It's an ordinary editor buffer, so the reader is already using the editor: moving
|
|
46
|
+
around and searching work, and so does the key log.
|
|
47
|
+
- Every button is also a link, so it can be reached with the keyboard. Put the
|
|
48
|
+
cursor on it and press enter. The mouse works too.
|
|
49
|
+
- It's easy to edit: the text is a file, not GTK code.
|
|
50
|
+
|
|
51
|
+
A separate dialog was rejected: demos play in the main window, and a dialog would
|
|
52
|
+
have to close or get in the way.
|
|
53
|
+
|
|
54
|
+
### New link kind: `⟦run:<action>|<label>⟧`
|
|
55
|
+
|
|
56
|
+
- `Buffer#handle_word` gets a `:run` type next to `:help`; enter on the link runs the
|
|
57
|
+
action with `call_action`.
|
|
58
|
+
- **Only actions in an allowlist run:** `help.*`, `app.demo`, `settings.*` (decide
|
|
59
|
+
the exact list). Any `.txt` file can contain this syntax, so opening a downloaded
|
|
60
|
+
file must not be able to run arbitrary actions. Outside the list, the link only
|
|
61
|
+
shows a message.
|
|
62
|
+
- **Buttons:** on a help page, each `⟦run:…⟧` link is shown as a `Gtk::Button`
|
|
63
|
+
with the label after `|`, in place of the link's text. The text stays in the
|
|
64
|
+
buffer but is hidden by an invisible GTK tag. The button is at a child anchor
|
|
65
|
+
that takes the place of a space the page adds before the link (before, because
|
|
66
|
+
GTK doesn't draw a widget that follows invisible text). Clicking the button runs
|
|
67
|
+
the action. In a buffer that can be edited, the link text is shown instead of
|
|
68
|
+
the button while the cursor is on its line. In a read-only one (the help pages)
|
|
69
|
+
the button is always shown; a cursor on the hidden text moves onto the button,
|
|
70
|
+
and enter there runs the link.
|
|
71
|
+
- `⟦help:…⟧` gets more targets: `keybindings` (exists), `vim_conflicts`, `intro`,
|
|
72
|
+
`vim_intro`.
|
|
73
|
+
|
|
74
|
+
### Keys in the text come from the bindings
|
|
75
|
+
|
|
76
|
+
The template says `{key:mode.insert}`, `{key:buf.save}` and so on. When the page is
|
|
77
|
+
opened, these are replaced with the bound keys from `vma.kbd.bindings` (the first
|
|
78
|
+
binding in Command mode, formatted as on the key bindings page, in `⦁…⦁`). The page
|
|
79
|
+
stays right when bindings change or with the notepad scheme. An action that has no
|
|
80
|
+
binding shows its menu path or the `:` command instead. A test checks that every
|
|
81
|
+
`{key:…}` in the template resolves.
|
|
82
|
+
|
|
83
|
+
### Content (keep it to about one screen)
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
❙Welcome to Vimamsa❙
|
|
87
|
+
A Vim-inspired text editor. This page: Help ▸ Introduction.
|
|
88
|
+
|
|
89
|
+
◼ Modes
|
|
90
|
+
Command mode: keys move and edit (badge at the bottom right shows the mode).
|
|
91
|
+
Insert mode: keys type text. Enter it with {key:mode.insert}, leave it with {key:mode.prev}.
|
|
92
|
+
Visual mode: select text, {key:mode.visual}.
|
|
93
|
+
|
|
94
|
+
◼ Watch a demo (each plays in its own buffer; the key log on the right
|
|
95
|
+
shows every key and what it did)
|
|
96
|
+
⟦run:help.demo|▶ Basic editing⟧ moving, editing, undo ~1 min
|
|
97
|
+
⟦run:help.demo.easyjump|▶ Easy jump⟧ jump anywhere on screen ~40 s
|
|
98
|
+
⟦run:help.demo.files|▶ Switching files⟧ file finder, buffer history ~40 s
|
|
99
|
+
|
|
100
|
+
◼ The essentials
|
|
101
|
+
Open file {key:file.open} File finder {key:file.finder} Save {key:buf.save}
|
|
102
|
+
Search {key:search.buf} Undo {key:undo.last} Command line {key:mode.cmdline}
|
|
103
|
+
|
|
104
|
+
◼ Coming from Vim?
|
|
105
|
+
⟦help:vim_intro⟧ the main differences, in one screen
|
|
106
|
+
|
|
107
|
+
◼ Learn more
|
|
108
|
+
⟦help:keybindings⟧ all key bindings
|
|
109
|
+
⟦run:app.demo|Install demo files⟧ text and images to try
|
|
110
|
+
Customize: ⟦~/.config/vimamsa/custom.rb⟧ (Ruby, loaded at startup)
|
|
111
|
+
|
|
112
|
+
⟦run:help.intro.toggle_startup|Don't show at startup⟧
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The demo lengths are measured, not guessed: `DemoPlayer` can sum the waits and
|
|
116
|
+
delays of a steps file. They could be generated like the keys (`{demo_len:basic}`).
|
|
117
|
+
|
|
118
|
+
### For Vim users: a one-screen summary
|
|
119
|
+
|
|
120
|
+
A second short page, `vim_intro.txt`, opened by `⟦help:vim_intro⟧` on the intro
|
|
121
|
+
page. It lists the differences a Vim user hits in the first minutes, and ends with
|
|
122
|
+
links to the full lists. Its keys use `{key:…}` too, so it stays right when the
|
|
123
|
+
bindings change. Content, from what the code does now (2026-11-21):
|
|
124
|
+
|
|
125
|
+
- **`:` is very limited.** It understands only `:w`, `:q`, `:wq`, `:e <file>`, `:<line
|
|
126
|
+
number>`, `:!<shell command>` (output into a buffer) and `:reg`. Anything else is
|
|
127
|
+
run as Ruby, so there is no `:s///`, `:g`, `:set`, `:%`, ranges or `:help`. Search
|
|
128
|
+
and replace has its own commands (`{key:search.buf}`, the Search menu), and settings
|
|
129
|
+
are in Settings.
|
|
130
|
+
- **ctrl alone switches modes.** Press and release ctrl with no other key in between:
|
|
131
|
+
in Command mode it enters Insert mode, and in Insert and Visual mode it leaves
|
|
132
|
+
them. `esc` works
|
|
133
|
+
too, but it doesn't move the cursor one character left as Vim's does.
|
|
134
|
+
- **Some keys do other things:**
|
|
135
|
+
|
|
136
|
+
| Key | Vim | Vimlike |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `s` | change a character | easy jump |
|
|
139
|
+
| `C` | change to end of line | grep in files |
|
|
140
|
+
| `O` | open a line above | end of line |
|
|
141
|
+
| `X` | delete a character back | new line below |
|
|
142
|
+
| `space` | right | prefix: `space <char>` inserts a character |
|
|
143
|
+
| `tab` | jump forward | switch to the last buffer |
|
|
144
|
+
| `z` | prefix (`zz`, `zt`) | Browse mode |
|
|
145
|
+
| `ctrl-o` | jump back | open a file |
|
|
146
|
+
| Insert `ctrl-n` / `ctrl-p` | completion | line down / up |
|
|
147
|
+
| Insert `ctrl-c` | leave Insert mode | copy |
|
|
148
|
+
|
|
149
|
+
`,` starts many of vimlike's own commands (see the key bindings page).
|
|
150
|
+
- **Not there yet:** line-wise and block visual (`V`, `ctrl-v`); `ge`, `{` / `}`,
|
|
151
|
+
`%`; `=` and `gq`; `ctrl-e` / `ctrl-y`; `gv` and `gi`.
|
|
152
|
+
- **The same as Vim:** operators with motions and text objects (`d c y gU gu g~ >
|
|
153
|
+
<`, `dw`, `ci(`, `yap` …), counts, registers (`"a`–`"z`, `"+`), `.`, macros
|
|
154
|
+
(`q` / `@`), marks.
|
|
155
|
+
- **Prefer Vim's keys?** Settings ▸ Keybinding scheme ▸ `vim` (restart needed).
|
|
156
|
+
- Links: ⟦help:vim_conflicts⟧ (every key that differs, generated) and the list of
|
|
157
|
+
missing Vim bindings.
|
|
158
|
+
|
|
159
|
+
The table is short on purpose: it doesn't try to list all 42 conflicts. A test
|
|
160
|
+
checks each row against the live bindings (e.g. that `s` runs `jump.easy` in
|
|
161
|
+
vimlike), so the page can't drift from the keymap unnoticed. Rows could be
|
|
162
|
+
generated from `vim_binding_conflicts` with a hand-picked list of keys, but then
|
|
163
|
+
someone still has to write each description.
|
|
164
|
+
|
|
165
|
+
### When it is shown
|
|
166
|
+
|
|
167
|
+
- **`--intro`** on the command line shows the page at start whatever the setting,
|
|
168
|
+
the user dir or other arguments say, and doesn't change the setting. It's for
|
|
169
|
+
trying the page and for tests: `ruby exe/vimamsa --intro`, or with a fresh
|
|
170
|
+
`--user-dir` to see a real first start.
|
|
171
|
+
- Shown on start when `cnf.intro.show_on_startup` is true. It defaults to true and
|
|
172
|
+
is set to false after the page has been shown once, so normally the page appears
|
|
173
|
+
only on the first start.
|
|
174
|
+
- The setting is in Settings ▸ Behavior, and the page's last button changes it.
|
|
175
|
+
- **Not shown** when:
|
|
176
|
+
- files or dirs are given on the command line;
|
|
177
|
+
- a session is being restored;
|
|
178
|
+
- in test mode (`vma_test_mode?`, as for `check_session_restore`);
|
|
179
|
+
- `cnf.startup_file` is set.
|
|
180
|
+
|
|
181
|
+
In those cases the user already knows what they want.
|
|
182
|
+
- **Always available:**
|
|
183
|
+
- Help ▸ Introduction, the first item in the Help menu;
|
|
184
|
+
- the action `help.intro` (no key binding: the menu is enough);
|
|
185
|
+
- `:intro` on the command line.
|
|
186
|
+
- The intro buffer is read-only and isn't saved in the session or file history.
|
|
187
|
+
Opening it again switches to the existing buffer.
|
|
188
|
+
|
|
189
|
+
### Demos started from the page
|
|
190
|
+
|
|
191
|
+
- A demo stops when another buffer is opened. When it was started from the intro
|
|
192
|
+
page, stopping it or letting it finish returns to the page (`DemoPlayer` remembers
|
|
193
|
+
the buffer it was started from), so the next demo is one click away.
|
|
194
|
+
- Demos keep looping until stopped (current behaviour). The demo controls (pause,
|
|
195
|
+
speed, ✕) are already shown above the key log.
|
|
196
|
+
|
|
197
|
+
### Switching demos while one plays
|
|
198
|
+
|
|
199
|
+
While a demo plays, the demo controls above the key log
|
|
200
|
+
(`gui_keylog_panel.rb`, `show_demo_controls`) also list the demos, so the user can
|
|
201
|
+
go to another one without the menu or the intro page:
|
|
202
|
+
|
|
203
|
+
- A dropdown (`Gtk::DropDown`) next to the pause and speed buttons, with the demo
|
|
204
|
+
titles from `DemoPlayer::DEMOS` and the current one selected. Choosing another
|
|
205
|
+
demo calls `DemoPlayer.toggle(name)`, which stops the playing one and starts the
|
|
206
|
+
new one, keeping the speed setting. Optionally add "Next ▸", which starts the next
|
|
207
|
+
demo in the list.
|
|
208
|
+
- For this, each demo in `DemoPlayer::DEMOS` gets a `title:` ("Basic editing") and a
|
|
209
|
+
one-line `desc:`. The Help ▸ Demos menu, the intro page and the dropdown all use
|
|
210
|
+
them, so a new demo needs adding in one place only.
|
|
211
|
+
- The key log is cleared when the demo changes, as at the start of a round.
|
|
212
|
+
- Test: start the basic demo, choose "Easy jump" in the dropdown; the easy jump
|
|
213
|
+
demo runs, the basic one stopped, and the dropdown shows "Easy jump".
|
|
214
|
+
|
|
215
|
+
## Implementation order
|
|
216
|
+
|
|
217
|
+
1. `⟦run:action|label⟧` links: parsing in `handle_word` and the context menu, the
|
|
218
|
+
allowlist, and the new `⟦help:…⟧` targets. Tests: an allowed action runs, a
|
|
219
|
+
disallowed one doesn't and shows a message.
|
|
220
|
+
2. `intro.txt`, `{key:…}` substitution, the `help.intro` action, the Help menu item,
|
|
221
|
+
`:intro`, and a read-only buffer kept out of the session. Tests: every `{key:…}`
|
|
222
|
+
resolves in vimlike and notepad, and opening the page twice keeps one buffer.
|
|
223
|
+
3. Buttons at child anchors for `⟦run:…⟧` links. Test: clicking the button
|
|
224
|
+
(`signal_emit("clicked")`) starts the demo.
|
|
225
|
+
4. Show on first start (`cnf.intro.show_on_startup`, the conditions above), plus the
|
|
226
|
+
Settings checkbox. Test: shown with a fresh user dir, not with a file argument,
|
|
227
|
+
not the second time.
|
|
228
|
+
5. Return to the intro page after a demo started from it.
|
|
229
|
+
6. `title:` / `desc:` in `DemoPlayer::DEMOS`, and the demo dropdown in the demo
|
|
230
|
+
controls.
|
|
231
|
+
7. `vim_intro.txt` and `⟦help:vim_intro⟧`, with the test that checks its table
|
|
232
|
+
against the live bindings.
|
|
233
|
+
8. Update the README (mention Help ▸ Introduction and `--intro`) and
|
|
234
|
+
`custom_example.rb`.
|
|
235
|
+
|
|
236
|
+
`--intro` comes with step 2, so every later step can be tried with
|
|
237
|
+
`ruby exe/vimamsa --intro`.
|
|
238
|
+
|
|
239
|
+
Run the suite in the test VM after each step (`./run_tests_vm.rb`).
|
|
240
|
+
|
|
241
|
+
## Later
|
|
242
|
+
|
|
243
|
+
- No guided exercises on the intro page: it stays text plus demos. A separate step
|
|
244
|
+
by step tutorial may come later. The intro page would then link to it, and the
|
|
245
|
+
`⟦run:…⟧` links and buttons can be reused there.
|
|
246
|
+
|
|
247
|
+
## DONE
|
|
248
|
+
|
|
249
|
+
- 2026-11-21, `6448bb9`. All the steps:
|
|
250
|
+
- `lib/vimamsa/intro_page.rb`, plus `help/intro.txt` and `help/vim_intro.txt`.
|
|
251
|
+
- `⟦run:…⟧` links with an allowlist (`help.*`, `app.demo`), and inline buttons.
|
|
252
|
+
- `{key:…}`, `{demos}` and `{vim_key_table}` placeholders.
|
|
253
|
+
- Read-only help buffers (`Buffer#read_only`, refused in `add_delta`).
|
|
254
|
+
- Help ▸ Introduction and Help ▸ Vimamsa for Vim users; `:intro`; `--intro`.
|
|
255
|
+
- `cnf.intro.show_on_startup` (Settings ▸ Behavior; set false once shown at
|
|
256
|
+
start).
|
|
257
|
+
- `DEMOS` `title:` / `desc:` / `action:` (used by the menu, the page and the
|
|
258
|
+
dropdown), and `DemoPlayer.duration`.
|
|
259
|
+
- The demo dropdown above the key log (on its own row, so the panel keeps its
|
|
260
|
+
width); switching keeps the speed.
|
|
261
|
+
- Back to the page after a demo started from it.
|
|
262
|
+
- README and `custom_example.rb`.
|
|
263
|
+
- Tests: `tests/test_intro_page.rb` (19). Full suite in the VM: 500 passed.
|
|
264
|
+
- Buttons are only added to help pages. A ⟦run:…⟧ link in an ordinary file
|
|
265
|
+
works with the keyboard and the context menu, but gets no button: that would
|
|
266
|
+
need a placeholder char in the file, as images do.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Plan: better organized "Show key bindings" page
|
|
2
|
+
|
|
3
|
+
TODO: act next on step 4 of "Implementation order" (text-object renderer and
|
|
4
|
+
`<char>`/`<num>` templates). Steps 1-3 are done (see DONE at the end).
|
|
5
|
+
|
|
6
|
+
## Context
|
|
7
|
+
|
|
8
|
+
Help ▸ Show key bindings (`show_key_bindings`, `lib/vimamsa/key_bindings_report.rb:18`)
|
|
9
|
+
dumps lines like
|
|
10
|
+
|
|
11
|
+
[C] d i <char> : buf.text_object_op(:delete, <char>, :i)
|
|
12
|
+
|
|
13
|
+
into the catch-all **Others** section. The page should be organized by what the user
|
|
14
|
+
wants to do, with readable descriptions, and work the same way for every keybinding
|
|
15
|
+
scheme.
|
|
16
|
+
|
|
17
|
+
## Why it's disorganized now (verified 2026-11-19)
|
|
18
|
+
|
|
19
|
+
1. **Sections are hardcoded to the vimlike keywords.** The report asks
|
|
20
|
+
`get_by_keywords` for `intro`, `hyperplaintext`, `core` and `experimental`, and
|
|
21
|
+
everything else goes to Others. The `vim` scheme tags its bindings `vim motion`,
|
|
22
|
+
`vim edit`, `vim visual`, `vim insert`, `vim replace` and `vim misc`, and notepad
|
|
23
|
+
tags them `notepad`. With those schemes, **almost every binding ends up in Others.**
|
|
24
|
+
2. **`core` is one bucket for about 205 bindings** (`key_bindings_vimlike.rb:114-390`):
|
|
25
|
+
motions, file and buffer handling, deleting, marks, macros, mode switches. The
|
|
26
|
+
file already has comment headers for these groups (`# MOVING`, `#### Deleting`,
|
|
27
|
+
`# Marks`, `# Macros`, `# Buffer handling`, …), but the keyword ignores them.
|
|
28
|
+
3. **Bindings registered outside the scheme files have ad-hoc or no keywords, so they
|
|
29
|
+
land in Others.** These are text objects (`text_objects.rb:351`, keyword
|
|
30
|
+
`vim text objects`), the file manager (13 `bindkey`s), grep, bookmarks, the buffer
|
|
31
|
+
manager, diff view, the minor modes (`audio`, `macro`, `bmgr`, `bmark`, `grep`,
|
|
32
|
+
`diffview`, `fexp`) and modules (`ollama`, `tts`, `dictation`, `color_highlight`).
|
|
33
|
+
4. **Template families show up as cryptic raw lines.** For example, text objects are
|
|
34
|
+
`ops × {i,a} × <char>`: 13 lines that all look the same and don't show which
|
|
35
|
+
objects exist (`iw`, `i(`, `it`, …).
|
|
36
|
+
5. **Raw Ruby instead of descriptions.** This is a separate TODO item ("Descriptive
|
|
37
|
+
names for key bindings"), and this plan depends on it.
|
|
38
|
+
6. **Raw conditions such as `I tab(vma.buf.view.autocp_active)`** are shown as Ruby
|
|
39
|
+
code.
|
|
40
|
+
7. **Lines are sorted alphabetically by the whole `[Mode] keys` string**, so related
|
|
41
|
+
bindings are scattered, and the mode letter is the main sort key. Deduplication is
|
|
42
|
+
done by string-matching rendered lines (`done.concat(x.lines)`).
|
|
43
|
+
|
|
44
|
+
## Design
|
|
45
|
+
|
|
46
|
+
### 1. Structured binding list from the tree
|
|
47
|
+
|
|
48
|
+
Add `KeyBindingTree#bindings` → array of records
|
|
49
|
+
`{ mode:, keys:, action:, keywords:, eval_rule:, desc: }`, using the same traversal as
|
|
50
|
+
`get_by_keywords` (`key_binding_tree.rb:374`). Fill in `desc` through the
|
|
51
|
+
`action_description` helper from the descriptions TODO item. The report, the
|
|
52
|
+
free-bindings report and the vim-conflicts report are built from this data instead of
|
|
53
|
+
from parsed strings. `get_by_keywords` stays as a thin wrapper for existing callers and
|
|
54
|
+
tests.
|
|
55
|
+
|
|
56
|
+
### 2. A fixed category list, tagged with `cat:<id>` keywords
|
|
57
|
+
|
|
58
|
+
One ordered list in `key_bindings_report.rb` (or a small `key_categories.rb`):
|
|
59
|
+
|
|
60
|
+
| id | Heading |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `basic` | Basics (quick start) |
|
|
63
|
+
| `motion` | Moving the cursor |
|
|
64
|
+
| `search` | Searching and jumping (`/`, `n`, `*`, `f`/`t`, easy-jump, `gf`) |
|
|
65
|
+
| `insert` | Entering insert mode and typing |
|
|
66
|
+
| `edit` | Delete, change, copy, paste (operators and their motions) |
|
|
67
|
+
| `textobj` | Text objects |
|
|
68
|
+
| `case` | Case and text transforms |
|
|
69
|
+
| `visual` | Visual mode |
|
|
70
|
+
| `undo` | Undo, redo, repeat |
|
|
71
|
+
| `marks` | Marks and bookmarks |
|
|
72
|
+
| `macro` | Macros |
|
|
73
|
+
| `file` | Files (open, save, finder, history, file manager) |
|
|
74
|
+
| `buffer` | Buffers and windows (switch, close, two-column) |
|
|
75
|
+
| `view` | Panels and view (file/func/keylog panels, folding, font) |
|
|
76
|
+
| `grep` | Search across files (grep lines, ack) |
|
|
77
|
+
| `code` | Code (LSP, auto-format, comment, run line) |
|
|
78
|
+
| `hpt` | Hyper plaintext |
|
|
79
|
+
| `module:<name>` | Modules ▸ <name from `_info`> |
|
|
80
|
+
| `mode:<id>` | Minor modes (audio, macro, bmgr, bmark, grep, diffview, fexp) |
|
|
81
|
+
| `debug` | Debug / experimental |
|
|
82
|
+
|
|
83
|
+
- **Tagging.** `add_keys` keywords get a `cat:<id>` word, e.g. `add_keys "core cat:motion", {...}`.
|
|
84
|
+
The existing keywords stay, so nothing that queries them breaks.
|
|
85
|
+
- **Split vimlike's big `core` block** into several `add_keys` calls at its existing
|
|
86
|
+
comment headers. Do the same for the vim scheme's six sections and for notepad.
|
|
87
|
+
- **Automatic categories, so most code doesn't need manual tags:**
|
|
88
|
+
- a binding in a minor mode (first key is a minor-mode id) → `mode:<id>`
|
|
89
|
+
- a binding added from inside a module's `<name>_init` → `module:<name>`. Set a
|
|
90
|
+
"current module" context in `module_set_enabled` / the startup loop, and have
|
|
91
|
+
`bindkey` add the keyword.
|
|
92
|
+
- legacy keyword map: `vim motion` → `motion`, `vim text objects` → `textobj`,
|
|
93
|
+
`hyperplaintext` → `hpt`, `experimental` → `debug`, etc.
|
|
94
|
+
- **Basics stays independent of the scheme.** Instead of the vimlike-only `intro`
|
|
95
|
+
keyword, define `BASIC_ACTIONS` (save, quit, undo/redo, insert, esc, search, open
|
|
96
|
+
file, switch buffer, show key bindings, …) and show whatever keys the active scheme
|
|
97
|
+
binds them to. Those bindings still also appear in their own category.
|
|
98
|
+
|
|
99
|
+
### 3. Page layout
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
❙Key bindings — scheme: vimlike❙
|
|
103
|
+
[C]=Command [I]=Insert [V]=Visual … <key>! = press and release alone
|
|
104
|
+
|
|
105
|
+
◼ Moving the cursor
|
|
106
|
+
Command / Visual
|
|
107
|
+
h j k l Move left / down / up / right
|
|
108
|
+
w b e Next word start / previous word start / word end
|
|
109
|
+
<count> G Go to line <count>
|
|
110
|
+
Insert
|
|
111
|
+
ctrl-a Start of line
|
|
112
|
+
…
|
|
113
|
+
◼ Text objects
|
|
114
|
+
Operators: d (delete) c (change) y (copy) gU gu g~ (case) v (select, Visual)
|
|
115
|
+
Objects: iw aw iW aW is as ip ap i" a" i' a' i` a` i( a( (ib ab) i[ a[
|
|
116
|
+
i{ a{ (iB aB) i< a< it at
|
|
117
|
+
Examples: d i w delete word · c i " change inside quotes · y a p copy paragraph
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
- Within a category, bindings are grouped by **mode** as a subheading, not used as a
|
|
121
|
+
sort key. Inside a group they're kept in **definition order** (the order in the
|
|
122
|
+
scheme file, which is logical: hjkl together), not alphabetical.
|
|
123
|
+
- Keys that share one description are merged on one line (`"VCX up" / "VC k"` →
|
|
124
|
+
`k up`).
|
|
125
|
+
- Columns are aligned: keys | description. The raw action is dimmed after the
|
|
126
|
+
description only when it adds something (see the descriptions TODO), or always for
|
|
127
|
+
Ruby-string actions as `⟨code⟩`.
|
|
128
|
+
- **Template families get a custom renderer.** A category can provide a block that
|
|
129
|
+
draws its section. `textobj` draws the operator × object table above from the
|
|
130
|
+
text-object definitions in `text_objects.rb`, so it can't go out of date. `<char>`
|
|
131
|
+
/ `<num>` bindings show as `d f <char>`, `d <count> e` with a description that
|
|
132
|
+
names the placeholder.
|
|
133
|
+
- **Conditions** (`eval_rule`) are shown as readable text through a small table
|
|
134
|
+
(`"vma.buf.view.autocp_active"` → "when the completion popup is open",
|
|
135
|
+
`"vma.kbd.next_command_count!=nil"` → "with a count"). Unknown rules are shown dimmed
|
|
136
|
+
as they are.
|
|
137
|
+
- Categories with no bindings in the active scheme are left out. The header says
|
|
138
|
+
which scheme is shown.
|
|
139
|
+
|
|
140
|
+
### 4. Keep it organized: a test instead of Others
|
|
141
|
+
|
|
142
|
+
- For each scheme (via `load_scheme_kbd`, `key_bindings_report.rb`), every binding
|
|
143
|
+
resolves to exactly one known category. Any that don't are printed, so a new
|
|
144
|
+
binding without a category fails the suite. Others stays only as a runtime
|
|
145
|
+
fallback, for bindings users add in `custom.rb`, under the heading "Your bindings
|
|
146
|
+
(custom.rb)" if `bindkey` was called during custom.rb loading. Otherwise it's
|
|
147
|
+
"Uncategorized".
|
|
148
|
+
- Snapshot-ish test: the rendered page for vimlike contains the headings in order and
|
|
149
|
+
the text-object table, and contains no `buf.text_object_op(` line.
|
|
150
|
+
|
|
151
|
+
### 5. Optional follow-ups
|
|
152
|
+
|
|
153
|
+
- Hyperplaintext folding per `◼` section, so long categories can be collapsed.
|
|
154
|
+
- `show_key_bindings` takes an optional filter (category or search string). Add menu
|
|
155
|
+
entries "Key bindings: Editing", …, or reuse Search for Actions for that.
|
|
156
|
+
- Show the category in Search for Actions results.
|
|
157
|
+
|
|
158
|
+
## Implementation order
|
|
159
|
+
|
|
160
|
+
1. `KeyBindingTree#bindings` (structured records) + tests. Port `show_key_bindings`
|
|
161
|
+
to it with the current sections. Output stays the same.
|
|
162
|
+
2. Category list, `cat:` tagging, auto-categories (minor mode, module, legacy map).
|
|
163
|
+
Split the big vimlike `core` block and tag the vim/notepad sections. Add the
|
|
164
|
+
"no uncategorized bindings" test.
|
|
165
|
+
3. New layout: grouping by mode, definition order, merged keys, aligned columns,
|
|
166
|
+
condition text, scheme in the header, Basics from `BASIC_ACTIONS`.
|
|
167
|
+
4. Text-object renderer and `<char>`/`<num>` template rendering.
|
|
168
|
+
5. Descriptions (the separate TODO item) fill in the description column. This can run
|
|
169
|
+
in parallel; until then the column shows the raw action.
|
|
170
|
+
|
|
171
|
+
Run the full suite in the VM after each step.
|
|
172
|
+
|
|
173
|
+
## DONE
|
|
174
|
+
|
|
175
|
+
- **Steps 1-2: binding records and categories** (2026-11-21, commit "feat: key
|
|
176
|
+
bindings page grouped by category"). `KeyBindingTree#bindings` returns
|
|
177
|
+
`{ mode:, keys:, action:, keywords:, desc: }` records in definition order,
|
|
178
|
+
including actions on nodes that also have longer bindings; `get_by_keywords`
|
|
179
|
+
is built on it. `desc` now also covers dotted action ids (since the renames
|
|
180
|
+
the page showed raw ids) and shows procs as `proc (file.rb:line)`.
|
|
181
|
+
Categories (`KEY_CATEGORIES` in `key_bindings_report.rb`, the table above
|
|
182
|
+
plus `app`, `help`, `custom` and `internal`): `key_binding_category` takes a
|
|
183
|
+
minor mode, then the namespace of a named action
|
|
184
|
+
(`doc/action_names_plan.md`), then a `cat:<id>` keyword, the
|
|
185
|
+
`module:<name>` / `custom` context, the major mode (`B`, `X`, `R`), and the
|
|
186
|
+
older section words (`vim motion`, `experimental`, ...). The context comes
|
|
187
|
+
from `KeyBindingTree#with_keywords`, wrapped around module inits (startup
|
|
188
|
+
and Settings) and the three places `custom.rb` runs. vimlike's `intro` and
|
|
189
|
+
`core` blocks are split into `cat:` groups (same bindings, same order within
|
|
190
|
+
each group, checked by script); the vim table gets `vim marks` and an
|
|
191
|
+
insert section. The page lists Basics (`intro`, as before), then the
|
|
192
|
+
categories in order; "Others" is gone. `tests/test_key_categories.rb`: every
|
|
193
|
+
binding of vimlike, vim and notepad has a category.
|
|
194
|
+
Left for later: Basics still uses the `intro` keyword (`BASIC_ACTIONS` is
|
|
195
|
+
step 3); the conflict report still uses its own traversal
|
|
196
|
+
(`kbd_leaf_bindings`).
|
|
197
|
+
- **Step 3: page layout** (2026-11-21). `key_bindings_page` builds the text,
|
|
198
|
+
`key_bindings_section` one section: rows in definition order
|
|
199
|
+
(`State#seq`, set by `bindkey`; `KeyBindingTree#bindings` is sorted by it),
|
|
200
|
+
the same keys and description in several modes merged into one row,
|
|
201
|
+
rows grouped by modes under `◼◼ Command, Visual` subheadings (ordered by
|
|
202
|
+
their first mode, then by which was defined first; none in minor-mode
|
|
203
|
+
sections), keys of a group with the same description merged (`y y / Y`),
|
|
204
|
+
keys and descriptions in aligned columns. Conditions are shown as text
|
|
205
|
+
through `KEY_CONDITIONS` (`(with a count)`), others as `(if <rule>)`. The
|
|
206
|
+
header names the scheme. Basics lists `BASIC_ACTIONS` with the keys the
|
|
207
|
+
active keymap binds them to in Command, Visual and Insert mode. Tests in
|
|
208
|
+
`tests/test_key_categories.rb` (`test_section_layout`, `test_page_layout`).
|
|
209
|
+
Not done: dimming the raw action after a description (hyperplaintext has
|
|
210
|
+
no dim style).
|
|
211
|
+
- **Step 5: descriptions** (2026-11-21): done through step 6 of
|
|
212
|
+
`doc/action_names_plan.md`, which made every Ruby-string binding a named
|
|
213
|
+
action with a description.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Plan: line ends in a treap (`LineTree`)
|
|
2
|
+
|
|
3
|
+
## Why
|
|
4
|
+
|
|
5
|
+
`Buffer#@line_ends` is a sorted Array of the positions of every `\n`. Lookups are
|
|
6
|
+
fast (`[i]`, `bsearch_index`), but every edit shifts all later entries in a Ruby
|
|
7
|
+
loop (`update_line_ends`, `buffer.rb`): 0.65 ms per edit at 10k lines and 6.3 ms at
|
|
8
|
+
100k (measured 2026-11-21, see `doc/TODO.md`, "Performance"). A replace pays it
|
|
9
|
+
twice.
|
|
10
|
+
|
|
11
|
+
An implicit treap of lines makes edits and lookups O(log n) expected. Background
|
|
12
|
+
and an interactive walkthrough of the operations: the "Treap of Lines" artifact,
|
|
13
|
+
and the "tree structures" discussion in `doc/TODO.md`.
|
|
14
|
+
|
|
15
|
+
## Design
|
|
16
|
+
|
|
17
|
+
`lib/vimamsa/line_tree.rb`, class `LineTree`.
|
|
18
|
+
|
|
19
|
+
- **One node per line**, in document order. Lines are ordered by position in the
|
|
20
|
+
tree; line numbers aren't stored.
|
|
21
|
+
- `len`: characters in the line, its `\n` included
|
|
22
|
+
- `prio`: random, and a parent's is higher than its children's (heap order)
|
|
23
|
+
- `cnt` and `sum`: lines and characters in the subtree
|
|
24
|
+
- **The last node is the text after the last `\n`** (usually empty, because buffers
|
|
25
|
+
end with `\n`). So every position, including the end of the text, belongs to a
|
|
26
|
+
node, and `size` (the number of newlines) is the node count minus 1.
|
|
27
|
+
- Core operations, as in the artifact: `split` and `merge` by line count, a descent by
|
|
28
|
+
line number or by character position, and an O(k) build from a list of lengths.
|
|
29
|
+
|
|
30
|
+
### Array-compatible interface
|
|
31
|
+
|
|
32
|
+
`@line_ends` stays the name, and the tree answers the Array methods the code
|
|
33
|
+
uses. The about 75 call sites (`buffer.rb`, `buffer_cursor.rb`, `fold.rb`,
|
|
34
|
+
`vim_operators.rb`, `vim_core.rb`, `bookmarks.rb`, `gui_file_panel.rb`) then don't
|
|
35
|
+
change:
|
|
36
|
+
|
|
37
|
+
| Method | Meaning | Cost |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `size` | number of `\n` | O(1) |
|
|
40
|
+
| `[i]` (negative `i` allowed) | position of the i-th `\n` | O(log n) |
|
|
41
|
+
| `bsearch_index { \|x\| … }` / `bsearch { … }` | find-minimum binary search over the `\n` positions, as `Array#bsearch` | O(log n), one descent |
|
|
42
|
+
| `to_a`, `==` | the plain Array, for tests and checks | O(n) |
|
|
43
|
+
|
|
44
|
+
Extra methods for later callers: `line_start(i)`, `line_len(i)`, `line_at(pos)` →
|
|
45
|
+
`[line, column]`, `total`.
|
|
46
|
+
|
|
47
|
+
### Updates
|
|
48
|
+
|
|
49
|
+
`Buffer#update_line_ends(pos, changeamount, changestr)` calls
|
|
50
|
+
`@line_ends.insert(pos, text)` or `@line_ends.delete(pos, removed_text)`. Both
|
|
51
|
+
come from `run_delta`, which already knows the inserted or removed text.
|
|
52
|
+
|
|
53
|
+
- **Insert `text` at `pos`** (on line j, column c), where `text` has k newlines:
|
|
54
|
+
- **k = 0:** line j gets longer. Only the sums on its path change.
|
|
55
|
+
- **k > 0:**
|
|
56
|
+
- line j becomes `c + first piece + 1`
|
|
57
|
+
- the middle pieces become new lines
|
|
58
|
+
- the last piece plus the rest of line j becomes the last new line
|
|
59
|
+
- the k new lines are added with one split, an O(k) build and two merges
|
|
60
|
+
- **Delete `n` chars at `pos`**, where the removed text has m newlines:
|
|
61
|
+
- **m = 0:** line j gets shorter.
|
|
62
|
+
- **m > 0:** lines j … j + m become one line, of length `c + (len(j + m) − end column)`.
|
|
63
|
+
Lines j + 1 … j + m are removed with two splits and a merge.
|
|
64
|
+
- **A full rebuild** (`set_content`, `recalc_line_ends`) builds the tree from
|
|
65
|
+
`each_line` in O(n). There's no regex scan any more.
|
|
66
|
+
|
|
67
|
+
## Tests
|
|
68
|
+
|
|
69
|
+
- **Random edits compared with a reference:** apply random inserts and deletes
|
|
70
|
+
(with and without newlines, at the start, middle and end, including non-ASCII
|
|
71
|
+
text) to a String and to a `LineTree`, and compare `to_a` with the newline
|
|
72
|
+
positions of the String after every step.
|
|
73
|
+
- **Invariants after each step:** heap order, and `cnt` / `sum` consistent.
|
|
74
|
+
- **Array interface:** `[]` with negative indexes, `bsearch_index` and `bsearch`
|
|
75
|
+
equal the Array versions for every position.
|
|
76
|
+
- **Buffer:** editing a buffer keeps `line_ends.to_a` equal to a fresh scan. The
|
|
77
|
+
existing suite covers the callers.
|
|
78
|
+
- **Performance:** 1000 single-character inserts in the middle of a 100k-line
|
|
79
|
+
buffer must be well below the old cost (about 6 ms each).
|
|
80
|
+
|
|
81
|
+
## Order
|
|
82
|
+
|
|
83
|
+
1. `LineTree` with unit tests (no Buffer changes).
|
|
84
|
+
2. Buffer uses it: `set_content`, `update_line_ends`, `recalc_line_ends`,
|
|
85
|
+
`sanity_check_line_ends`. `require` in `rbvma.rb`. Full suite in the VM.
|
|
86
|
+
3. Measure the edit cost at 100k lines, and record it in `doc/TODO.md`.
|
|
87
|
+
4. Later: call sites that loop over all lines (`fold.rb`'s fold search) can walk
|
|
88
|
+
the tree in order instead of calling `[i]` per line. Per-line data (the
|
|
89
|
+
highlighter state, tokens) can move into the nodes when own highlighting comes.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Vim keybindings missing from Vimamsa
|
|
2
|
+
|
|
3
|
+
Comparison of Vimamsa's two Vim-style keymaps against standard Vim:
|
|
4
|
+
|
|
5
|
+
- `vimlike` (default) — `lib/vimamsa/key_bindings_vimlike.rb`
|
|
6
|
+
- `vim` (`cnf.keybindings.scheme = "vim"`) — `lib/vimamsa/key_bindings_vim.rb`
|
|
7
|
+
|
|
8
|
+
The scheme is selected in `lib/vimamsa/editor.rb` (`Editor#start`).
|
|
9
|
+
|
|
10
|
+
This list comes from reading the binding files, not from testing in the editor.
|
|
11
|
+
The generated [vimlike_vim_conflicts.md](vimlike_vim_conflicts.md) compares the two
|
|
12
|
+
keymaps binding by binding.
|
|
13
|
+
|
|
14
|
+
## Operators and motions
|
|
15
|
+
|
|
16
|
+
Done (2026-11-21): the operator + motion layer (`lib/vimamsa/vim_operators.rb`,
|
|
17
|
+
step 1 of `doc/vim_compatibility_plan.md`). Every operator works with every motion and
|
|
18
|
+
text object, with counts before the operator and before the motion (`2d3w`):
|
|
19
|
+
|
|
20
|
+
- Operators: `d c y gU gu g~ > <`. Doubled, they act on lines: `dd cc yy gUU >>`.
|
|
21
|
+
- Motions: `h l j k w b e W B E 0 ^ $ gg G f t F T` (with a character or `space`),
|
|
22
|
+
`'x` and `` `x `` (marks). `cw` works like `ce`, and `dw` on the last word of a line
|
|
23
|
+
doesn't join lines, as in vim.
|
|
24
|
+
- Text objects: `iw aw iW aW is as ip ap`, the quotes, the brackets and `it at`.
|
|
25
|
+
|
|
26
|
+
The `vim` keymap has all of them. `vimlike` has every combination it doesn't use for
|
|
27
|
+
something else (see [vimlike_vim_conflicts.md](vimlike_vim_conflicts.md)). Its own
|
|
28
|
+
`d w`, `d e`, `d $`, `y e`, `g U w`, ... stay, so for those keys vimlike behaves as
|
|
29
|
+
before. `vimlike` also gets `W B E t T` as plain motions, and its own `O` (end of line)
|
|
30
|
+
works after every operator (`c O`, `g U O`).
|
|
31
|
+
|
|
32
|
+
Still missing:
|
|
33
|
+
- Operators `=` (reindent) and `gq` (format).
|
|
34
|
+
- Motions `ge`, `{` / `}` (paragraph), `(` / `)` (sentence), `%` (matching bracket),
|
|
35
|
+
`H` / `M` / `L` (top, middle and bottom of the screen), `,` (repeat `f` backwards),
|
|
36
|
+
`;` after `t` / `T`.
|
|
37
|
+
- `#` (search backward for the word under the cursor).
|
|
38
|
+
- Repeating `i(` in Visual mode to grow the selection.
|
|
39
|
+
|
|
40
|
+
## Scrolling and jumps
|
|
41
|
+
|
|
42
|
+
- `ctrl-e` / `ctrl-y` (scroll by one line), and `zt` / `zb`.
|
|
43
|
+
- `ctrl-i` (jump forward). `ctrl-o` is only an approximation that goes to the last
|
|
44
|
+
edit.
|
|
45
|
+
- `ctrl-d` / `ctrl-u` scroll a full page instead of half a page.
|
|
46
|
+
- `gv` (reselect the last visual area) and `gi` (insert where you last inserted).
|
|
47
|
+
|
|
48
|
+
## Visual mode and other editing
|
|
49
|
+
|
|
50
|
+
- Line-wise visual (`V`), block visual (`ctrl-v`) and `o` (swap selection ends) are
|
|
51
|
+
missing. `vimlike` binds `V` and `ctrl-v` to other actions.
|
|
52
|
+
- `ctrl-x` (decrement a number) is missing; `ctrl-a` is in both keymaps.
|
|
53
|
+
- `gJ` (join lines without adding a space) is missing.
|
|
54
|
+
- `.` is done (2026-11-21, `lib/vimamsa/dot_repeat.rb`): it repeats the last change,
|
|
55
|
+
including the text typed after `c`, `i`, `o`, ..., with a new count if one is given,
|
|
56
|
+
as one undo step. Not for changes made in Visual mode.
|
|
57
|
+
- `esc` in Insert mode doesn't move the cursor one character left, as vim's does.
|
|
58
|
+
- Registers are done (2026-11-21, `lib/vimamsa/registers.rb`): `""`, `"0`, `"1`–`"9`,
|
|
59
|
+
`"-`, `"a`–`"z` (`"A` appends), `"+` / `"*` and `"_`, selected with `"x` before any
|
|
60
|
+
copy, delete or put. They remember whether the text was whole lines. Insert-mode
|
|
61
|
+
`ctrl-r x` is in the `vim` keymap only. `:reg` lists them.
|