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.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +93 -0
  3. data/.gitignore +4 -1
  4. data/Dockerfile +7 -4
  5. data/README.md +195 -99
  6. data/custom_example.rb +59 -17
  7. data/doc/TODO.md +678 -0
  8. data/doc/action_names_plan.md +442 -0
  9. data/doc/bundling_plan.md +570 -0
  10. data/doc/delta_syntax_plan.md +293 -0
  11. data/doc/demo_recording_plan.md +288 -0
  12. data/doc/design_goals.md +27 -0
  13. data/doc/intro_page_plan.md +266 -0
  14. data/doc/key_bindings_report_plan.md +213 -0
  15. data/doc/line_tree_plan.md +89 -0
  16. data/doc/missing_vim_bindings.md +61 -0
  17. data/doc/modules_settings_plan.md +433 -0
  18. data/doc/refactor_dedup_plan.md +117 -0
  19. data/doc/registries_plan.md +202 -0
  20. data/doc/startup_speed_plan.md +97 -0
  21. data/doc/treap_visualizer.html +585 -0
  22. data/doc/unused_code_plan.md +120 -0
  23. data/doc/vim_compatibility_plan.md +451 -0
  24. data/doc/vimlike_vim_conflicts.md +262 -0
  25. data/doc/vm_snapshots_plan.md +146 -0
  26. data/doc/wysiwyg_plan.md +231 -0
  27. data/exe/run_tests.rb +124 -3
  28. data/exe/vimamsa +68 -5
  29. data/fonts/OFL-Oxanium.txt +93 -0
  30. data/fonts/Oxanium[wght].ttf +0 -0
  31. data/help/intro.txt +30 -0
  32. data/help/vim_intro.txt +31 -0
  33. data/icon.png +0 -0
  34. data/img/demo.gif +0 -0
  35. data/img/demo.mp4 +0 -0
  36. data/lang/hyperplaintext.lang +7 -1
  37. data/lib/vimamsa/ack.rb +13 -1
  38. data/lib/vimamsa/actions.rb +385 -37
  39. data/lib/vimamsa/appimage_env.rb +35 -0
  40. data/lib/vimamsa/audio.rb +2 -5
  41. data/lib/vimamsa/bookmarks.rb +302 -0
  42. data/lib/vimamsa/buffer.rb +675 -118
  43. data/lib/vimamsa/buffer_changetext.rb +150 -68
  44. data/lib/vimamsa/buffer_cursor.rb +7 -0
  45. data/lib/vimamsa/buffer_list.rb +6 -2
  46. data/lib/vimamsa/buffer_manager.rb +10 -7
  47. data/lib/vimamsa/bundled_fonts.rb +32 -0
  48. data/lib/vimamsa/cli_help.rb +75 -0
  49. data/lib/vimamsa/clipboard.rb +9 -3
  50. data/lib/vimamsa/conf.rb +68 -3
  51. data/lib/vimamsa/constants.rb +3 -0
  52. data/lib/vimamsa/crash_handler.rb +149 -0
  53. data/lib/vimamsa/debug.rb +6 -3
  54. data/lib/vimamsa/demo_player.rb +458 -0
  55. data/lib/vimamsa/demo_recorder.rb +277 -0
  56. data/lib/vimamsa/desktop_install.rb +96 -0
  57. data/lib/vimamsa/diff_buffer.rb +40 -11
  58. data/lib/vimamsa/dot_repeat.rb +104 -0
  59. data/lib/vimamsa/easy_jump.rb +57 -3
  60. data/lib/vimamsa/editor.rb +327 -78
  61. data/lib/vimamsa/encrypt.rb +78 -29
  62. data/lib/vimamsa/file_finder.rb +4 -19
  63. data/lib/vimamsa/file_history.rb +4 -1
  64. data/lib/vimamsa/file_manager.rb +46 -31
  65. data/lib/vimamsa/fold.rb +226 -0
  66. data/lib/vimamsa/form_input.rb +388 -0
  67. data/lib/vimamsa/gui.rb +603 -119
  68. data/lib/vimamsa/gui_command_line.rb +247 -0
  69. data/lib/vimamsa/gui_dialog.rb +94 -42
  70. data/lib/vimamsa/gui_file_panel.rb +356 -25
  71. data/lib/vimamsa/gui_form_generator.rb +75 -40
  72. data/lib/vimamsa/gui_func_panel.rb +67 -22
  73. data/lib/vimamsa/gui_image.rb +3 -0
  74. data/lib/vimamsa/gui_key_hint.rb +165 -0
  75. data/lib/vimamsa/gui_keylog_panel.rb +408 -0
  76. data/lib/vimamsa/gui_menu.rb +84 -53
  77. data/lib/vimamsa/gui_select_window.rb +80 -75
  78. data/lib/vimamsa/gui_settings.rb +86 -41
  79. data/lib/vimamsa/gui_sourceview.rb +280 -92
  80. data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
  81. data/lib/vimamsa/gui_text.rb +63 -2
  82. data/lib/vimamsa/gui_theme.rb +615 -0
  83. data/lib/vimamsa/hook.rb +5 -0
  84. data/lib/vimamsa/hyper_plain_text.rb +3 -0
  85. data/lib/vimamsa/intro_page.rb +368 -0
  86. data/lib/vimamsa/key_actions.rb +382 -193
  87. data/lib/vimamsa/key_binding_tree.rb +467 -273
  88. data/lib/vimamsa/key_bindings_notepad.rb +45 -0
  89. data/lib/vimamsa/key_bindings_report.rb +484 -0
  90. data/lib/vimamsa/key_bindings_vim.rb +104 -0
  91. data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
  92. data/lib/vimamsa/key_names.rb +80 -0
  93. data/lib/vimamsa/langservp.rb +271 -54
  94. data/lib/vimamsa/line_tree.rb +367 -0
  95. data/lib/vimamsa/macro.rb +23 -3
  96. data/lib/vimamsa/main.rb +14 -8
  97. data/lib/vimamsa/rbvma.rb +41 -1
  98. data/lib/vimamsa/registers.rb +125 -0
  99. data/lib/vimamsa/run_ruby.rb +64 -0
  100. data/lib/vimamsa/search.rb +3 -0
  101. data/lib/vimamsa/search_replace.rb +15 -14
  102. data/lib/vimamsa/string_util.rb +134 -40
  103. data/lib/vimamsa/terminal.rb +3 -0
  104. data/lib/vimamsa/test_framework.rb +28 -2
  105. data/lib/vimamsa/tests.rb +11 -8
  106. data/lib/vimamsa/text_objects.rb +310 -0
  107. data/lib/vimamsa/text_transforms.rb +18 -0
  108. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  109. data/lib/vimamsa/user_dirs.rb +83 -0
  110. data/lib/vimamsa/util.rb +46 -7
  111. data/lib/vimamsa/version.rb +1 -1
  112. data/lib/vimamsa/vim_core.rb +355 -0
  113. data/lib/vimamsa/vim_operators.rb +365 -0
  114. data/lib/vimamsa.rb +0 -1
  115. data/modules/calculator/calculator.rb +5 -5
  116. data/modules/color_highlight/color_highlight.rb +118 -0
  117. data/modules/color_highlight/color_highlight_info.rb +3 -0
  118. data/modules/dictation/dictation.rb +1054 -0
  119. data/modules/dictation/dictation_info.rb +3 -0
  120. data/modules/dictation/whisper_worker.py +273 -0
  121. data/modules/ollama/ollama.rb +107 -0
  122. data/modules/ollama/ollama_info.rb +3 -0
  123. data/modules/terminal/terminal.rb +5 -5
  124. data/modules/tts/tts.rb +119 -0
  125. data/modules/tts/tts_info.rb +3 -0
  126. data/run_e2e_vm.sh +28 -0
  127. data/run_tests_vm.rb +138 -0
  128. data/scripts/appimage/AppRun +54 -0
  129. data/scripts/appimage/Dockerfile +18 -0
  130. data/scripts/appimage/build.sh +19 -0
  131. data/scripts/appimage/build_in_container.sh +192 -0
  132. data/scripts/appimage/smoke_test.sh +27 -0
  133. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  134. data/scripts/demo/demo_files_steps.txt +52 -0
  135. data/scripts/demo/demo_steps.txt +67 -0
  136. data/scripts/demo/notes.txt +6 -0
  137. data/scripts/demo/record_demo.rb +156 -0
  138. data/scripts/demo/report.rb +7 -0
  139. data/scripts/demo/shapes.rb +29 -0
  140. data/scripts/demo/square/shapes.rb +29 -0
  141. data/scripts/demo/square/steps.txt +185 -0
  142. data/scripts/lib/perf_startup.rb +138 -0
  143. data/scripts/lib/script_helpers.rb +53 -0
  144. data/scripts/perf_compare.rb +34 -0
  145. data/scripts/profile_startup.rb +72 -0
  146. data/styles/134272-molokai.xml +3 -0
  147. data/styles/molokai_cyber.xml +48 -0
  148. data/styles/molokai_edit.xml +1 -0
  149. data/tests/support/virtual_keyboard.rb +254 -0
  150. data/tests/support/virtual_mic.rb +67 -0
  151. data/tests/test_ack.rb +22 -0
  152. data/tests/test_action_ids.rb +232 -0
  153. data/tests/test_auto_format.rb +122 -0
  154. data/tests/test_autocomplete.rb +211 -0
  155. data/tests/test_autosave.rb +145 -0
  156. data/tests/test_basic_editing.rb +46 -16
  157. data/tests/test_bookmarks.rb +206 -0
  158. data/tests/test_bracket_match.rb +88 -0
  159. data/tests/test_bundling.rb +92 -0
  160. data/tests/test_cli_help.rb +64 -0
  161. data/tests/test_color_highlight.rb +92 -0
  162. data/tests/test_command_line.rb +79 -0
  163. data/tests/test_command_line_file.rb +27 -0
  164. data/tests/test_context_menu_file.rb +147 -0
  165. data/tests/test_copy_paste.rb +106 -26
  166. data/tests/test_crash_handler.rb +39 -0
  167. data/tests/test_custom_two_phase.rb +92 -0
  168. data/tests/test_demo_player.rb +301 -0
  169. data/tests/test_demo_recorder.rb +202 -0
  170. data/tests/test_dialog_callback_errors.rb +44 -0
  171. data/tests/test_dictation.rb +294 -0
  172. data/tests/test_diff_buffer_name.rb +51 -0
  173. data/tests/test_dot_repeat.rb +88 -0
  174. data/tests/test_double_click.rb +41 -0
  175. data/tests/test_drag_selection.rb +125 -0
  176. data/tests/test_e2e_cmdline.rb +116 -0
  177. data/tests/test_e2e_dictation.rb +98 -0
  178. data/tests/test_e2e_replace_char.rb +58 -0
  179. data/tests/test_easy_jump.rb +93 -0
  180. data/tests/test_extract_file_links.rb +55 -0
  181. data/tests/test_file_format.rb +217 -0
  182. data/tests/test_file_manager.rb +72 -0
  183. data/tests/test_file_panel.rb +269 -0
  184. data/tests/test_flash.rb +78 -0
  185. data/tests/test_fold.rb +111 -0
  186. data/tests/test_font_refresh.rb +56 -0
  187. data/tests/test_form_input.rb +203 -0
  188. data/tests/test_func_panel.rb +68 -0
  189. data/tests/test_grep_apply.rb +46 -0
  190. data/tests/test_gtk_sync.rb +126 -0
  191. data/tests/test_hpt_highlight_visible.rb +75 -0
  192. data/tests/test_hpt_link_highlight.rb +82 -0
  193. data/tests/test_intro_page.rb +437 -0
  194. data/tests/test_jump_to_file.rb +41 -0
  195. data/tests/test_key_bindings.rb +208 -0
  196. data/tests/test_key_categories.rb +163 -0
  197. data/tests/test_keylog_panel.rb +261 -0
  198. data/tests/test_line_ends.rb +51 -0
  199. data/tests/test_line_tree.rb +86 -0
  200. data/tests/test_lsp_clangd.rb +281 -0
  201. data/tests/test_lsp_jump.rb +87 -0
  202. data/tests/test_lsp_position_encoding.rb +49 -0
  203. data/tests/test_lsp_symbols.rb +68 -0
  204. data/tests/test_macro.rb +137 -0
  205. data/tests/test_markdown_highlight.rb +57 -0
  206. data/tests/test_mode_badge.rb +41 -0
  207. data/tests/test_module_interface.rb +9 -9
  208. data/tests/test_notepad_bindings.rb +67 -0
  209. data/tests/test_perf_startup.rb +28 -0
  210. data/tests/test_popup_queue.rb +51 -0
  211. data/tests/test_random_edit.rb +109 -0
  212. data/tests/test_registers.rb +122 -0
  213. data/tests/test_revert.rb +127 -0
  214. data/tests/test_run_ruby.rb +77 -0
  215. data/tests/test_startup_file.rb +58 -0
  216. data/tests/test_status_area.rb +50 -0
  217. data/tests/test_text_objects.rb +163 -0
  218. data/tests/test_text_transforms.rb +341 -0
  219. data/tests/test_tmp_user_dir.rb +79 -0
  220. data/tests/test_tts.rb +68 -0
  221. data/tests/test_undo.rb +34 -34
  222. data/tests/test_user_dirs.rb +122 -0
  223. data/tests/test_vim_bindings.rb +353 -0
  224. data/tests/test_vim_conflicts.rb +100 -0
  225. data/tests/test_vim_operators.rb +116 -0
  226. data/tests/test_window_layout.rb +302 -0
  227. data/vimamsa.gemspec +3 -1
  228. data/vm_guest_run.sh +129 -0
  229. metadata +167 -10
