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
@@ -30,7 +30,7 @@ class TestCustomTwoPhase < VmaTest
30
30
  end
31
31
 
32
32
  def test_phase1_settings_reached_module_init
33
- assert_eq ["fexp d d"], paths_of(:fexp_cut_file),
33
+ assert_eq ["fexp d d"], paths_of("fexp.cut_file"),
34
34
  "cnf.fexp.experimental from the body of custom.rb should reach FileManager.init"
35
35
  end
36
36
 
@@ -0,0 +1,301 @@
1
+ # Help ▸ Play demo: the README demo steps played inside the editor
2
+ # (demo_player.rb, scripts/demo/demo_steps.txt)
3
+ class TestDemoPlayer < VmaTest
4
+ SHAPES = File.join(DemoPlayer::DIR, "shapes.rb")
5
+
6
+ def wait_until_done(player, secs = 60)
7
+ wait_for(secs) { !player.running? }
8
+ assert !player.running?, "demo still running after #{secs} s"
9
+ end
10
+
11
+ # Runs the main loop until the block is true or secs pass; the block's value
12
+ def wait_for(secs)
13
+ t = Time.now
14
+ until (ok = yield) || Time.now - t > secs
15
+ drain_idle
16
+ sleep 0.005
17
+ end
18
+ ok
19
+ end
20
+
21
+ # Runs the main loop for secs
22
+ def idle_for(secs)
23
+ wait_for(secs) { false }
24
+ end
25
+
26
+ # A short demo: after a wait, x deletes the first character of the file;
27
+ # then the closing wait, if any
28
+ def short_player(wait, closing = nil, **opts)
29
+ steps = [["wait", wait.to_s], ["keys", "x"]]
30
+ steps << ["wait", closing.to_s] if closing
31
+ # on the easy jump demo's file (scripts/demo/shapes.rb, as original)
32
+ DemoPlayer.new(:easyjump, speed: 1, steps: steps, **opts)
33
+ end
34
+
35
+ def original
36
+ File.read(SHAPES)
37
+ end
38
+
39
+ def test_steps_parse
40
+ steps = DemoPlayer.parse(File.read(DemoPlayer::STEPS))
41
+ assert steps.any? { |c, a| c == "keys" && a.include?("@JUMP_LABEL@") }
42
+ assert steps.any? { |c, _| c == "target" }, "no target line for the easy jump"
43
+ assert steps.any? { |c, a| c == "type" && a.start_with?("puts ") }
44
+ end
45
+
46
+ # The basic demo (square/steps.txt), fast: it plays to the end and turns
47
+ # Circle into a Square class with a width (search and replace in a form,
48
+ # the action search, easy jumps), back in Command mode
49
+ # (Not faster: at 50x an easy jump can come before the view has scrolled
50
+ # to its target, which then has no label.)
51
+ def test_plays_whole_demo
52
+ # its action searches find the same action whatever else is registered
53
+ assert_eq "sel.convert.remove_empty_lines", vma.actions.search_actions_update_callback("sel.convert.remempty")[0][1]
54
+ assert_eq "sel.convert.eval", vma.actions.search_actions_update_callback("sel.convert.eval")[0][1]
55
+ p = DemoPlayer.new(speed: 3, loop: false)
56
+ p.start
57
+ wait_until_done(p, 300)
58
+ assert_eq "Demo finished", p.stop_message
59
+ t = p.buf.to_s
60
+ assert t.include?("class Square < Shape"), t
61
+ assert t.include?("@width**2"), t
62
+ # the action search ran the eval converter on the whole file
63
+ assert t.end_with?("[3.141592653589793, 1]\n\n") || t.include?("[3.141592653589793, 1]"), t
64
+ assert_mode :command
65
+ ensure
66
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
67
+ end
68
+
69
+ # The easy jump demo moves Shape#to_s above area, with v + easy jump to
70
+ # select it, x and P
71
+ def test_easyjump_demo_moves_to_s
72
+ p = DemoPlayer.new(:easyjump, speed: 50, loop: false)
73
+ p.start
74
+ wait_until_done(p)
75
+ l = original.lines
76
+ want = l[0..4] + ["\n"] + l[10..12] + ["\n"] + l[6..8] + l[13..]
77
+ assert_eq want.join, p.buf.to_s
78
+ assert_mode :command
79
+ ensure
80
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
81
+ end
82
+
83
+ # The file switching demo: tab, browse mode h / l and the file explorer
84
+ # visit every file and end on shapes.rb, unchanged, at the top
85
+ def test_files_demo_switches_files
86
+ p = DemoPlayer.new(:files, speed: 20, loop: false)
87
+ p.start
88
+ seen = []
89
+ t = Time.now
90
+ while p.running? && Time.now - t < 60
91
+ seen << File.basename(vma.buf.fname.to_s)
92
+ drain_idle
93
+ sleep 0.005
94
+ end
95
+ assert !p.running?, "demo still running"
96
+ order = seen.chunk_while { |a, b| a == b }.map(&:first)
97
+ assert_eq "Demo finished", p.stop_message, "#{p.stop_message}; buffers in order: #{order.inspect}, log: #{vma.gui.keylog_panel.entries.last(4).map { |e| e[:chord] || e[:text] }.inspect}"
98
+ # "": the file explorer's buffer
99
+ assert_eq ["", "notes.txt", "report.rb", "shapes.rb"], seen.uniq.sort
100
+ assert_eq "shapes.rb", File.basename(vma.buf.fname.to_s)
101
+ assert_eq File.read(SHAPES), vma.buf.to_s
102
+ assert_eq 0, vma.buf.pos
103
+ assert vma.buffers.list.none? { |b| b.module.is_a?(FileManager) rescue false }, "file explorer still open"
104
+ ensure
105
+ p&.bufs&.each { |b| vma.buffers.close_buffer(b.id) }
106
+ end
107
+
108
+ def test_easyjump_steps_parse
109
+ steps = DemoPlayer.parse(File.read(DemoPlayer::DEMOS[:easyjump][:steps]))
110
+ assert steps.count { |c, a| c == "keys" && a.include?("@JUMP_LABEL@") } >= 5
111
+ end
112
+
113
+ # Another demo from the menu stops the playing one and starts; the same
114
+ # one again stops it
115
+ def test_toggle_switches_demo
116
+ DemoPlayer.toggle(:basic)
117
+ a = DemoPlayer.current
118
+ DemoPlayer.toggle(:easyjump)
119
+ b = DemoPlayer.current
120
+ assert !a.running?
121
+ assert b.running?
122
+ assert_eq :easyjump, b.name
123
+ DemoPlayer.toggle(:easyjump)
124
+ assert !b.running?
125
+ drain_idle
126
+ ensure
127
+ [a, b].compact.each { |x| x.stop; vma.buffers.close_buffer(x.buf.id) if x.buf }
128
+ end
129
+
130
+ # The key log's close button stops the demo and hides the panel
131
+ def test_close_button_stops_demo
132
+ p = short_player(5)
133
+ p.start
134
+ panel = vma.gui.keylog_panel
135
+ assert panel.active?, "key log not shown by the demo"
136
+ panel.close_btn.signal_emit("clicked")
137
+ drain_idle
138
+ assert !p.running?, "demo still running"
139
+ assert !panel.active?, "key log still shown"
140
+ ensure
141
+ p&.stop
142
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
143
+ end
144
+
145
+ # The easy jump label is looked up for the target line in this window (a
146
+ # line near the top: the test window may not show line 16 the demo uses)
147
+ def test_jump_label_reaches_target
148
+ p = DemoPlayer.new
149
+ b = create_new_buffer(File.read(SHAPES), "demotest", true)
150
+ p.instance_variable_set(:@buf, b)
151
+ p.instance_variable_set(:@target, " def area")
152
+ b.set_pos(0)
153
+ # Let the new view get laid out: easy jump labels only what's visible
154
+ 20.times { drain_idle; sleep 0.02 }
155
+ keys("s")
156
+ ej = EasyJump.class_variable_get(:@@cur)
157
+ label = p.send(:jump_label)
158
+ marks = ej.instance_variable_get(:@easy_jump_wsmarks)
159
+ assert label != ["esc"], "no label: target line start #{b.index(" def area")}, marks #{marks.first(30).inspect}, visible #{get_visible_area.inspect}, cur buf #{vma.buf.equal?(b)}"
160
+ label.each { |c| p.send(:press, c) }
161
+ assert_eq b.index(" def area"), b.pos
162
+ ensure
163
+ vma.buffers.close_buffer(b.id) if b
164
+ end
165
+
166
+ # At the end the file goes back to how it was and the demo plays again
167
+ def test_loops_until_stopped
168
+ p = short_player(0.3, 0.3)
169
+ p.start
170
+ assert wait_for(5) { p.buf.to_s == original[1..] }, "the first round didn't delete a char"
171
+ assert wait_for(5) { p.rounds >= 1 }, "no second round"
172
+ assert p.running?
173
+ assert_eq original, p.buf.to_s
174
+ assert wait_for(5) { p.buf.to_s == original[1..] }, "the second round didn't play"
175
+ p.stop
176
+ assert !p.running?
177
+ ensure
178
+ p&.stop
179
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
180
+ end
181
+
182
+ # The key log starts empty, without the keys typed before the demo
183
+ def test_key_log_cleared_at_start
184
+ act "panel.keylog.toggle"
185
+ keys "j k"
186
+ assert vma.gui.keylog_panel.entries.size > 0
187
+ p = short_player(5, loop: false)
188
+ p.start
189
+ assert_eq [], vma.gui.keylog_panel.entries
190
+ ensure
191
+ p&.stop
192
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
193
+ act "panel.keylog.toggle" if vma.gui.keylog_panel.active?
194
+ end
195
+
196
+ # Paused, the step waits; continued, it runs. The button label follows.
197
+ def test_pause_and_continue
198
+ p = short_player(0.2, loop: false)
199
+ panel = vma.gui.keylog_panel
200
+ p.start
201
+ assert panel.demo_bar.visible?
202
+ assert_eq "Pause", panel.demo_pause_btn.label
203
+ p.toggle_pause
204
+ assert p.paused?
205
+ assert_eq "Continue", panel.demo_pause_btn.label
206
+ idle_for(0.6)
207
+ assert_eq original, p.buf.to_s, "a paused demo went on"
208
+ p.toggle_pause
209
+ assert !p.paused?
210
+ assert_eq "Pause", panel.demo_pause_btn.label
211
+ wait_until_done(p, 5)
212
+ assert_eq original[1..], p.buf.to_s
213
+ assert !panel.demo_bar.visible?, "demo controls still shown after the end"
214
+ ensure
215
+ p&.stop
216
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
217
+ end
218
+
219
+ # A demo from any steps file (scripts/demo/record_demo.rb): no controls,
220
+ # on_finish gets the stop message
221
+ def test_given_demo_without_controls
222
+ got = nil
223
+ demo = { steps: DemoPlayer::DEMOS[:easyjump][:steps], files: ["shapes.rb"], src: DemoPlayer::DIR }
224
+ p = DemoPlayer.new(:recording, demo: demo, steps: [["wait", "0.1"], ["keys", "x"]], speed: 1, loop: false,
225
+ controls: false, on_finish: proc { |m| got = m })
226
+ p.start
227
+ assert !vma.gui.keylog_panel.demo_bar.visible?, "controls shown"
228
+ wait_until_done(p, 5)
229
+ assert_eq "Demo finished", got
230
+ assert_eq original[1..], p.buf.to_s
231
+ ensure
232
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
233
+ end
234
+
235
+ # An easy jump target outside the window (a demo recorded in a bigger
236
+ # one): the cursor still ends on it
237
+ def test_jump_target_not_shown
238
+ Dir.mktmpdir("vma-demo-src") { |src|
239
+ File.write(File.join(src, "long.txt"), (1..300).map { |i| "line #{i} some words here\n" }.join)
240
+ steps = [["wait", "0.1"], ["keys", "s"], ["target", "line 200 col 6"], ["keys", "@JUMP_LABEL@"], ["keys", "x"]]
241
+ p = DemoPlayer.new(:recording, demo: { steps: nil, files: ["long.txt"], src: src }, steps: steps,
242
+ speed: 1, loop: false, controls: false)
243
+ p.start
244
+ wait_until_done(p, 10)
245
+ assert_eq "Demo finished", p.stop_message
246
+ l = p.buf.lines[199]
247
+ assert_eq "line 00 some words here\n", l, "x not at line 200 col 6"
248
+ assert_mode :command
249
+ }
250
+ ensure
251
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
252
+ end
253
+
254
+ def test_speed_steps
255
+ p = DemoPlayer.new
256
+ r = p.rate
257
+ assert DemoPlayer::RATES.include?(r), "default rate #{r} not in RATES"
258
+ p.faster
259
+ assert_eq DemoPlayer::RATES[DemoPlayer::RATES.index(r) + 1], p.rate
260
+ 8.times { p.faster }
261
+ assert_eq DemoPlayer::RATES.last, p.rate
262
+ 20.times { p.slower }
263
+ assert_eq DemoPlayer::RATES.first, p.rate
264
+ assert_eq "0.25×", DemoPlayer.rate_label(0.25)
265
+ assert_eq "2×", DemoPlayer.rate_label(2)
266
+ end
267
+
268
+ # Speed divides the waits: a 2 s wait at 4× takes 0.5 s, a 0.2 s wait at
269
+ # 0.25× takes 0.8 s (the bounds are loose for slow machines)
270
+ def test_speed_changes_waits
271
+ p = short_player(2, loop: false)
272
+ p.set_rate(4)
273
+ p.start
274
+ assert_eq "4×", vma.gui.keylog_panel.demo_speed_lbl.label
275
+ assert wait_for(1.5) { !p.running? }, "a 2 s wait at 4× took over 1.5 s"
276
+ vma.buffers.close_buffer(p.buf.id)
277
+
278
+ p = short_player(0.2, loop: false)
279
+ p.set_rate(0.25)
280
+ p.start
281
+ idle_for(0.4)
282
+ assert p.running?, "a 0.2 s wait at 0.25× took under 0.4 s"
283
+ wait_until_done(p, 5)
284
+ ensure
285
+ p&.stop
286
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
287
+ end
288
+
289
+ def test_toggle_stops
290
+ DemoPlayer.toggle
291
+ p = DemoPlayer.current
292
+ assert p.running?
293
+ assert vma.gui.keylog_panel.demo_bar.visible?
294
+ DemoPlayer.toggle
295
+ assert !p.running?
296
+ assert !vma.gui.keylog_panel.demo_bar.visible?
297
+ drain_idle
298
+ ensure
299
+ vma.buffers.close_buffer(p.buf.id) if p&.buf
300
+ end
301
+ end
@@ -0,0 +1,202 @@
1
+ # Recording demos (demo_recorder.rb, doc/demo_recording_plan.md part 2):
2
+ # keys into steps, and a recorded demo played back (DemoPlayer user demos)
3
+ class TestDemoRecorder < VmaTest
4
+ K = DemoRecorder::Key
5
+
6
+ def lines(keys, end_line: 0)
7
+ DemoRecorder.steps(keys, end_line: end_line).lines.map(&:chomp).reject { |l| l.start_with?("#") }
8
+ end
9
+
10
+ def wait_until(secs = 60)
11
+ t = Time.now
12
+ until yield || Time.now - t > secs
13
+ drain_idle
14
+ sleep 0.005
15
+ end
16
+ yield
17
+ end
18
+
19
+ # delay from the typical gap, wait for a pause, type for Insert-mode typing
20
+ def test_steps_from_keys
21
+ ins = "a.edit.insert.char!('%s')"
22
+ keys = [
23
+ K.new(t: 0.0, key: "j", mode: :command, action: "move.line.next"),
24
+ K.new(t: 0.4, key: "j", mode: :command, action: "move.line.next"),
25
+ K.new(t: 3.0, key: "i", mode: :command, action: "mode.insert"),
26
+ K.new(t: 3.4, key: "h", mode: :insert, action: ins % "h"),
27
+ K.new(t: 3.8, key: "i", mode: :insert, action: ins % "i"),
28
+ K.new(t: 4.2, key: "esc", mode: :insert, action: "mode.prev"),
29
+ ]
30
+ assert_eq ["delay 0.4", "wait 1", "keys j j", "wait 2.2", "keys i", "type hi", "keys esc"], lines(keys)
31
+ end
32
+
33
+ def test_long_pause_capped
34
+ keys = [K.new(t: 0.0, key: "j", mode: :command, action: "x"), K.new(t: 30.0, key: "k", mode: :command, action: "x")]
35
+ assert lines(keys).include?("wait 3"), lines(keys).inspect
36
+ end
37
+
38
+ # Leading spaces of typed text go in a keys line ("type " would lose them)
39
+ def test_typed_leading_space
40
+ keys = [" ", "a"].each_with_index.map { |c, i|
41
+ K.new(t: i * 0.3, key: c == " " ? "space" : c, mode: :insert, action: c == " " ? "edit.insert.space" : "a.edit.insert.char!('a')")
42
+ }
43
+ assert_eq ["keys space", "type a"], lines(keys).last(2)
44
+ end
45
+
46
+ # An easy jump's label keys become the target line and @JUMP_LABEL@
47
+ def test_easy_jump_label
48
+ keys = [
49
+ K.new(t: 0.0, key: "s", mode: :command, action: "jump.easy", line: 0),
50
+ K.new(t: 0.4, key: "a", mode: :command, action: nil, line: 0, read: true),
51
+ K.new(t: 0.8, key: "b", mode: :command, action: nil, line: 0, read: true),
52
+ K.new(t: 1.2, key: "d", mode: :command, action: nil, line: 7, col: 12),
53
+ K.new(t: 1.4, key: "d", mode: :command, action: "edit.delete.line", line: 7),
54
+ ]
55
+ l = lines(keys)
56
+ i = l.index("keys s")
57
+ assert i, l.inspect
58
+ # the d of d d has no action, but isn't a label key
59
+ assert_eq ["target line 8 col 13", "keys @JUMP_LABEL@", "keys d d"], l[i + 1, 3]
60
+ end
61
+
62
+ # ctrl alone is a key ("ctrl!"), ctrl held for ctrl-r is not
63
+ def test_bare_modifier
64
+ r = DemoRecorder.new
65
+ r.instance_variable_set(:@recording, true)
66
+ r.instance_variable_set(:@t0, 0)
67
+ r.key_input("ctrl", :key_press)
68
+ r.key_input("ctrl!", :key_release)
69
+ r.key_input("ctrl", :key_press)
70
+ r.key_input("ctrl-r", :key_press)
71
+ r.key_input("j", :key_press)
72
+ r.key_input("j!", :key_release)
73
+ assert_eq ["ctrl", "ctrl-r", "j"], r.keys.map(&:key)
74
+ end
75
+
76
+ # Record real keys (an edit and , r r with typing in the form), name it in
77
+ # the save form, play it back: the same text
78
+ def test_record_save_and_play_back
79
+ b = create_new_buffer("one two one\nline two\n", "rectest")
80
+ rec = DemoRecorder.new
81
+ DemoRecorder.current = rec
82
+ rec.start
83
+ keys "j d d"
84
+ keys ", r r o n e tab 1 enter"
85
+ want = b.to_s.dup
86
+ assert_eq "1 two 1\n", want
87
+ rec.stop
88
+ assert FormInput.current, "no name form"
89
+ keys "ctrl-a r t enter"
90
+ dir = File.join(DemoPlayer.user_demos_dir, "rt")
91
+ assert File.exist?(File.join(dir, "steps.txt")), "not saved"
92
+ steps = File.read(File.join(dir, "steps.txt"))
93
+ assert steps.include?("type one"), steps
94
+ assert_eq "one two one\nline two\n", File.read(File.join(dir, "demo.txt")), "start file"
95
+ assert_eq :user_rt, DemoRecorder.last_saved
96
+ assert DemoPlayer.demos.key?(:user_rt)
97
+ assert vma.actions.include?("help.demo.user.rt")
98
+
99
+ p = DemoPlayer.new(:user_rt, speed: 50, loop: false)
100
+ p.start
101
+ assert wait_until { !p.running? }, "demo still running"
102
+ assert_eq "Demo finished", p.stop_message, steps
103
+ assert_eq want, p.buf.to_s, steps
104
+ ensure
105
+ DemoRecorder.current = nil
106
+ FormInput.current&.cancel
107
+ drain_idle
108
+ p&.bufs&.each { |x| vma.buffers.close_buffer(x.id) }
109
+ FileUtils.rm_rf(DemoPlayer.user_demos_dir)
110
+ end
111
+
112
+ # An easy jump to a word inside a line (s + a label), then d w: all keys
113
+ # play back, at the same character (the d, which has no action, used to be
114
+ # taken for a label key)
115
+ def test_record_dd_then_easy_jump
116
+ text = (1..12).map { |i| "line number #{i} with words\n" }.join
117
+ b = create_new_buffer(text, "rectest")
118
+ # easy jump labels only what is shown: wait until the view is laid out
119
+ assert wait_until(10) { (a = get_visible_area) && a[1] - a[0] > 100 }, "view not laid out: #{get_visible_area.inspect}"
120
+ rec = DemoRecorder.new
121
+ DemoRecorder.current = rec
122
+ rec.start
123
+ keys "s"
124
+ ej = EasyJump.class_variable_get(:@@cur)
125
+ # a labelled word inside line 6, not its start
126
+ ls = b.index("line number 6")
127
+ marks = ej.instance_variable_get(:@easy_jump_wsmarks)
128
+ target = marks.select { |m| m > ls && m < b.index("\n", ls) }.min
129
+ assert target, "no labelled word inside line 6: #{marks.sort.inspect}"
130
+ n = marks.index(target)
131
+ label = ej.instance_variable_get(:@jump_sequence)[n].downcase.chars
132
+ keys label.join(" ")
133
+ assert_eq target, b.pos, "jump"
134
+ keys "d w"
135
+ keys "x"
136
+ want = b.to_s.dup
137
+ rec.stop(save: false)
138
+ steps = rec.steps_text(file: "demo.txt")
139
+ assert steps.include?("keys d w"), steps
140
+ col = target - ls + 1
141
+ assert steps.include?("target line 6 col #{col}"), steps
142
+ rec.save("ddjump")
143
+ p = DemoPlayer.new(:user_ddjump, speed: 50, loop: false)
144
+ p.start
145
+ assert wait_until { !p.running? }, "demo still running"
146
+ assert_eq want, p.buf.to_s, steps
147
+ ensure
148
+ vma.kbd.remove_keyhandling_override # easy jump left reading keys
149
+ vma.gui.clear_overlay rescue nil
150
+ vma.kbd.set_mode(:command)
151
+ DemoRecorder.current = nil
152
+ p&.bufs&.each { |x| vma.buffers.close_buffer(x.id) }
153
+ FileUtils.rm_rf(DemoPlayer.user_demos_dir)
154
+ end
155
+
156
+ # The action search (a list window): select lines, , , s, type a fuzzy
157
+ # name, enter. It is recorded (form mode) and plays back.
158
+ def test_record_action_search
159
+ b = create_new_buffer("a\n\nb\n\nc\n", "rectest")
160
+ rec = DemoRecorder.new
161
+ DemoRecorder.current = rec
162
+ rec.start
163
+ keys "v j j j"
164
+ keys ", , s"
165
+ assert FormInput.current, "action search not in form mode"
166
+ keys "r e m e m p t y l i n e s"
167
+ keys "enter"
168
+ assert FormInput.current.nil?, "action search still open"
169
+ want = b.to_s.dup
170
+ assert_eq "a\nb\nc\n", want
171
+ rec.stop(save: false)
172
+ steps = rec.steps_text(file: "demo.txt")
173
+ assert steps.include?("type rememptylines"), steps
174
+ assert steps.include?("keys enter"), steps
175
+ rec.save("search")
176
+ p = DemoPlayer.new(:user_search, speed: 50, loop: false)
177
+ p.start
178
+ assert wait_until { !p.running? }, "demo still running"
179
+ assert_eq want, p.buf.to_s, steps
180
+ ensure
181
+ FormInput.current&.cancel
182
+ vma.kbd.set_mode(:command)
183
+ DemoRecorder.current = nil
184
+ p&.bufs&.each { |x| vma.buffers.close_buffer(x.id) }
185
+ FileUtils.rm_rf(DemoPlayer.user_demos_dir)
186
+ end
187
+
188
+ # The stop command's own keys aren't in the demo
189
+ def test_stop_keys_dropped
190
+ rec = DemoRecorder.new
191
+ DemoRecorder.current = rec
192
+ rec.start
193
+ keys "j"
194
+ rec.key_input(",", :key_press)
195
+ rec.key_input("x", :key_press)
196
+ rec.key_action("help.demo.record")
197
+ rec.stop(save: false)
198
+ assert_eq ["j"], rec.keys.map(&:key)
199
+ ensure
200
+ DemoRecorder.current = nil
201
+ end
202
+ end
@@ -5,7 +5,7 @@ class TestDictation < VmaTest
5
5
  end
