vimamsa 0.1.27 → 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 (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -89
  3. data/custom_example.rb +18 -6
  4. data/doc/TODO.md +327 -110
  5. data/doc/action_names_plan.md +442 -0
  6. data/doc/bundling_plan.md +2 -1
  7. data/doc/delta_syntax_plan.md +293 -0
  8. data/doc/demo_recording_plan.md +288 -0
  9. data/doc/design_goals.md +27 -0
  10. data/doc/intro_page_plan.md +266 -0
  11. data/doc/key_bindings_report_plan.md +45 -0
  12. data/doc/line_tree_plan.md +89 -0
  13. data/doc/missing_vim_bindings.md +34 -44
  14. data/doc/modules_settings_plan.md +1 -1
  15. data/doc/registries_plan.md +202 -0
  16. data/doc/startup_speed_plan.md +97 -0
  17. data/doc/treap_visualizer.html +585 -0
  18. data/doc/vim_compatibility_plan.md +186 -31
  19. data/doc/vimlike_vim_conflicts.md +236 -228
  20. data/doc/vm_snapshots_plan.md +4 -4
  21. data/doc/wysiwyg_plan.md +231 -0
  22. data/exe/run_tests.rb +8 -1
  23. data/exe/vimamsa +49 -6
  24. data/help/intro.txt +30 -0
  25. data/help/vim_intro.txt +31 -0
  26. data/img/demo.gif +0 -0
  27. data/img/demo.mp4 +0 -0
  28. data/lang/hyperplaintext.lang +1 -1
  29. data/lib/vimamsa/ack.rb +2 -0
  30. data/lib/vimamsa/actions.rb +381 -36
  31. data/lib/vimamsa/bookmarks.rb +8 -8
  32. data/lib/vimamsa/buffer.rb +83 -37
  33. data/lib/vimamsa/buffer_changetext.rb +58 -36
  34. data/lib/vimamsa/buffer_list.rb +2 -2
  35. data/lib/vimamsa/buffer_manager.rb +6 -6
  36. data/lib/vimamsa/cli_help.rb +75 -0
  37. data/lib/vimamsa/clipboard.rb +6 -3
  38. data/lib/vimamsa/conf.rb +9 -0
  39. data/lib/vimamsa/crash_handler.rb +2 -2
  40. data/lib/vimamsa/debug.rb +2 -2
  41. data/lib/vimamsa/demo_player.rb +458 -0
  42. data/lib/vimamsa/demo_recorder.rb +277 -0
  43. data/lib/vimamsa/diff_buffer.rb +1 -1
  44. data/lib/vimamsa/dot_repeat.rb +104 -0
  45. data/lib/vimamsa/easy_jump.rb +54 -3
  46. data/lib/vimamsa/editor.rb +89 -46
  47. data/lib/vimamsa/file_history.rb +1 -1
  48. data/lib/vimamsa/file_manager.rb +23 -23
  49. data/lib/vimamsa/form_input.rb +388 -0
  50. data/lib/vimamsa/gui.rb +83 -13
  51. data/lib/vimamsa/gui_command_line.rb +44 -5
  52. data/lib/vimamsa/gui_form_generator.rb +17 -6
  53. data/lib/vimamsa/gui_key_hint.rb +165 -0
  54. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  55. data/lib/vimamsa/gui_menu.rb +69 -50
  56. data/lib/vimamsa/gui_select_window.rb +77 -43
  57. data/lib/vimamsa/gui_settings.rb +9 -5
  58. data/lib/vimamsa/gui_sourceview.rb +15 -81
  59. data/lib/vimamsa/gui_theme.rb +11 -2
  60. data/lib/vimamsa/hook.rb +2 -0
  61. data/lib/vimamsa/intro_page.rb +368 -0
  62. data/lib/vimamsa/key_actions.rb +315 -225
  63. data/lib/vimamsa/key_binding_tree.rb +228 -61
  64. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  65. data/lib/vimamsa/key_bindings_report.rb +290 -67
  66. data/lib/vimamsa/key_bindings_vim.rb +47 -297
  67. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  68. data/lib/vimamsa/key_names.rb +80 -0
  69. data/lib/vimamsa/line_tree.rb +367 -0
  70. data/lib/vimamsa/macro.rb +20 -3
  71. data/lib/vimamsa/rbvma.rb +15 -0
  72. data/lib/vimamsa/registers.rb +125 -0
  73. data/lib/vimamsa/run_ruby.rb +64 -0
  74. data/lib/vimamsa/search_replace.rb +4 -4
  75. data/lib/vimamsa/string_util.rb +17 -3
  76. data/lib/vimamsa/tests.rb +8 -8
  77. data/lib/vimamsa/text_objects.rb +11 -54
  78. data/lib/vimamsa/text_transforms.rb +4 -0
  79. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  80. data/lib/vimamsa/user_dirs.rb +83 -0
  81. data/lib/vimamsa/version.rb +1 -1
  82. data/lib/vimamsa/vim_core.rb +355 -0
  83. data/lib/vimamsa/vim_operators.rb +365 -0
  84. data/modules/calculator/calculator.rb +5 -5
  85. data/modules/color_highlight/color_highlight.rb +3 -3
  86. data/modules/dictation/dictation.rb +32 -32
  87. data/modules/ollama/ollama.rb +5 -5
  88. data/modules/terminal/terminal.rb +5 -5
  89. data/modules/tts/tts.rb +10 -10
  90. data/run_e2e_vm.sh +3 -3
  91. data/run_tests_vm.rb +138 -0
  92. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  93. data/scripts/demo/demo_files_steps.txt +52 -0
  94. data/scripts/demo/demo_steps.txt +9 -1
  95. data/scripts/demo/notes.txt +6 -0
  96. data/scripts/demo/record_demo.rb +60 -81
  97. data/scripts/demo/report.rb +7 -0
  98. data/scripts/demo/shapes.rb +1 -0
  99. data/scripts/demo/square/shapes.rb +29 -0
  100. data/scripts/demo/square/steps.txt +185 -0
  101. data/scripts/lib/perf_startup.rb +138 -0
  102. data/scripts/lib/script_helpers.rb +53 -0
  103. data/scripts/perf_compare.rb +34 -0
  104. data/scripts/profile_startup.rb +72 -0
  105. data/tests/test_action_ids.rb +232 -0
  106. data/tests/test_auto_format.rb +2 -2
  107. data/tests/test_autocomplete.rb +1 -1
  108. data/tests/test_basic_editing.rb +18 -18
  109. data/tests/test_bookmarks.rb +6 -6
  110. data/tests/test_bracket_match.rb +3 -0
  111. data/tests/test_cli_help.rb +64 -0
  112. data/tests/test_color_highlight.rb +2 -2
  113. data/tests/test_command_line.rb +1 -1
  114. data/tests/test_context_menu_file.rb +18 -0
  115. data/tests/test_copy_paste.rb +33 -33
  116. data/tests/test_custom_two_phase.rb +1 -1
  117. data/tests/test_demo_player.rb +301 -0
  118. data/tests/test_demo_recorder.rb +202 -0
  119. data/tests/test_dictation.rb +16 -16
  120. data/tests/test_dot_repeat.rb +88 -0
  121. data/tests/test_easy_jump.rb +93 -0
  122. data/tests/test_extract_file_links.rb +3 -3
  123. data/tests/test_file_panel.rb +2 -2
  124. data/tests/test_flash.rb +1 -1
  125. data/tests/test_fold.rb +1 -1
  126. data/tests/test_form_input.rb +203 -0
  127. data/tests/test_func_panel.rb +2 -2
  128. data/tests/test_gtk_sync.rb +7 -7
  129. data/tests/test_intro_page.rb +437 -0
  130. data/tests/test_key_categories.rb +163 -0
  131. data/tests/test_keylog_panel.rb +163 -3
  132. data/tests/test_line_ends.rb +51 -0
  133. data/tests/test_line_tree.rb +86 -0
  134. data/tests/test_lsp_clangd.rb +2 -2
  135. data/tests/test_macro.rb +2 -2
  136. data/tests/test_module_interface.rb +9 -9
  137. data/tests/test_notepad_bindings.rb +5 -5
  138. data/tests/test_perf_startup.rb +28 -0
  139. data/tests/test_random_edit.rb +27 -27
  140. data/tests/test_registers.rb +122 -0
  141. data/tests/test_run_ruby.rb +77 -0
  142. data/tests/test_startup_file.rb +1 -1
  143. data/tests/test_text_objects.rb +1 -1
  144. data/tests/test_text_transforms.rb +12 -0
  145. data/tests/test_tmp_user_dir.rb +79 -0
  146. data/tests/test_tts.rb +10 -10
  147. data/tests/test_undo.rb +34 -34
  148. data/tests/test_user_dirs.rb +122 -0
  149. data/tests/test_vim_bindings.rb +107 -6
  150. data/tests/test_vim_conflicts.rb +41 -4
  151. data/tests/test_vim_operators.rb +116 -0
  152. data/tests/test_window_layout.rb +83 -0
  153. data/vimamsa.gemspec +1 -1
  154. data/vm_guest_run.sh +22 -2
  155. metadata +58 -3
  156. data/run_tests_vm.sh +0 -130
@@ -0,0 +1,232 @@
1
+ # Dotted action ids, the a.… reference and old-id aliases
2
+ # (doc/action_names_plan.md, step 1).
3
+ class TestActionIds < VmaTest
4
+ KEYS = %w[1 2 3 4 5].map { |n| "C , Q Q #{n}" }
5
+
6
+ def setup_counter
7
+ @n = 0
8
+ reg_act("test.ids.run", proc { @n += 1 }, "Test action")
9
+ end
10
+
11
+ def cleanup
12
+ KEYS.each { |k| unbindkey(k) rescue nil }
13
+ unreg_act("test.ids.run")
14
+ ACTION_ALIASES.delete(:test_ids_old)
15
+ end
16
+
17
+ def test_string_id_registers_and_runs
18
+ setup_counter
19
+ assert vma.actions.include?("test.ids.run")
20
+ assert vma.actions.include?(a.test.ids.run), "a.… reference not resolved"
21
+ act("test.ids.run")
22
+ a.test.ids.run!
23
+ assert_eq 2, @n
24
+ ensure
25
+ cleanup
26
+ end
27
+
28
+ def test_bindkey_accepts_string_and_reference
29
+ setup_counter
30
+ bindkey KEYS[0], "test.ids.run"
31
+ bindkey KEYS[1], a.test.ids.run
32
+ keys(", Q Q 1")
33
+ keys(", Q Q 2")
34
+ assert_eq 2, @n
35
+ assert_eq ", Q Q 2", vma.kbd.act_bindings["C"]["test.ids.run"]
36
+ ensure
37
+ cleanup
38
+ end
39
+
40
+ def test_old_id_alias
41
+ setup_counter
42
+ ACTION_ALIASES[:test_ids_old] = "test.ids.run"
43
+ assert vma.actions.include?(:test_ids_old)
44
+ bindkey KEYS[2], :test_ids_old
45
+ keys(", Q Q 3")
46
+ act(:test_ids_old)
47
+ act("test_ids_old") # as a macro stored in JSON has it
48
+ assert_eq 3, @n
49
+ # the binding is stored under the new id
50
+ assert_eq ", Q Q 3", vma.kbd.act_bindings["C"]["test.ids.run"]
51
+ ensure
52
+ cleanup
53
+ end
54
+
55
+ def test_unknown_reference_is_an_error_with_suggestion
56
+ setup_counter
57
+ msgs = []
58
+ old = vma.kbd.error_handler
59
+ vma.kbd.error_handler = proc { |m| msgs << m }
60
+ begin
61
+ bindkey KEYS[3], a.test.ids.rnu
62
+ ensure
63
+ vma.kbd.error_handler = old
64
+ end
65
+ assert msgs.any? { |m| m.include?("test.ids.rnu") && m.include?("did you mean test.ids.run") }, msgs.inspect
66
+ assert !vma.kbd.act_bindings["C"].key?("test.ids.rnu"), "typo was bound"
67
+ err = (a.test.ids.rnu! rescue $!)
68
+ assert err.message.include?("did you mean test.ids.run"), err.message
69
+ ensure
70
+ cleanup
71
+ end
72
+
73
+ # BasicObject proxy: names Object defines are path segments too
74
+ def test_reference_paths
75
+ assert_eq "move.line.end", a.move.line.end.to_s
76
+ assert_eq "app.class.send.display", a.app.class.send.display.to_s
77
+ assert_eq "a.buf.save.as", a.buf.save.as.inspect
78
+ assert_eq "x buf.save", "x #{a.buf.save}"
79
+ end
80
+
81
+ # A registered id wins over running the string as Ruby; other strings,
82
+ # including bound Ruby code, still run as Ruby
83
+ def test_registered_id_wins_over_ruby
84
+ got = nil
85
+ reg_act("buf.lines", proc { got = :action }, "Test")
86
+ exec_action("buf.lines")
87
+ assert_eq :action, got
88
+ unreg_act("buf.lines")
89
+ assert_eq vma.buf.lines, exec_action("buf.lines")
90
+
91
+ bindkey KEYS[4], "vma.buf.set_content('ruby ran')"
92
+ keys(", Q Q 5")
93
+ assert vma.buf.to_s.start_with?("ruby ran"), vma.buf.to_s.inspect
94
+ ensure
95
+ unreg_act("buf.lines")
96
+ cleanup
97
+ end
98
+
99
+ def test_command_line_runs_reference
100
+ setup_counter
101
+ eval("a.test.ids.run!", TOPLEVEL_BINDING)
102
+ assert_eq 1, @n
103
+ ensure
104
+ cleanup
105
+ end
106
+
107
+ def test_macros_convert_old_ids
108
+ setup_counter
109
+ ACTION_ALIASES[:test_ids_old] = "test.ids.run"
110
+ m = { "x" => [:test_ids_old, "test_ids_old", "buf.move(FORWARD_CHAR)"], "y" => ["move.word.next"] }
111
+ assert vma.macro.convert_action_aliases(m)
112
+ assert_eq ["test.ids.run", "test.ids.run", "buf.move(FORWARD_CHAR)"], m["x"]
113
+ assert_eq ["move.word.next"], m["y"]
114
+ assert !vma.macro.convert_action_aliases(m), "second pass changed something"
115
+ # A macro still holding an old id runs
116
+ vma.macro.run_actions([:test_ids_old, "test.ids.run"])
117
+ assert_eq 2, @n
118
+ ensure
119
+ cleanup
120
+ end
121
+
122
+ # Step 2: duplicates merged into one action each; the old ids are aliases
123
+ def test_duplicates_merged
124
+ { "undo.last" => [:undo, :edit_undo], "undo.redo" => [:redo, :edit_redo],
125
+ "jump.edit.prev" => [:jump_last_edit, :jump_to_last_edit],
126
+ "move.char.prev" => [:move_backward_char, :e_move_backward_char],
127
+ "move.line.next" => [:move_next_line, :forward_line],
128
+ "move.line.prev" => [:move_prev_line, :backward_line],
129
+ "grep.buf" => [:grep_buffer, :invoke_grep_search] }.each { |id, olds|
130
+ assert vma.actions.ids.include?(id), "#{id} not registered"
131
+ olds.each { |o|
132
+ assert !vma.actions.ids.include?(o), "#{o} still registered on its own"
133
+ assert vma.actions[o].equal?(vma.actions[id]), "#{o} doesn't resolve to #{id}"
134
+ }
135
+ }
136
+ buf.set_content("ab\n")
137
+ buf.set_pos(0)
138
+ keys("x") # vimlike x: delete char
139
+ act(:edit_undo) # old menu id still works
140
+ assert_buf "ab\n"
141
+ end
142
+
143
+ # Ids registered only by another keymap, an optional module or a minor mode
144
+ # set up on first use; not loaded in the test setup
145
+ OPTIONAL_IDS = /\A(mode\.notepad|dictation|tts|ollama|terminal|calculator|color_highlight|fexp|bmgr|bmark|diffview)\./
146
+
147
+ NAMESPACES = %w[app mode move jump search grep ack edit undo case sel buf file
148
+ panel view style macro mark lsp term help debug custom kbd op form]
149
+
150
+ # Registered actions other than Ruby-code bindings and the user's custom.rb
151
+ # (eval'd, so its procs come from "(eval)")
152
+ def own_actions
153
+ vma.actions.ids.map { |k| [k, vma.actions[k]] }.reject { |_k, a|
154
+ a.opt&.[](:code) || (a.method.respond_to?(:source_location) && a.method.source_location.to_a[0].to_s.start_with?("(eval"))
155
+ }
156
+ end
157
+
158
+ def test_ids_are_dotted_with_known_namespace
159
+ known = NAMESPACES + Dir[File.expand_path("../modules/*", __dir__)].map { |d| File.basename(d) } +
160
+ vma.kbd.root.children.map(&:key_name) +
161
+ %w[diffview] # minor mode created on first use
162
+ bad = own_actions.map(&:first).reject { |k|
163
+ k.class == String && k.match?(ACTION_ID_RE) && known.include?(k.split(".")[0])
164
+ }
165
+ assert bad.empty?, "ids not of the form <namespace>.x.y: #{bad.inspect}"
166
+ end
167
+
168
+ # Catches duplicates like undo / edit_undo
169
+ def test_no_duplicate_actions
170
+ by = own_actions.group_by { |_k, a|
171
+ m = a.method
172
+ [m.respond_to?(:source_location) ? m.source_location : m.inspect, a.method_name]
173
+ }
174
+ dups = by.values.select { |v| v.size > 1 }.map { |v| v.map(&:first) }
175
+ assert dups.empty?, "same code and description: #{dups.inspect}"
176
+ end
177
+
178
+ # ── Step 4: using the hierarchy ──
179
+
180
+ def test_path_replaces_group
181
+ assert_eq ["move", "word", "next"], vma.actions["move.word.next"].path
182
+ grouped = own_actions.select { |_k, a| a.opt&.key?(:group) }.map(&:first)
183
+ assert grouped.empty?, ":group still set on #{grouped.inspect}"
184
+ end
185
+
186
+ def test_complete
187
+ ns = vma.actions.complete("")
188
+ assert ns.include?("move.") && ns.include?("buf."), ns.inspect
189
+ m = vma.actions.complete("move.")
190
+ assert m.include?("move.word.") && m.include?("move.random"), m.inspect
191
+ assert m.all? { |c| c.start_with?("move.") }
192
+ b = vma.actions.complete("buf.")
193
+ assert b.include?("buf.save") && b.include?("buf.save."), "action and parent: #{b.inspect}"
194
+ end
195
+
196
+ def test_search_actions_namespace_filter
197
+ rows = vma.actions.search_actions_update_callback("move.")
198
+ assert rows.size > 5, rows.inspect
199
+ assert rows.all? { |_key, str| str.start_with?("move.") }, rows.inspect
200
+ # id and description in columns of their own
201
+ assert rows.any? { |_key, id, desc| id == "move.word.next" && !desc.to_s.empty? }, "no description shown"
202
+ rows = vma.actions.search_actions_update_callback("move.wordnext")
203
+ assert rows.all? { |_key, str| str.start_with?("move.") }, rows.inspect
204
+ assert rows[0][1].start_with?("move.word.next"), rows.inspect
205
+ end
206
+
207
+ def test_search_actions_finds_old_id
208
+ rows = vma.actions.search_actions_update_callback("close_current_buffer")
209
+ assert rows[0][1].start_with?("buf.close"), rows.inspect
210
+ end
211
+
212
+ def test_cmdline_tab_completion
213
+ cl = vma.gui.cmd_line
214
+ e = cl.entry
215
+ { "a.mov" => "a.move.", "a.move.wo" => "a.move.word.", "x = a.buf.sav" => "x = a.buf.save",
216
+ "a.buf.save" => "a.buf.save", "foo.mov" => "foo.mov" }.each { |typed, want|
217
+ e.text = typed
218
+ e.set_position(-1)
219
+ cl.complete_action_id
220
+ assert_eq want, e.text
221
+ }
222
+ e.text = "a.mo"
223
+ e.set_position(-1)
224
+ assert_eq ["mode.", "move."], cl.complete_action_id
225
+ e.text = ""
226
+ end
227
+
228
+ def test_every_alias_points_to_an_action
229
+ bad = ACTION_ALIASES.reject { |_old, n| vma.actions.include?(n) || n.match?(OPTIONAL_IDS) }
230
+ assert bad.empty?, "aliases to unregistered actions: #{bad.inspect}"
231
+ end
232
+ end
@@ -29,7 +29,7 @@ class TestAutoFormat < VmaTest
29
29
  set_lang("ruby")
30
30
  # Put cursor somewhere in the middle of the content
31
31
  act 'buf.set_content("x=1\ny=2\nz=3\n")'
32
- act :jump_to_start_of_buffer
32
+ act "move.buf.start"
33
33
  act "buf.auto_format"
34
34
  # Cursor should be within valid buffer bounds
35
35
  pos = vma.buf.pos
@@ -42,7 +42,7 @@ class TestAutoFormat < VmaTest
42
42
  set_lang("ruby")
43
43
  # Lots of extra whitespace that rufo will remove — content shrinks
44
44
  act 'buf.set_content("x = 1\ny = 2\n")'
45
- act :jump_to_end_of_buffer
45
+ act "move.buf.end"
46
46
  act "buf.auto_format"
47
47
  pos = vma.buf.pos
48
48
  assert pos >= 0, "cursor pos #{pos} is negative after shrink"
@@ -147,7 +147,7 @@ class TestAutocomplete < VmaTest
147
147
  keys("i z e")
148
148
  keys("esc") # dismiss, stay in insert
149
149
  assert !view.autocp_active
150
- act :autocp_manual_trigger
150
+ act "edit.complete"
151
151
  assert view.autocp_active, "ctrl-space action should reopen the popup"
152
152
  ensure
153
153
  teardown_seed
@@ -6,9 +6,9 @@ class TestBasicEditing < VmaTest
6
6
 
7
7
  def test_delete_char_forward
8
8
  act 'buf.insert_txt("abcde")'
9
- act :jump_to_start_of_buffer
10
- act :delete_char_forward
11
- act :delete_char_forward
9
+ act "move.buf.start"
10
+ act "edit.delete.char"
11
+ act "edit.delete.char"
12
12
  assert_buf "cde\n"
13
13
  end
14
14
 
@@ -21,20 +21,20 @@ class TestBasicEditing < VmaTest
21
21
 
22
22
  def test_select_all_action
23
23
  act 'buf.insert_txt("hello\nworld")'
24
- act :select_all
24
+ act "sel.all"
25
25
  assert vma.buf.selection_active?, "select_all should activate selection"
26
26
  assert_eq 0, vma.buf.get_visual_mode_range.begin
27
27
  assert_eq vma.buf.size - 1, vma.buf.get_visual_mode_range.end
28
- act :copy_selection
28
+ act "sel.copy"
29
29
  assert_eq "hello\nworld\n", vma.clipboard.get
30
30
  end
31
31
 
32
32
  def test_undo_redo
33
33
  act 'buf.insert_txt("hello")'
34
34
  assert_buf "hello\n"
35
- act :undo
35
+ act "undo.last"
36
36
  assert_buf "\n"
37
- act :redo
37
+ act "undo.redo"
38
38
  assert_buf "hello\n"
39
39
  end
40
40
 
@@ -47,27 +47,27 @@ class TestBasicEditing < VmaTest
47
47
 
48
48
  def test_jump_start_end
49
49
  act 'buf.insert_txt("hello")'
50
- act :jump_to_start_of_buffer
50
+ act "move.buf.start"
51
51
  assert_pos 0, 0
52
- act :jump_to_end_of_buffer
52
+ act "move.buf.end"
53
53
  assert_pos 0, 5
54
54
  end
55
55
 
56
56
  def test_copy_paste
57
57
  #Note: Buffer contains a single "\n" by default
58
58
  act 'buf.insert_txt("hello\n")'
59
- act :jump_to_start_of_buffer
60
- act :copy_cur_line
61
- act :jump_to_end_of_buffer
62
- act :paste_after_cursor
59
+ act "move.buf.start"
60
+ act "edit.line.copy"
61
+ act "move.buf.end"
62
+ act "edit.paste.after"
63
63
  assert_buf "hello\n\nhello\n"
64
64
  end
65
65
 
66
66
  def test_delete_line
67
67
  act 'buf.insert_txt("first\n")'
68
68
  act 'buf.insert_txt("second")'
69
- act :jump_to_start_of_buffer
70
- act :delete_line
69
+ act "move.buf.start"
70
+ act "edit.delete.line"
71
71
  assert_buf "second\n"
72
72
  end
73
73
  end
@@ -94,14 +94,14 @@ end
94
94
  class TestDeleteFindChar < VmaTest
95
95
  def test_df_char
96
96
  act 'buf.insert_txt("foo bar baz")'
97
- act :jump_to_start_of_buffer
97
+ act "move.buf.start"
98
98
  keys "d f a"
99
99
  assert_buf "r baz\n"
100
100
  end
101
101
 
102
102
  def test_dF_char
103
103
  act 'buf.insert_txt("foo bar baz")'
104
- act :jump_to_start_of_buffer
104
+ act "move.buf.start"
105
105
  act "buf.set_pos(10)" # on the final 'z'
106
106
  keys "d F a"
107
107
  assert_buf "foo bar bz\n"
@@ -109,7 +109,7 @@ class TestDeleteFindChar < VmaTest
109
109
 
110
110
  def test_df_not_on_line_is_noop
111
111
  act 'buf.insert_txt("foo\nbar")'
112
- act :jump_to_start_of_buffer
112
+ act "move.buf.start"
113
113
  keys "d f b"
114
114
  assert_buf "foo\nbar\n"
115
115
  end
@@ -29,7 +29,7 @@ class TestBookmarks < VmaTest
29
29
  def add_at(path, lpos)
30
30
  jump_to_file(path, lpos + 1)
31
31
  assert_eq lpos, vma.buf.lpos
32
- act(:bookmark_add)
32
+ act("mark.add")
33
33
  bm = vma.bookmarks.list.find { |b| b[:fname] == path && b[:lpos] == lpos }
34
34
  assert bm, "bookmark was not added at line #{lpos}"
35
35
  bm
@@ -172,13 +172,13 @@ class TestBookmarks < VmaTest
172
172
  b3[:created] = Time.now - 200
173
173
  b5[:created] = Time.now - 100
174
174
 
175
- act(:bookmark_list)
175
+ act("mark.list")
176
176
  assert_mode :bmark
177
177
  list_id = vma.buf.id
178
178
  rows = vma.buf.to_s.lines.select { |l| l.include?(tilde_path(path)) }.collect(&:strip)
179
179
  assert_eq ["line 5", "line 3", "line 1"], rows.collect { |r| r.split(" ").last }
180
180
 
181
- act(:bmark_select) # cursor starts on the first (newest) row
181
+ act("bmark.select") # cursor starts on the first (newest) row
182
182
  assert_eq path, vma.buf.fname
183
183
  assert_eq 4, vma.buf.lpos
184
184
  assert vma.buffers.get_buffer_by_id(list_id).nil?, "list buffer should be closed"
@@ -193,13 +193,13 @@ class TestBookmarks < VmaTest
193
193
  add_at(path, 1)
194
194
  bm = add_at(path, 6) # newest -> first row
195
195
 
196
- act(:bookmark_list)
197
- act(:bmark_delete)
196
+ act("mark.list")
197
+ act("bmark.delete")
198
198
  assert !vma.bookmarks.list.include?(bm), "bookmark not deleted"
199
199
  assert_eq 1, vma.bookmarks.list.count { |b| b[:fname] == path }
200
200
  rows = vma.buf.to_s.lines.select { |l| l.include?(tilde_path(path)) }
201
201
  assert_eq 1, rows.size
202
- act(:close_current_buffer)
202
+ act("buf.close")
203
203
  ensure
204
204
  cleanup(f)
205
205
  end
@@ -15,6 +15,9 @@ class TestBracketMatch < VmaTest
15
15
  # [matched_offset, state] from the last "bracket-matched" signal, state as
16
16
  # :found, :not_found, :out_of_range or :none. nil if no signal came.
17
17
  def match_at(pos, text = TEXT)
18
+ # Broadway (--headless without xvfb) draws nothing while no browser is
19
+ # connected, so GtkSourceView never updates the highlight
20
+ skip "no drawing on the Broadway backend" if ENV["VMA_HEADLESS"] == "broadway"
18
21
  b = vma.buf
19
22
  b.set_content(text)
20
23
  drain_idle
@@ -0,0 +1,64 @@
1
+ # vimamsa --help: the options and the actions, without starting the editor
2
+ # (lib/vimamsa/cli_help.rb)
3
+ require "open3"
4
+ require "rbconfig"
5
+ require "tmpdir"
6
+
7
+ class TestCliHelp < VmaTest
8
+ EXE = File.expand_path("../exe/vimamsa", __dir__)
9
+
10
+ def run_help(*args)
11
+ Dir.mktmpdir("vma-help") { |ud|
12
+ # a running editor's listen dir: --help must not be sent to it as a file
13
+ FileUtils.mkdir_p(File.join(ud, "listen"))
14
+ out, st = Open3.capture2e(RbConfig.ruby, EXE, "--user-dir", ud, *args)
15
+ [out, st, Dir.children(File.join(ud, "listen"))]
16
+ }
17
+ end
18
+
19
+ def test_help_lists_options_and_actions
20
+ skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
21
+ out, st, listen = run_help("--help")
22
+ assert st.success?, "exit status #{st.exitstatus}: #{out[-500..]}"
23
+ assert_eq [], listen, "--help was passed to a running editor"
24
+ assert out.include?("Usage: vimamsa"), out[0, 300]
25
+ assert out.include?("--intro")
26
+ assert out.include?("--user-dir")
27
+ lines = out.lines.map(&:strip)
28
+ save = lines.find { |l| l.start_with?("buf.save ") }
29
+ assert save, "buf.save not listed"
30
+ assert_eq vma.actions["buf.save"].method_name.to_s, save.sub(/\Abuf\.save\s+/, ""), "description"
31
+ %w[help.intro help.demo move.motion op.motion edit.register].each { |id|
32
+ assert lines.any? { |l| l == id || l.start_with?("#{id} ") }, "#{id} not listed"
33
+ }
34
+ n = out[/Actions \((\d+)\)/, 1].to_i
35
+ listed = lines.select { |l| l.match?(/\A[a-z][a-z0-9_]*(\.[a-z0-9_]+)+(\s|\z)/) }.map { |l| l.split[0] }
36
+ assert_eq n, listed.size
37
+ # all real actions; missing ones only from modules (registered on init)
38
+ # and custom.rb (from custom_example.rb, e.g. the getnums converter)
39
+ live = vma.actions.dotted_ids.map(&:to_s)
40
+ assert_eq [], listed - live, "listed but not actions"
41
+ extra = (Dir[File.expand_path("../modules/*/*.rb", __dir__)] + [File.expand_path("../custom_example.rb", __dir__), get_dot_path("custom.rb")])
42
+ .select { |f| File.exist?(f) }.map { |f| File.read(f) }.join
43
+ missing = (live - listed).reject { |id| extra.include?(id) || extra.include?(":#{id.sub("sel.convert.", "")})") || id.include?("zz_") }
44
+ assert missing.empty?, "actions missing from --help: #{missing.inspect}"
45
+ assert !out.include?("Init_vmaext\n" * 2)
46
+ end
47
+
48
+ def test_short_option
49
+ skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
50
+ out, st, = run_help("-h")
51
+ assert st.success?
52
+ assert out.include?("Usage: vimamsa")
53
+ end
54
+
55
+ # The list is the same as in the running editor, apart from what modules
56
+ # and custom.rb add
57
+ def test_action_lines_format
58
+ lines = Vimamsa.cli_action_lines(vma.actions)
59
+ assert lines.all? { |l| l.start_with?(" ") }
60
+ ids = lines.map { |l| l.split[0] }
61
+ assert_eq ids.sort, ids
62
+ assert ids.include?("buf.save")
63
+ end
64
+ end
@@ -68,9 +68,9 @@ class TestColorHighlight < VmaTest
68
68
  def test_toggle_action
69
69
  prev = cnf.modules.color_highlight.enabled?
70
70
  cnf.modules.color_highlight.enabled = true
71
- act :toggle_highlight_colors
71
+ act "color_highlight.toggle"
72
72
  assert_eq false, cnf.modules.color_highlight.enabled?
73
- act :toggle_highlight_colors
73
+ act "color_highlight.toggle"
74
74
  assert_eq true, cnf.modules.color_highlight.enabled?
75
75
  ensure
76
76
  cnf.modules.color_highlight.enabled = prev
@@ -69,7 +69,7 @@ class TestCommandLine < VmaTest
69
69
  end
70
70
 
71
71
  def test_open_and_close
72
- act :start_cmd_line
72
+ act "mode.cmdline"
73
73
  stack = vma.gui.instance_variable_get(:@minibuf_stack)
74
74
  assert_eq "cmdline", stack.visible_child_name, "command line shown"
75
75
  cl.close
@@ -58,6 +58,24 @@ class TestContextMenuFile < VmaTest
58
58
  end
59
59
  end
60
60
 
61
+ # ⟦help:keybindings⟧ opened from the context menu shows the key bindings,
62
+ # like opening it with the keyboard does
63
+ def test_help_link_opens_from_menu
64
+ with_menu("⟦help:keybindings⟧") do |_b, labels, _dir|
65
+ assert labels.include?("Open link"), labels.inspect
66
+ called = nil
67
+ orig = Vimamsa.instance_method(:call_action)
68
+ Vimamsa.send(:define_method, :call_action) { |id, *a| called = id }
69
+ begin
70
+ vma.gui.app.lookup_action("ctx_open_link").activate(nil)
71
+ drain_idle
72
+ ensure
73
+ Vimamsa.send(:define_method, :call_action, orig)
74
+ end
75
+ assert_eq "help.keys", called
76
+ end
77
+ end
78
+
61
79
  def test_no_item_for_missing_file
62
80
  with_menu("missing.pdf") do |_b, labels, _dir|
63
81
  assert !labels.any? { |l| l.start_with?("Open file") }, labels.inspect
@@ -24,56 +24,56 @@ class TestCopyPaste < VmaTest
24
24
 
25
25
  def test_copy_line_paste_after
26
26
  act 'buf.insert_txt("hello\n")'
27
- act :jump_to_start_of_buffer
28
- act :copy_cur_line
29
- act :jump_to_end_of_buffer
30
- act :paste_after_cursor
27
+ act "move.buf.start"
28
+ act "edit.line.copy"
29
+ act "move.buf.end"
30
+ act "edit.paste.after"
31
31
  assert_buf "hello\n\nhello\n"
32
32
  end
33
33
 
34
34
  def test_copy_line_paste_before
35
35
  act 'buf.insert_txt("hello\n")'
36
36
  act 'buf.insert_txt("world")'
37
- act :jump_to_start_of_buffer
38
- act :copy_cur_line
37
+ act "move.buf.start"
38
+ act "edit.line.copy"
39
39
  act "buf.move(FORWARD_LINE)"
40
- act :paste_before_cursor
40
+ act "edit.paste.before"
41
41
  assert_buf "hello\nhello\nworld\n"
42
42
  end
43
43
 
44
44
  def test_copy_paste_twice
45
45
  act 'buf.insert_txt("abc")'
46
- act :jump_to_start_of_buffer
47
- act :copy_cur_line
48
- act :jump_to_end_of_buffer
49
- act :paste_after_cursor
50
- act :paste_after_cursor
46
+ act "move.buf.start"
47
+ act "edit.line.copy"
48
+ act "move.buf.end"
49
+ act "edit.paste.after"
50
+ act "edit.paste.after"
51
51
  assert_buf "abc\nabc\nabc\n"
52
52
  end
53
53
 
54
54
  def test_cut_selection_paste
55
55
  act 'buf.insert_txt("hello world")'
56
- act :jump_to_start_of_buffer
56
+ act "move.buf.start"
57
57
  # Select "hello" (5 chars)
58
58
  act "buf.start_selection"
59
59
  4.times { act "buf.move(FORWARD_CHAR)" }
60
- act :cut_selection
60
+ act "sel.cut"
61
61
  assert_buf " world\n"
62
62
  act "buf.jump(END_OF_LINE)"
63
- act :paste_after_cursor
63
+ act "edit.paste.after"
64
64
  assert_buf " worldhello\n"
65
65
  end
66
66
 
67
67
  def test_copy_selection_paste
68
68
  act 'buf.insert_txt("foo bar")'
69
- act :jump_to_start_of_buffer
69
+ act "move.buf.start"
70
70
  act "buf.start_selection"
71
71
  2.times { act "buf.move(FORWARD_CHAR)" }
72
- act :copy_selection
72
+ act "sel.copy"
73
73
  # Original buffer unchanged
74
74
  assert_buf "foo bar\n"
75
75
  act "buf.jump(END_OF_LINE)"
76
- act :paste_after_cursor
76
+ act "edit.paste.after"
77
77
  assert_buf "foo barfoo\n"
78
78
  end
79
79
 
@@ -84,26 +84,26 @@ class TestCopyPaste < VmaTest
84
84
 
85
85
  def test_copy_line_updates_clipboard
86
86
  act 'buf.insert_txt("myline")'
87
- act :jump_to_start_of_buffer
88
- act :copy_cur_line
87
+ act "move.buf.start"
88
+ act "edit.line.copy"
89
89
  assert_eq "myline\n", vma.clipboard.get
90
90
  end
91
91
 
92
92
  def test_cut_selection_updates_clipboard
93
93
  act 'buf.insert_txt("hello")'
94
- act :jump_to_start_of_buffer
94
+ act "move.buf.start"
95
95
  act "buf.start_selection"
96
96
  2.times { act "buf.move(FORWARD_CHAR)" }
97
- act :cut_selection
97
+ act "sel.cut"
98
98
  assert_eq "hel", vma.clipboard.get
99
99
  end
100
100
 
101
101
  def test_paste_multiline
102
102
  act 'buf.insert_txt("line1\nline2\nline3")'
103
- act :jump_to_start_of_buffer
104
- act :copy_cur_line
105
- act :jump_to_end_of_buffer
106
- act :paste_after_cursor
103
+ act "move.buf.start"
104
+ act "edit.line.copy"
105
+ act "move.buf.end"
106
+ act "edit.paste.after"
107
107
  assert_buf "line1\nline2\nline3\nline1\n"
108
108
  end
109
109
 
@@ -116,20 +116,20 @@ class TestCopyPaste < VmaTest
116
116
 
117
117
  def test_async_paste_inserts_at_captured_position
118
118
  act 'buf.insert_txt("line one\nline two\n")'
119
- act :jump_to_start_of_buffer
119
+ act "move.buf.start"
120
120
  ipos = buf.pos # where the user pressed paste
121
121
  vma.clipboard << "X"
122
- act :jump_to_end_of_buffer # cursor moves away during the async read
122
+ act "move.buf.end" # cursor moves away during the async read
123
123
  buf.paste_finish("X", AFTER, nil, ipos: ipos)
124
124
  assert_buf "lXine one\nline two\n\n"
125
125
  end
126
126
 
127
127
  def test_async_paste_line_mode_uses_captured_state
128
128
  act 'buf.insert_txt("AAA\nBBB\nCCC\n")'
129
- act :jump_to_start_of_buffer
130
- act :copy_cur_line # clipboard = "AAA\n", @paste_lines = true
129
+ act "move.buf.start"
130
+ act "edit.line.copy" # clipboard = "AAA\n", @paste_lines = true
131
131
  ipos = buf.pos
132
- act :jump_to_end_of_buffer # cursor moves to the last line
132
+ act "move.buf.end" # cursor moves to the last line
133
133
  buf.paste_finish("AAA\n", AFTER, nil, ipos: ipos, paste_lines: true)
134
134
  assert_buf "AAA\nAAA\nBBB\nCCC\n\n"
135
135
  end
@@ -138,7 +138,7 @@ class TestCopyPaste < VmaTest
138
138
  # used, preserving prior behavior.
139
139
  def test_paste_finish_without_capture_uses_live_cursor
140
140
  act 'buf.insert_txt("line one\nline two\n")'
141
- act :jump_to_start_of_buffer
141
+ act "move.buf.start"
142
142
  vma.clipboard << "X"
143
143
  buf.paste_finish("X", AFTER, nil)
144
144
  assert_buf "lXine one\nline two\n\n"
@@ -151,7 +151,7 @@ class TestCopyPaste < VmaTest
151
151
  act 'buf.insert_txt("AAA\nBBB\nCCC\n")'
152
152
  act "buf.set_pos(8)" # start of "CCC"
153
153
  act "buf.mark_current_position('a')"
154
- act :jump_to_start_of_buffer # cursor back on line 0
154
+ act "move.buf.start" # cursor back on line 0
155
155
  act "buf.copy(:to_mark, 'a')"
156
156
  assert_eq "\nBBB\nC", vma.clipboard.get
157
157
  assert_buf "AAA\nBBB\nCCC\n\n" # buffer unchanged by a copy