@@ -0,0 +1,437 @@
1
+ # The introduction page and the Vim summary (intro_page.rb, help/*.txt):
2
+ # ⟦run:…⟧ links and their buttons, {key:…} placeholders, read-only help
3
+ # buffers, the demo list above the key log, and when the page is shown at
4
+ # start (doc/intro_page_plan.md)
5
+ require "rbconfig"
6
+ require "tmpdir"
7
+
8
+ class TestIntroPage < VmaTest
9
+ REPO = File.expand_path("..", __dir__)
10
+
11
+ def setup_counter
12
+ $intro_test_runs = 0
13
+ reg_act("help.zz_intro_test", proc { $intro_test_runs += 1 }, "test")
14
+ reg_act("edit.zz_intro_test", proc { $intro_test_runs += 1 }, "test")
15
+ end
16
+
17
+ def close_help_pages
18
+ vma.buffers.list.select { |b| b.help_page }.each { |b| vma.buffers.close_buffer(b.id) }
19
+ end
20
+
21
+ def stop_demo
22
+ p = DemoPlayer.current
23
+ return if p.nil?
24
+ p.stop
25
+ (p.bufs || []).each { |b| vma.buffers.close_buffer(b.id) if vma.buffers.list.any? { |x| x.equal?(b) } }
26
+ drain_idle
27
+ end
28
+
29
+ # ── Links ────────────────────────────────────────────────────────────────
30
+
31
+ def test_link_at
32
+ s = "abc ⟦run:help.x|Two words⟧ d ⟦help:intro⟧\n"
33
+ assert_eq "⟦run:help.x|Two words⟧", hpt_link_at(s, s.index("words"))
34
+ assert_eq "⟦help:intro⟧", hpt_link_at(s, s.index("intro"))
35
+ assert_eq nil, hpt_link_at(s, 1)
36
+ end
37
+
38
+ def test_enter_runs_allowed_action
39
+ setup_counter
40
+ create_new_buffer("x ⟦run:help.zz_intro_test|Run it now⟧\n", "linktest")
41
+ buf.set_pos(buf.index("it now"))
42
+ buf.handle_line_action
43
+ assert_eq 1, $intro_test_runs
44
+ ensure
45
+ vma.actions.unregister("help.zz_intro_test") rescue nil
46
+ vma.actions.unregister("edit.zz_intro_test") rescue nil
47
+ end
48
+
49
+ # Any .txt file can hold a ⟦run:…⟧ link: only allowed actions run
50
+ def test_disallowed_action_not_run
51
+ setup_counter
52
+ create_new_buffer("⟦run:edit.zz_intro_test|Do it⟧\n", "linktest")
53
+ buf.set_pos(3)
54
+ buf.handle_line_action
55
+ assert_eq 0, $intro_test_runs
56
+ assert !hpt_run_allowed?("app.quit")
57
+ assert hpt_run_allowed?("help.demo")
58
+ assert hpt_run_allowed?("app.demo")
59
+ ensure
60
+ vma.actions.unregister("help.zz_intro_test") rescue nil
61
+ vma.actions.unregister("edit.zz_intro_test") rescue nil
62
+ end
63
+
64
+ def test_help_link_opens_vim_intro
65
+ create_new_buffer("see ⟦help:vim_intro⟧\n", "linktest")
66
+ buf.set_pos(6)
67
+ buf.handle_line_action
68
+ assert_eq "vim_intro", vma.buf.help_page
69
+ ensure
70
+ close_help_pages
71
+ end
72
+
73
+ # ── The page ─────────────────────────────────────────────────────────────
74
+
75
+ def test_intro_page_filled_in
76
+ b = show_help_page("intro")
77
+ assert_eq "intro", b.help_page
78
+ assert b.read_only
79
+ assert !b.include?("{"), "placeholder left: #{b.lines.grep(/\{/).first}"
80
+ assert !b.include?("(no key for"), "unbound key: #{b.lines.grep(/no key for/).first}"
81
+ DemoPlayer::DEMOS.each_value { |d| assert b.include?("⟦run:#{d[:action]}|▶ #{d[:title]}⟧"), d[:title] }
82
+ assert b.include?("⦁ctrl!⦁ or ⦁i⦁"), "mode.insert keys: #{b.lines.grep(/Insert mode/).first}"
83
+ ensure
84
+ close_help_pages
85
+ end
86
+
87
+ # The links to the other help pages are buttons too, and open them
88
+ def test_help_page_links_are_buttons
89
+ b = show_help_page("intro")
90
+ drain_idle
91
+ %w[help.vim_intro help.keys].each { |act|
92
+ assert b.help_buttons.any? { |a, _, _| a == act }, "no button for #{act}"
93
+ }
94
+ btn = b.help_buttons.find { |a, _, _| a == "help.vim_intro" }[1]
95
+ btn.signal_emit("clicked")
96
+ assert_eq "vim_intro", vma.buf.help_page
97
+ ensure
98
+ close_help_pages
99
+ end
100
+
101
+ # On a read-only page the ⦁ marks are hidden, the text between them is
102
+ # not, and the cursor steps over a hidden mark
103
+ def test_marks_hidden_on_help_page
104
+ b = show_help_page("intro")
105
+ drain_idle
106
+ # the first marked key on the page (e.g. ⦁ctrl!⦁ from {key:...})
107
+ m = b.match(/⦁[^⦁\n]+⦁/)
108
+ assert m, "no ⦁ marks on the page"
109
+ i = m.begin(0)
110
+ assert hidden?(b, i), "opening mark shown"
111
+ assert hidden?(b, m.end(0) - 1), "closing mark shown"
112
+ assert !hidden?(b, i + 1), "key text hidden"
113
+ b.set_pos(i - 1)
114
+ hpt_skip_hidden_marks(b)
115
+ keys "l"
116
+ assert_eq i + 1, b.pos, "cursor on the hidden opening mark"
117
+ keys "h"
118
+ assert_eq i - 1, b.pos, "cursor back on the hidden opening mark"
119
+ # an editable buffer shows them
120
+ e = create_new_buffer("a ⦁key⦁ b\n", "marktest")
121
+ gui_set_file_lang(e.id, "hyperplaintext")
122
+ hpt_hide_marks(e)
123
+ assert !hidden?(e, 2), "mark hidden in an editable buffer"
124
+ ensure
125
+ close_help_pages
126
+ end
127
+
128
+ # The keys come from the bindings, so the page works in notepad too
129
+ # (which never leaves Insert mode, so it has no I:mode.prev)
130
+ def test_keys_resolve_in_notepad
131
+ kbd = load_scheme_kbd(["vimlike", "notepad"])
132
+ specs = HELP_PAGES.flat_map { |n| File.read(File.join(HELP_DIR, "#{n}.txt")).scan(/\{key:([^}]+)\}/).flatten }
133
+ assert specs.size >= 8
134
+ (specs - ["I:mode.prev"]).each { |s|
135
+ t = help_key_text(s, kbd)
136
+ assert !t.include?("no key for"), "#{s}: #{t}"
137
+ }
138
+ end
139
+
140
+ def test_opening_twice_keeps_one_buffer
141
+ a = show_help_page("intro")
142
+ create_new_buffer("other\n", "other")
143
+ b = show_help_page("intro")
144
+ assert a.equal?(b)
145
+ assert vma.buf.equal?(a)
146
+ assert_eq 1, vma.buffers.list.count { |x| x.help_page == "intro" }
147
+ ensure
148
+ close_help_pages
149
+ end
150
+
151
+ def test_read_only
152
+ b = show_help_page("intro")
153
+ text = b.to_s.dup
154
+ keys "x d d"
155
+ keys "i a b c esc"
156
+ assert_eq text, b.to_s
157
+ ensure
158
+ vma.kbd.set_mode(:command)
159
+ close_help_pages
160
+ end
161
+
162
+ def test_command_line_and_menu
163
+ vma.gui.cmd_line.execute("intro")
164
+ assert_eq "intro", vma.buf.help_page
165
+ assert_eq "Help ▸ Introduction", vma.gui.menu.path_for("help.intro")
166
+ assert_eq "Help ▸ Demos ▸ Easy jump", vma.gui.menu.path_for("help.demo.easyjump")
167
+ ensure
168
+ close_help_pages
169
+ end
170
+
171
+ # ── Buttons and demos ────────────────────────────────────────────────────
172
+
173
+ # One button per ⟦run:…⟧ line; the GTK buffer keeps the Buffer's length
174
+ def test_buttons_added
175
+ b = show_help_page("intro")
176
+ drain_idle
177
+ n = b.lines.count { |l| l.include?("⟦run:") }
178
+ assert_eq n, b.help_buttons.size
179
+ assert_eq DemoPlayer::DEMOS.size + 4, n
180
+ assert_eq b.size, b.view.buffer.char_count
181
+ ensure
182
+ close_help_pages
183
+ end
184
+
185
+ def hidden?(b, pos)
186
+ tag = b.view.buffer.tag_table.lookup("hpt_hidden")
187
+ !tag.nil? && b.view.buffer.get_iter_at(offset: pos).has_tag?(tag)
188
+ end
189
+
190
+ # On a read-only page the buttons replace the link text everywhere; the
191
+ # cursor moves off the hidden text onto the button, where enter runs it
192
+ def test_buttons_replace_links_on_help_page
193
+ setup_counter
194
+ b = show_help_page("intro")
195
+ drain_idle
196
+ from = b.index("⟦run:help.demo|")
197
+ assert_eq HPT_BUTTON_SLOT, b[from - 1]
198
+ assert !hidden?(b, from - 1), "the button's place hidden"
199
+ assert hidden?(b, from), "link text shown"
200
+ assert hidden?(b, from + 5)
201
+ btn = b.help_buttons[0][1]
202
+ assert btn.visible?, "button hidden"
203
+ assert_eq "pointer", btn.cursor&.name, "mouse pointer over the button"
204
+ # the cursor on the link's line: still hidden (read-only)
205
+ b.set_pos(from + 3)
206
+ hpt_update_run_buttons(b)
207
+ assert hidden?(b, from), "link shown with the cursor on its line"
208
+ assert_eq from - 1, b.pos, "cursor not moved onto the button"
209
+ ensure
210
+ vma.actions.unregister("help.zz_intro_test") rescue nil
211
+ vma.actions.unregister("edit.zz_intro_test") rescue nil
212
+ close_help_pages
213
+ end
214
+
215
+ # The cursor treats a button as one char: w and l from the button go past
216
+ # its (hidden) link, b and h come back onto it, w from before it stops on
217
+ # it; and many w's in a row move on without getting stuck
218
+ def test_cursor_treats_button_as_one_char
219
+ b = show_help_page("intro")
220
+ drain_idle
221
+ at = b.index("#{HPT_BUTTON_SLOT}⟦run:help.demo|")
222
+ to = b.index("⟧", at) + 1
223
+ b.set_pos(at)
224
+ hpt_skip_button(b)
225
+ keys "l"
226
+ assert_eq to, b.pos, "l from the button"
227
+ keys "h"
228
+ assert_eq at, b.pos, "h back onto the button"
229
+ keys "w"
230
+ assert_eq b.index(/\S/, to), b.pos, "w from the button: the next word after the link"
231
+ keys "b"
232
+ assert_eq at, b.pos, "b back onto the button"
233
+ # w from the end of the line above stops on the button
234
+ b.set_pos(at - 2)
235
+ hpt_skip_button(b)
236
+ keys "w"
237
+ assert_eq at, b.pos, "w onto the button"
238
+ last = b.pos
239
+ 40.times {
240
+ keys "w"
241
+ assert b.pos > last || b.pos >= b.size - 2, "w stuck at #{b.pos}: #{b[b.pos, 20].inspect}"
242
+ last = b.pos
243
+ break if b.pos >= b.size - 2
244
+ }
245
+ ensure
246
+ close_help_pages
247
+ end
248
+
249
+ # In a buffer that can be edited, the link text shows instead of the
250
+ # button while the cursor is on its line
251
+ def test_link_code_shown_on_cursor_line_when_editable
252
+ setup_counter
253
+ b = create_new_buffer("first line\nx#{HPT_BUTTON_SLOT}⟦run:help.zz_intro_test|Go⟧ y\nlast\n", "linktest")
254
+ help_add_run_buttons(b)
255
+ btn = b.help_buttons[0][1]
256
+ from = b.index("⟦")
257
+ b.set_pos(0)
258
+ hpt_update_run_buttons(b)
259
+ assert hidden?(b, from)
260
+ assert btn.visible?
261
+ keys "j"
262
+ assert !hidden?(b, from), "link code hidden with the cursor on its line"
263
+ assert !btn.visible?, "button shown with the cursor on its line"
264
+ keys "j"
265
+ assert hidden?(b, from)
266
+ assert btn.visible?
267
+ assert_eq b.size, b.view.buffer.char_count
268
+ btn.signal_emit("clicked")
269
+ assert_eq 1, $intro_test_runs
270
+ ensure
271
+ vma.actions.unregister("help.zz_intro_test") rescue nil
272
+ vma.actions.unregister("edit.zz_intro_test") rescue nil
273
+ end
274
+
275
+ # Enter on the button position (before the hidden link) runs the link
276
+ def test_enter_on_button_position
277
+ setup_counter
278
+ b = create_new_buffer("x ⟦run:help.zz_intro_test|Go⟧\n", "linktest")
279
+ b.set_pos(1)
280
+ b.handle_line_action
281
+ assert_eq 1, $intro_test_runs
282
+ ensure
283
+ vma.actions.unregister("help.zz_intro_test") rescue nil
284
+ vma.actions.unregister("edit.zz_intro_test") rescue nil
285
+ end
286
+
287
+ # A demo started from the page goes back to the page when it stops
288
+ def test_button_starts_demo_and_returns
289
+ intro = show_help_page("intro")
290
+ drain_idle
291
+ _, btn = intro.help_buttons.find { |a, _| a == "help.demo.easyjump" }
292
+ btn.signal_emit("clicked")
293
+ drain_idle
294
+ p = DemoPlayer.current
295
+ assert p.running?, "demo not started"
296
+ assert_eq :easyjump, p.name
297
+ assert !vma.buf.equal?(intro)
298
+ p.stop("Demo stopped")
299
+ drain_idle
300
+ assert vma.buf.equal?(intro), "not back on the intro page"
301
+ ensure
302
+ stop_demo
303
+ close_help_pages
304
+ end
305
+
306
+ # The demo list above the key log switches demos, keeping the speed
307
+ def test_demo_list_switches
308
+ DemoPlayer.toggle(:basic)
309
+ a = DemoPlayer.current
310
+ a.faster
311
+ rate = a.rate
312
+ list = vma.gui.keylog_panel.demo_list
313
+ assert_eq 0, list.selected
314
+ list.selected = DemoPlayer::DEMOS.keys.index(:easyjump)
315
+ # the switch runs in an idle callback
316
+ t = Time.now
317
+ until !DemoPlayer.current.equal?(a) || Time.now - t > 5
318
+ drain_idle
319
+ sleep 0.01
320
+ end
321
+ b = DemoPlayer.current
322
+ assert !a.running?, "the basic demo still runs"
323
+ assert b.running?
324
+ assert_eq :easyjump, b.name
325
+ assert_eq rate, b.rate
326
+ assert_eq DemoPlayer::DEMOS.keys.index(:easyjump), list.selected
327
+ ensure
328
+ [a, b].compact.each { |x| x.stop; (x.bufs || []).each { |y| vma.buffers.close_buffer(y.id) if vma.buffers.list.any? { |z| z.equal?(y) } } }
329
+ drain_idle
330
+ end
331
+
332
+ def test_demo_duration
333
+ DemoPlayer::DEMOS.each_key { |n|
334
+ d = DemoPlayer.duration(n)
335
+ assert d > 5 && d < 600, "#{n}: #{d} s"
336
+ assert DemoPlayer.duration_text(n).match?(/\A\d+ (s|min)\z/)
337
+ }
338
+ end
339
+
340
+ # ── Vim summary ──────────────────────────────────────────────────────────
341
+
342
+ # Each row of the "keys that do something else" table matches the keymap
343
+ def test_vim_key_table_matches_bindings
344
+ all = vma.kbd.bindings
345
+ VIM_INTRO_KEYS.each { |mode, keys, _vim, action|
346
+ b = all.find { |x| x[:mode] == mode && x[:keys].join(" ") == keys && x[:template].nil? }
347
+ assert b, "#{mode} #{keys}: not bound"
348
+ assert_eq action, b[:action].to_s, "#{mode} #{keys}"
349
+ }
350
+ page = show_help_page("vim_intro")
351
+ VIM_INTRO_KEYS.each { |_, keys, vim, _| assert page.lines.any? { |l| l.include?(keys) && l.include?(vim) }, keys }
352
+ ensure
353
+ close_help_pages
354
+ end
355
+
356
+ # ── At start ─────────────────────────────────────────────────────────────
357
+
358
+ def test_intro_on_startup_rules
359
+ was = cnf.intro.show_on_startup?
360
+ sf = cnf.startup_file!
361
+ cnf.intro.show_on_startup = true
362
+ cnf.startup_file = false
363
+ rule = lambda { |argv: [], forced: false, test_mode: false, session: []|
364
+ intro_on_startup?(argv: argv, forced: forced, test_mode: test_mode, session: session)
365
+ }
366
+ assert rule.(), "fresh start"
367
+ assert rule.(forced: true, test_mode: true, session: ["x"]), "--intro"
368
+ assert !rule.(test_mode: true), "test mode"
369
+ assert !rule.(argv: [File.join(REPO, "README.md")]), "file argument"
370
+ assert !rule.(argv: [REPO]), "dir argument"
371
+ assert !rule.(session: ["/x"]), "session to restore"
372
+ cnf.startup_file = "/nonexistent/startup.txt"
373
+ assert rule.(), "startup file that doesn't exist"
374
+ cnf.startup_file = File.join(REPO, "README.md")
375
+ assert !rule.(), "startup file opened"
376
+ cnf.startup_file = false
377
+ cnf.intro.show_on_startup = false
378
+ assert !rule.(), "setting off"
379
+ ensure
380
+ cnf.intro.show_on_startup = was
381
+ cnf.startup_file = sf
382
+ end
383
+
384
+ # Real starts: shown with a fresh config dir, not the second time, not
385
+ # with a file to open; --intro shows it anyway
386
+ def test_shown_on_first_start
387
+ skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
388
+ Dir.mktmpdir("vma-intro") { |tmp|
389
+ ud = File.join(tmp, "user")
390
+ assert_eq "intro", start_and_report(ud)
391
+ assert_eq "nil", start_and_report(ud)
392
+ assert_eq "intro", start_and_report(ud, "--intro")
393
+ assert_eq "nil", start_and_report(File.join(tmp, "user2"), File.join(REPO, "README.md"))
394
+ assert File.read(File.join(ud, "settings.rb")).include?("cnf.intro.show_on_startup = false")
395
+ }
396
+ end
397
+
398
+ # Starts the editor with user dir ud; returns the help page shown once it
399
+ # is up ("nil" for none)
400
+ def start_and_report(ud, *args)
401
+ FileUtils.mkdir_p(ud)
402
+ out = File.join(ud, "shown.txt")
403
+ FileUtils.rm_f(out)
404
+ # custom.rb as on a real first start (from custom_example.rb), plus a
405
+ # report of the page shown
406
+ File.write(File.join(ud, "custom.rb"), File.read(File.join(REPO, "custom_example.rb")) + <<~RUBY)
407
+ cnf.lsp.enabled = false
408
+ def hook_custom_after_init
409
+ GLib::Idle.add {
410
+ File.write(#{out.inspect}, vma.buf.help_page.inspect.delete('"'))
411
+ GLib::Timeout.add(200) { vma.shutdown; false }
412
+ false
413
+ }
414
+ end
415
+ RUBY
416
+ pid = Process.spawn(RbConfig.ruby, File.join(REPO, "exe/vimamsa"), "--user-dir", ud, *args,
417
+ out: File::NULL, err: File.join(ud, "log.txt"))
418
+ t = Time.now
419
+ until File.exist?(out) && File.size(out) > 0
420
+ if Process.waitpid(pid, Process::WNOHANG)
421
+ pid = nil
422
+ break
423
+ end
424
+ if Time.now - t > 60
425
+ break
426
+ end
427
+ sleep 0.05
428
+ end
429
+ if pid
430
+ t = Time.now
431
+ sleep 0.05 while Process.waitpid(pid, Process::WNOHANG).nil? && Time.now - t < 20
432
+ Process.kill("KILL", pid) rescue nil
433
+ Process.wait(pid) rescue nil
434
+ end
435
+ File.exist?(out) ? File.read(out) : "no report (log: #{File.read(File.join(ud, "log.txt"))[-500..]})"
436
+ end
437
+ end
@@ -0,0 +1,41 @@
1
+ require "tempfile"
2
+
3
+ # Regression tests for jump_to_file / open_new_file.
4
+ #
5
+ # Bug: when the target file was not already open, open_new_file returned the
6
+ # buffer *id* (an Integer) instead of the Buffer object, so jump_to_file crashed
7
+ # with "undefined method `jump_to_line' for an instance of Integer". This is the
8
+ # path hit when jumping to source from a whole-repo git diff (diffview enter).
9
+ class TestJumpToFile < VmaTest
10
+
11
+ def make_temp_file(contents)
12
+ f = Tempfile.new(["jump_target", ".txt"])
13
+ f.write(contents)
14
+ f.flush
15
+ f
16
+ end
17
+
18
+ # open_new_file must hand back a Buffer for a file that isn't open yet.
19
+ def test_open_new_file_returns_buffer_when_not_open
20
+ f = make_temp_file("line1\nline2\nline3\n")
21
+ path = File.expand_path(f.path)
22
+ b = open_new_file(path)
23
+ assert b.is_a?(Buffer), "open_new_file must return a Buffer, got #{b.class}: #{b.inspect}"
24
+ assert_eq path, b.fname
25
+ ensure
26
+ f.close
27
+ f.unlink
28
+ end
29
+
30
+ # The end-to-end path that was crashing: jump to a line in a not-yet-open file.
31
+ def test_jump_to_file_positions_cursor
32
+ f = make_temp_file("line1\nline2\nline3\nline4\nline5\n")
33
+ path = File.expand_path(f.path)
34
+ jump_to_file(path, 3) # 1-based line 3
35
+ assert_eq path, vma.buf.fname
36
+ assert_eq 2, vma.buf.lpos # -> 0-based line 2
37
+ ensure
38
+ f.close
39
+ f.unlink
40
+ end
41
+ end
@@ -107,6 +107,69 @@ class TestKeyBindings < VmaTest
107
107
  assert_eq 2, count, "neither binding should fire after unbind"
108
108
  end
109
109
 
110
+ # include_child_nodes: clear every binding under a node in one call.
111
+
112
+ def test_unbindkey_include_child_nodes_clears_mode
113
+ count = 0
114
+ reg_act(:_test_uc1, proc { count += 1 }, "test")
115
+ reg_act(:_test_uc2, proc { count += 1 }, "test")
116
+ vma.kbd.add_minor_mode("tdictmode", :tdictmode, :command)
117
+ bindkey "tdictmode ctrl-F10", :_test_uc1
118
+ bindkey "tdictmode ctrl-F11 ctrl-F12", :_test_uc2
119
+
120
+ vma.kbd.set_mode(:tdictmode)
121
+ keys "ctrl-F10"
122
+ keys "ctrl-F11 ctrl-F12"
123
+ assert_eq 2, count, "both mode bindings should fire before unbind"
124
+
125
+ unbindkey "tdictmode", include_child_nodes: true
126
+ keys "ctrl-F10"
127
+ keys "ctrl-F11 ctrl-F12"
128
+ assert_eq 2, count, "no mode binding should fire after clearing children"
129
+ ensure
130
+ vma.kbd.set_mode(:command)
131
+ end
132
+
133
+ # A bare mode id (no chord) implies include_child_nodes.
134
+ def test_unbindkey_bare_mode_clears_children
135
+ count = 0
136
+ reg_act(:_test_ub_bare, proc { count += 1 }, "test")
137
+ vma.kbd.add_minor_mode("tbaremode", :tbaremode, :command)
138
+ bindkey "tbaremode ctrl-F9", :_test_ub_bare
139
+
140
+ vma.kbd.set_mode(:tbaremode)
141
+ keys "ctrl-F9"
142
+ assert_eq 1, count, "mode binding should fire before unbind"
143
+
144
+ unbindkey "tbaremode"
145
+ keys "ctrl-F9"
146
+ assert_eq 1, count, "bare-mode unbind should clear children"
147
+ ensure
148
+ vma.kbd.set_mode(:command)
149
+ end
150
+
151
+ # Clearing a minor mode's children must leave the inherited (command) mode.
152
+ def test_unbindkey_include_child_nodes_keeps_parent_mode
153
+ parent_count = 0
154
+ child_count = 0
155
+ reg_act(:_test_parent, proc { parent_count += 1 }, "test")
156
+ reg_act(:_test_child, proc { child_count += 1 }, "test")
157
+ bindkey "C ctrl-F7", :_test_parent
158
+ vma.kbd.add_minor_mode("tdmodeb", :tdmodeb, :command)
159
+ bindkey "tdmodeb ctrl-F8", :_test_child
160
+
161
+ vma.kbd.set_mode(:tdmodeb)
162
+ unbindkey "tdmodeb", include_child_nodes: true
163
+
164
+ keys "ctrl-F8"
165
+ assert_eq 0, child_count, "child binding should be cleared"
166
+ keys "ctrl-F7"
167
+ assert_eq 1, parent_count, "inherited command binding should still fire"
168
+ ensure
169
+ vma.kbd.set_mode(:command)
170
+ unbindkey "C ctrl-F7"
171
+ end
172
+
110
173
  # ── || (pipe) multi-binding syntax ───────────────────────────────────────
111
174
 
112
175
  def test_pipe_syntax_both_keys_trigger_same_action
@@ -122,6 +185,48 @@ class TestKeyBindings < VmaTest
122
185
 
123
186
  # ── repeat count ─────────────────────────────────────────────────────────
124
187
 
188
+ # Seed the buffer with `n` numbered lines ("line1".."lineN") and park the
189
+ # cursor at the top. The fresh test buffer is already "\n", so chomp.
190
+ def seed_numbered_lines(n)
191
+ text = (1..n).map { |i| "line#{i}" }.join("\n")
192
+ act "buf.insert_txt(#{text.inspect})"
193
+ act "buf.set_pos(0)"
194
+ end
195
+
196
+ # Text of the line the cursor is on.
197
+ def cur_line_text
198
+ vma.buf.to_s.lines[vma.buf.lpos].to_s.chomp
199
+ end
200
+
201
+ # "20G" jumps to line 20. Exercises a multi-digit count: each digit folds into
202
+ # next_command_count, then G's counted variant routes to buf.jump_to_line.
203
+ # The "0" matters — it is bound separately from [1-9] (a leading "0" is
204
+ # jump-to-column-0, not a count), so a two-digit count is the case that breaks.
205
+ def test_count_20_G_jumps_to_line_20
206
+ seed_numbered_lines(30)
207
+ keys "2 0 G"
208
+ assert_eq "line20", cur_line_text, "20G should land on line 20"
209
+ assert_pos 19, 0, "20G should put the cursor at the start of line 20"
210
+ end
211
+
212
+ # Single-digit count, for contrast: proves the count path itself works, so a
213
+ # failure above is specific to accumulating a second digit.
214
+ def test_count_5_G_jumps_to_line_5
215
+ seed_numbered_lines(30)
216
+ keys "5 G"
217
+ assert_eq "line5", cur_line_text, "5G should land on line 5"
218
+ assert_pos 4, 0, "5G should put the cursor at the start of line 5"
219
+ end
220
+
221
+ # esc aborts a count that is being typed, so the digits don't silently attach
222
+ # to the next command ("2 0 0 esc d d" must delete one line, not 200).
223
+ def test_esc_cancels_pending_count
224
+ keys "2 0 0"
225
+ assert_eq 200, vma.kbd.next_command_count, "digits should accumulate into a count"
226
+ keys "esc"
227
+ assert_eq nil, vma.kbd.next_command_count, "esc should cancel the pending count"
228
+ end
229
+
125
230
  def test_repeat_count_executes_action_n_times
126
231
  count = 0
127
232
  reg_act(:_test_repeat, proc { count += 1 }, "test")
@@ -149,4 +254,107 @@ class TestKeyBindings < VmaTest
149
254
  keys "esc"
150
255
  end
151
256
 
257
+ # ── binding to a mode that does not exist ────────────────────────────────
258
+
259
+ # A binding for an unknown mode used to be installed silently into the
260
+ # current default mode instead: 'bindkey "fexp , x"' in custom.rb (loaded
261
+ # before FileManager.init creates the fexp mode) became "C , x" and fired in
262
+ # every buffer.
263
+ def test_bindkey_unknown_mode_is_reported_and_binds_nothing
264
+ errors = capture_kbd_errors {
265
+ bindkey "nosuchmode z z", :_test_unknown_mode_action
266
+ }
267
+ assert_eq 1, errors.size, "unknown mode should be reported once: #{errors.inspect}"
268
+ assert errors[0].include?("nosuchmode"), "error should name the mode: #{errors[0]}"
269
+ assert_eq [], find_binding_paths(:_test_unknown_mode_action),
270
+ "nothing should have been bound"
271
+ end
272
+
273
+ # Mode part neither all uppercase (major modes) nor all lowercase (minor
274
+ # modes): used to raise NoMethodError on nil while loading custom.rb.
275
+ def test_bindkey_mixed_case_mode_is_reported_and_binds_nothing
276
+ errors = capture_kbd_errors {
277
+ bindkey "Fexp z z", :_test_mixed_case_mode_action
278
+ }
279
+ assert_eq 1, errors.size, "invalid mode should be reported once: #{errors.inspect}"
280
+ assert_eq [], find_binding_paths(:_test_mixed_case_mode_action),
281
+ "nothing should have been bound"
282
+ end
283
+
284
+ def test_bindkey_known_minor_mode_binds_to_that_mode
285
+ bindkey "fexp z z", :_test_fexp_action
286
+ assert_eq ["fexp z z"], find_binding_paths(:_test_fexp_action)
287
+ unbindkey "fexp z z"
288
+ end
289
+
290
+ # ── count inside a sequence (<num>) ──────────────────────────────────────
291
+
292
+ def test_count_inside_delete_word
293
+ vma.buf.set_content("one two three four\n")
294
+ vma.buf.set_pos(0)
295
+ keys "d 3 e"
296
+ assert_buf " four\n"
297
+ assert_mode :command
298
+ end
299
+
300
+ def test_count_inside_multiplies_outer_count
301
+ vma.buf.set_content("a b c d e f g h\n")
302
+ vma.buf.set_pos(0)
303
+ keys "2 d 3 e"
304
+ assert_buf " g h\n"
305
+ end
306
+
307
+ def test_count_inside_multi_digit
308
+ vma.buf.set_content((1..12).map(&:to_s).join(" ") + "\n")
309
+ vma.buf.set_pos(0)
310
+ keys "d 1 1 e"
311
+ assert_buf " 12\n"
312
+ end
313
+
314
+ def test_count_inside_aborted
315
+ vma.buf.set_content("one two three\n")
316
+ vma.buf.set_pos(0)
317
+ keys "d 2 esc"
318
+ keys "d e"
319
+ assert_buf " two three\n" # no count left over from the aborted sequence
320
+ end
321
+
322
+ def test_count_inside_custom_binding
323
+ got = []
324
+ bindkey "C , x <num> y", "$test_num_y << 1"
325
+ $test_num_y = got
326
+ keys ", x 4 y"
327
+ assert_eq 4, got.size
328
+ end
329
+
330
+ private
331
+
332
+ # Collect the errors the key binding tree reports while running blk.
333
+ def capture_kbd_errors
334
+ errors = []
335
+ prev = vma.kbd.error_handler
336
+ vma.kbd.error_handler = proc { |msg| errors << msg }
337
+ begin
338
+ yield
339
+ ensure
340
+ vma.kbd.error_handler = prev
341
+ end
342
+ errors
343
+ end
344
+
345
+ # Every key sequence in the whole tree bound to action, e.g. ["C , x"]
346
+ def find_binding_paths(action)
347
+ found = []
348
+ walk = lambda { |state, path|
349
+ state.children.each { |c|
350
+ p2 = path + [c.key_name]
351
+ found << p2.join(" ") if c.action == action
352
+ walk.call(c, p2)
353
+ }
354
+ }
355
+ vma.kbd.root.children.each { |mode| walk.call(mode, [mode.key_name]) }
356
+ found
357
+ end
358
+
359
+
152
360
  end