6
6
 
7
7
  def ensure_disabled
8
- dictation_disable if vma.actions.include?(:dictation_toggle)
8
+ dictation_disable if vma.actions.include?("dictation.toggle")
9
9
  end
10
10
 
11
11
  # --- _info ---
@@ -23,8 +23,8 @@ class TestDictation < VmaTest
23
23
  ensure_disabled
24
24
  load_dictation
25
25
  dictation_init
26
- assert vma.actions.include?(:dictation_toggle), "action not registered after init"
27
- assert vma.gui.menu.module_action?(:dictation_enter_mode), "menu item missing after init"
26
+ assert vma.actions.include?("dictation.toggle"), "action not registered after init"
27
+ assert vma.gui.menu.module_action?("dictation.enter_mode"), "menu item missing after init"
28
28
  ensure
29
29
  dictation_disable
30
30
  end
@@ -34,7 +34,7 @@ class TestDictation < VmaTest
34
34
  ensure_disabled
35
35
  load_dictation
36
36
  dictation_init
37
- hint = vma.gui.menu.kbd_hint(:dictation_enter_mode)
37
+ hint = vma.gui.menu.kbd_hint("dictation.enter_mode")
38
38
  assert hint.include?("[C]</span> , k"), "no , k hint: #{hint.inspect}"
39
39
  ensure
40
40
  dictation_disable
@@ -45,8 +45,8 @@ class TestDictation < VmaTest
45
45
  load_dictation
46
46
  dictation_init
47
47
  dictation_disable
48
- assert !vma.actions.include?(:dictation_toggle), "action still registered after disable"
49
- assert !vma.gui.menu.module_action?(:dictation_enter_mode), "menu item still present after disable"
48
+ assert !vma.actions.include?("dictation.toggle"), "action still registered after disable"
49
+ assert !vma.gui.menu.module_action?("dictation.enter_mode"), "menu item still present after disable"
50
50
  end
51
51
 
52
52
  def test_init_disable_cycle
@@ -54,9 +54,9 @@ class TestDictation < VmaTest
54
54
  load_dictation
55
55
  3.times do |i|
56
56
  dictation_init
57
- assert vma.actions.include?(:dictation_toggle), "action missing after init (cycle #{i})"
57
+ assert vma.actions.include?("dictation.toggle"), "action missing after init (cycle #{i})"
58
58
  dictation_disable
59
- assert !vma.actions.include?(:dictation_toggle), "action present after disable (cycle #{i})"
59
+ assert !vma.actions.include?("dictation.toggle"), "action present after disable (cycle #{i})"
60
60
  end
61
61
  end
62
62
 
@@ -196,7 +196,7 @@ class TestDictation < VmaTest
196
196
  elapsed = Time.now - t0
197
197
 
198
198
  assert_eq false, res[:ok], "transcribe should fail when the model never loads"
199
- assert res[:error].to_s.include?("not loaded"), "unexpected error: #{res[:error].inspect}"
199
+ assert res[:error].to_s.include?("no progress"), "unexpected error: #{res[:error].inspect}"
200
200
  assert elapsed < 10, "transcribe blocked #{elapsed.round(1)}s; should give up after the timeout"
201
201
  ensure
202
202
  cnf.dictation.startup_timeout = prev
@@ -232,18 +232,18 @@ class TestDictation < VmaTest
232
232
  ensure_disabled
233
233
  load_dictation
234
234
  dictation_init
235
- [:dictation_enter_mode, :dictation_toggle_stay,
236
- :dictation_newline, :dictation_exit_mode].each do |a|
235
+ ["dictation.enter_mode", "dictation.toggle_stay",
236
+ "dictation.newline", "dictation.exit_mode"].each do |a|
237
237
  assert vma.actions.include?(a), "#{a} not registered after init"
238
238
  end
239
239
  dictation_disable
240
- [:dictation_enter_mode, :dictation_toggle_stay,
241
- :dictation_newline, :dictation_exit_mode].each do |a|
240
+ ["dictation.enter_mode", "dictation.toggle_stay",
241
+ "dictation.newline", "dictation.exit_mode"].each do |a|
242
242
  assert !vma.actions.include?(a), "#{a} still registered after disable"
243
243
  end
244
244
  end
245
245
 
246
- # The menu item runs :dictation_enter_mode; clicked while already in the
246
+ # The menu item runs "dictation.enter_mode"; clicked while already in the
247
247
  # mode it leaves the mode instead (session not active: no recorder starts).
248
248
  def test_enter_mode_action_exits_when_in_mode
249
249
  ensure_disabled
@@ -251,7 +251,7 @@ class TestDictation < VmaTest
251
251
  dictation_init
252
252
  vma.kbd.set_mode(:dictation)
253
253
  assert_eq :dictation, vma.kbd.get_mode
254
- act(:dictation_enter_mode)
254
+ act("dictation.enter_mode")
255
255
  assert_eq :command, vma.kbd.get_mode, "menu toggle did not leave dictation mode"
256
256
  ensure
257
257
  vma.kbd.set_mode(:command)
@@ -286,7 +286,7 @@ class TestDictation < VmaTest
286
286
  act("buf.insert_txt_at('abc', 0)") # fresh buffer "\n" -> "abc\n"
287
287
  act("buf.set_pos(3)") # end of "abc", before the trailing "\n"
288
288
  assert !dictation_session.active?, "precondition: no active dictation"
289
- act(:dictation_newline)
289
+ act("dictation.newline")
290
290
  assert_buf "abc\n\n", "Enter should insert a newline when not dictating"
291
291
  ensure
292
292
  dictation_disable