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
@@ -86,6 +86,107 @@ class TestVimBindings < VmaTest
86
86
  assert_matches_vim("foo bar\n", "wgUUx") # cursor to line start
87
87
  end
88
88
 
89
+ # The operator + motion layer (vim_operators.rb): every operator with
90
+ # every motion, counts in both places
91
+ def test_operator_counts
92
+ assert_matches_vim("a b c d e f g\n", "d2w")
93
+ assert_matches_vim("a b c d e f g\n", "2dw")
94
+ assert_matches_vim("a b c d e f g\n", "2d2w")
95
+ assert_matches_vim("a\nb\nc\nd\ne\n", "d2j")
96
+ assert_matches_vim("a\nb\nc\nd\ne\n", "3dd")
97
+ assert_matches_vim("a\nb\nc\n", "5dd") # more lines than left: no-op
98
+ assert_matches_vim("a\nb\nc\n", "j2dd")
99
+ end
100
+
101
+ def test_operator_word_motions
102
+ assert_matches_vim("foo.bar baz\n", "dW")
103
+ assert_matches_vim("foo.bar baz\n", "dE")
104
+ assert_matches_vim("foo bar.baz\n", "$dB")
105
+ assert_matches_vim("foo bar baz\n", "wwdb")
106
+ assert_matches_vim("foo bar\nbaz\n", "wdw") # last word: not joined
107
+ assert_matches_vim("foo bar\nbaz qux\n", "wd2w")
108
+ assert_matches_vim("foo\n\nbar\n", "dw")
109
+ assert_matches_vim("foo bar\n", "jdb")
110
+ assert_matches_vim("x\n foo\nbar\n", "jjdb")
111
+ assert_matches_vim("foo bar baz\n", "llcwX\e") # cw inside a word
112
+ assert_matches_vim("foo bar baz\n", "lllcwX\e") # cw on a blank
113
+ assert_matches_vim("a bc d\n", "c2wX\e")
114
+ assert_matches_vim("foo bar\n", "yeP")
115
+ end
116
+
117
+ def test_operator_line_motions
118
+ assert_matches_vim("x\n abc def\n", "jwd0")
119
+ assert_matches_vim("x\n abc def\n", "j$d^")
120
+ assert_matches_vim("abc def\n", "wd$")
121
+ assert_matches_vim("abc\ndef\nghi\n", "d2$")
122
+ assert_matches_vim("abcdef\n", "$dh")
123
+ assert_matches_vim("abcdef\n", "$dl")
124
+ assert_matches_vim("abcdef\n", "d3l")
125
+ end
126
+
127
+ def test_operator_find_till
128
+ assert_matches_vim("foo bar baz\n", "dtb")
129
+ assert_matches_vim("foo bar baz\n", "d2fa")
130
+ assert_matches_vim("foo bar baz\n", "$dTo")
131
+ assert_matches_vim("foo bar baz\n", "$dF ")
132
+ assert_matches_vim("foo bar baz\n", "dt ")
133
+ assert_matches_vim("foo bar baz\n", "cfrX\e")
134
+ assert_matches_vim("foo bar baz\n", "gUfr")
135
+ end
136
+
137
+ def test_operator_linewise_motions
138
+ assert_matches_vim("a\nb\nc\nd\n", "jdk")
139
+ assert_matches_vim("a\nb\nc\nd\n", "jdG")
140
+ assert_matches_vim("a\nb\nc\nd\n", "jjdgg")
141
+ assert_matches_vim("a\nb\nc\nd\n", "d3G")
142
+ assert_matches_vim("a\nb\nc\n", "yjGp")
143
+ assert_matches_vim("a\nb\nc\n", "jcjX\e")
144
+ assert_matches_vim("a\nb\nc\n", "Gdj") # can't move: no-op
145
+ end
146
+
147
+ def test_indent_operators
148
+ assert_matches_vim("a\nb\nc\n", ">>")
149
+ assert_matches_vim("a\nb\nc\n", "3>>")
150
+ assert_matches_vim("a\n\nc\n", ">j")
151
+ assert_matches_vim("a\n\nc\n", ">2j") # empty lines stay empty
152
+ assert_matches_vim("\ta\n\tb\n", "<j")
153
+ assert_matches_vim(" a\nb\n", "<<")
154
+ assert_matches_vim("a b\nc\n", ">w") # > always works on lines
155
+ end
156
+
157
+ def test_operator_text_objects_and_case
158
+ assert_matches_vim("foo (bar baz) x\n", "fbd2w")
159
+ assert_matches_vim("foo (bar baz) x\n", "fb>i(")
160
+ assert_matches_vim("foo bar\nbaz\n", "g~j")
161
+ assert_matches_vim("foo bar\n", "gUiw")
162
+ assert_matches_vim("Foo Bar\n", "gu$")
163
+ assert_matches_vim("foo bar\n", "wgUb")
164
+ end
165
+
166
+ def test_plain_motions_from_the_layer
167
+ assert_matches_vim("foo.bar baz\n", "Wix\e")
168
+ assert_matches_vim("foo.bar baz\n", "Eix\e")
169
+ assert_matches_vim("foo bar.baz\n", "$Bix\e")
170
+ assert_matches_vim("foo bar baz\n", "tzix\e")
171
+ assert_matches_vim("foo bar baz\n", "$Tfix\e")
172
+ assert_matches_vim("abc\n", "$ix\e") # $ on the last character
173
+ end
174
+
175
+ # "." repeats the last change (dot_repeat.rb)
176
+ def test_dot_repeat
177
+ assert_matches_vim("a b c d e\n", "dw.")
178
+ assert_matches_vim("a b c d e\n", "dw2.")
179
+ assert_matches_vim("one two three\n", "cwfoo\ew.")
180
+ assert_matches_vim("ab\n", "ixy\e0.") # (vim's esc also moves left; vimamsa's doesn't)
181
+ assert_matches_vim("abcd\n", "x..")
182
+ assert_matches_vim("1\n2\n3\n4\n", "dd.")
183
+ assert_matches_vim("a\nb\n", ">>j.")
184
+ assert_matches_vim("a\nb\n", "A!\ej.")
185
+ assert_matches_vim("a\nb\n", "ox\ej.")
186
+ assert_matches_vim("foo bar\n", "gUiww.")
187
+ assert_matches_vim("a b c\n", "dwlu.") # undo doesn't replace the change
188
+ end
189
+
89
190
  def test_join
90
191
  assert_matches_vim("aa\nbb\n", "J")
91
192
  end
@@ -155,30 +256,30 @@ class TestVimBindings < VmaTest
155
256
 
156
257
  def test_zz_dispatch
157
258
  keys "z z"
158
- assert_eq :center_on_current_line, vma.kbd.cur_action
259
+ assert_eq "view.center", vma.kbd.cur_action
159
260
  end
160
261
 
161
262
  def test_ctrl_o_binding
162
- assert_eq "ctrl-o", vma.kbd.act_bindings["C"][:jump_to_last_edit]
263
+ assert_eq "ctrl-o", vma.kbd.act_bindings["C"]["jump.edit.prev"]
163
264
  end
164
265
 
165
266
  def test_backtick_jumps_to_mark
166
267
  act 'buf.insert_txt("one\ntwo\nthree\n")'
167
- act :jump_to_start_of_buffer
268
+ act "move.buf.start"
168
269
  keys "j m a G ` a"
169
270
  assert_eq 1, vma.buf.lpos
170
271
  end
171
272
 
172
273
  def test_ctrl_a_increments
173
274
  act 'buf.insert_txt("a 41 b")'
174
- act :jump_to_start_of_buffer
275
+ act "move.buf.start"
175
276
  keys "w ctrl-a"
176
277
  assert_buf "a 42 b\n"
177
278
  end
178
279
 
179
280
  def test_visual_case_ops
180
281
  act 'buf.insert_txt("abc def")'
181
- act :jump_to_start_of_buffer
282
+ act "move.buf.start"
182
283
  keys "v e U"
183
284
  assert_buf "ABC def\n"
184
285
  end
@@ -215,7 +316,7 @@ class TestVimBindings < VmaTest
215
316
  # last line, so jump to line 1 first.
216
317
  mode = NVIM == "nvim" ? ["--headless"] : ["-E", "-s", "-c", "1"]
217
318
  ok = system(NVIM, *mode, "-u", "NONE", "-i", "NONE", "-n",
218
- "-c", "set noautoindent nosmartindent",
319
+ "-c", "set noautoindent nosmartindent sw=4 ts=4",
219
320
  "-c", "normal! #{nkeys}",
220
321
  "-c", "wq!", f.path,
221
322
  out: File::NULL, err: File::NULL)
@@ -29,14 +29,14 @@ class TestVimConflicts < VmaTest
29
29
  r = row("C", "s") # vim substitute, vimlike easy_jump
30
30
  assert_eq [:conflict, :same_keys], [r[:status], r[:why]]
31
31
  r = row("C", "c c") # vimlike has no c operator
32
- assert_eq :missing, r[:status]
33
- assert_eq :shared, row("C", "d i <char>")[:status] # text objects in both
32
+ assert_eq :added, r[:status] # so it comes from VIM_BINDINGS
33
+ assert_eq :added, row("C", "d i <char>")[:status] # text objects from the shared templates
34
34
  end
35
35
 
36
36
  def test_shorter_and_prefix_conflicts
37
37
  kbd = KeyBindingTree.new(actions: ActionList.new)
38
38
  kbd.add_mode("C", :command)
39
- kbd.bindkey("C z", :start_browse_mode)
39
+ kbd.bindkey("C z", "mode.browse")
40
40
  kbd.bindkey("C , x", :foo)
41
41
  kbd.bindkey("C q <char>", :rec)
42
42
  st = ->(keys) { vim_binding_status(kbd, "C", keys.split, :vim_action) }
@@ -46,6 +46,43 @@ class TestVimConflicts < VmaTest
46
46
  assert_eq :missing, st.("t <char>")[:status]
47
47
  end
48
48
 
49
+ # Everything vimlike could take from the shared table, it took
50
+ def test_nothing_left_missing
51
+ missing = rows.select { |r| r[:status] == :missing }
52
+ assert missing.empty?, missing.map { |r| "#{r[:mode]} #{r[:keys].join(" ")}" }.inspect
53
+ end
54
+
55
+ # The live vimlike tree (the one the tests run with) has the added
56
+ # bindings, and they behave as in vim
57
+ def test_added_bindings_work_in_vimlike
58
+ assert vma.kbd.vim_added.include?(["C", ["c", "w"]]), "c w not added"
59
+ buf.set_content("foo bar baz\n")
60
+ buf.set_pos(4)
61
+ keys("D")
62
+ assert_buf "foo \n"
63
+ assert_mode :command
64
+
65
+ buf.set_content("foo bar\n")
66
+ buf.set_pos(0)
67
+ keys("c w x esc")
68
+ assert_buf "x bar\n"
69
+ assert_mode :command
70
+
71
+ buf.set_content(" foo\nbar\n")
72
+ buf.set_pos(3)
73
+ keys("S y esc")
74
+ assert_buf "y\nbar\n"
75
+ end
76
+
77
+ # Conflicting vim bindings are not loaded: vimlike's own action stays
78
+ def test_vimlike_keeps_its_own_bindings
79
+ st = vim_binding_status(vma.kbd, "C", ["s"], "edit.change.char")
80
+ assert_eq [:conflict, :same_keys], st.values_at(:status, :why)
81
+ assert !vma.kbd.vim_added.include?(["C", ["s"]])
82
+ # Adding C ctrl-f ("move.page.next") doesn't change the key the menu shows
83
+ assert_eq "pagedown", vma.kbd.act_bindings["C"]["move.page.next"]
84
+ end
85
+
49
86
  def test_loading_schemes_leaves_editor_alone
50
87
  kbd, acts = vma.kbd, vma.actions
51
88
  color = cnf.mode.command.cursor.background!
@@ -55,7 +92,7 @@ class TestVimConflicts < VmaTest
55
92
  assert vma.kbd.equal?(kbd), "vma.kbd replaced"
56
93
  assert vma.actions.equal?(acts), "vma.actions replaced"
57
94
  assert_eq "#123456", cnf.mode.command.cursor.background!
58
- assert vma.actions.include?(:show_key_bindings)
95
+ assert vma.actions.include?("help.keys")
59
96
  ensure
60
97
  cnf.mode.command.cursor.background = color
61
98
  end
@@ -0,0 +1,116 @@
1
+ # The operator + motion layer in the vimlike keymap (vim_operators.rb,
2
+ # doc/vim_compatibility_plan.md step 1). Vimlike gets every combination of
3
+ # the shared templates whose keys it doesn't use itself.
4
+ #
5
+ # CASES: [text with "|" at the cursor, vim keys, expected text, expected
6
+ # cursor offset]. The expected values come from vim 9.1 (vim -Nu NONE);
7
+ # test_cases_match_real_vim checks them again when vim is installed. The
8
+ # vim keymap has its own oracle tests in test_vim_bindings.rb.
9
+ require "tmpdir"
10
+
11
+ class TestVimOperators < VmaTest
12
+ CASES = [
13
+ ["foo b|ar baz", "cwX\e", "foo bX baz\n", 5],
14
+ ["foo bar| baz", "cwX\e", "foo barXbaz\n", 7],
15
+ ["one two three four", "d3w", "four\n", 0],
16
+ ["one two three four", "2d2w", "\n", 0],
17
+ ["foo bar", "gUtr", "FOO BAr\n", 0],
18
+ ["a.b c", "dW", "c\n", 0],
19
+ ["a\nb|\nc", ">>", "a\n\tb\nc\n", 3],
20
+ ["a\nb|\nc", ">j", "a\n\tb\n\tc\n", 3],
21
+ ["\ta\n\tb", "<j", "a\nb\n", 0],
22
+ ["a\nb|\nc\nd", "c2jX\e", "a\nX\n", 2],
23
+ ["one two", "wcbX\e", "Xtwo\n", 0],
24
+ ["x (a b) y", "fa>i(", "\tx (a b) y\n", 1],
25
+ ["ab cd", "c$X\e", "X\n", 0],
26
+ ["foo bar", "cOX\e", "X\n", 0], # vimlike's O motion (line end) after an operator
27
+ ]
28
+
29
+ def inserts?(keys)
30
+ keys.include?("\e")
31
+ end
32
+
33
+ def vma_keys(keys)
34
+ keys.chars.map { |ch| { "\e" => "esc", " " => "space" }.fetch(ch, ch) }.join(" ")
35
+ end
36
+
37
+ # [text before the cursor, from the cursor]; no "|" = cursor at the start
38
+ def split_case(text)
39
+ text.include?("|") ? text.split("|", 2) : ["", text]
40
+ end
41
+
42
+ def run_case(text, keys)
43
+ pre, rest = split_case(text)
44
+ s = pre + rest
45
+ s += "\n" unless s.end_with?("\n")
46
+ pos = pre.size
47
+ b = vma.buf
48
+ b.set_content(s)
49
+ b.set_pos(pos)
50
+ vma.kbd.set_mode(:command)
51
+ keys(vma_keys(keys))
52
+ [b.to_s, b.pos]
53
+ end
54
+
55
+ def test_cases
56
+ # > and < indent with a tab, as vim -u NONE (other tests change these)
57
+ saved = [cnf.tab.width!, cnf.tab.to_spaces_default?]
58
+ cnf.tab.width = 4
59
+ cnf.tab.to_spaces_default = false
60
+ fails = []
61
+ CASES.each { |text, keys, want, want_pos|
62
+ got, got_pos = run_case(text, keys)
63
+ ok = got == want && (inserts?(keys) || got_pos == want_pos)
64
+ fails << "#{text.inspect} #{keys.inspect}: got #{got.inspect} pos #{got_pos}, vim #{want.inspect} pos #{want_pos}" if !ok
65
+ vma.kbd.set_mode(:command)
66
+ }
67
+ assert fails.empty?, "#{fails.size} of #{CASES.size} cases differ from vim:\n " + fails.join("\n ")
68
+ ensure
69
+ cnf.tab.width, cnf.tab.to_spaces_default = saved if saved
70
+ end
71
+
72
+ # vimlike's own bindings win over the templates
73
+ def test_vimlike_bindings_kept
74
+ assert_eq "edit.delete.word.end", vma.kbd.find_state_by_path("C d e").action
75
+ assert_eq "op.motion", vma.kbd.find_state_by_path("C c w").action
76
+ end
77
+
78
+ # A motion added after the keymap loaded works with every operator
79
+ def test_key_set_add
80
+ vma.kbd.key_set_add(:motion, "Q" => :line_end)
81
+ vma.buf.set_content("abc def\n")
82
+ vma.buf.set_pos(0)
83
+ keys("g U Q")
84
+ assert_buf "ABC DEF\n"
85
+ ensure
86
+ vma.kbd.key_sets[:motion].delete("Q")
87
+ vma.kbd.bindings.select { |b| b[:args] && b[:keys].last == "Q" }.each { |b|
88
+ unbindkey("#{b[:mode]} #{b[:keys].join(" ")}")
89
+ }
90
+ assert vma.kbd.bindings.none? { |b| b[:args] && b[:keys].last == "Q" }, "Q bindings left"
91
+ end
92
+
93
+ def vim_result(text, keys)
94
+ pre, rest = split_case(text)
95
+ Dir.mktmpdir { |d|
96
+ f = "#{d}/f.txt"
97
+ File.write(f, pre + rest + (rest.end_with?("\n") ? "" : "\n"))
98
+ k = keys.gsub("\\", "\\\\\\\\").gsub('"', '\\"').gsub("\e", "\\<Esc>")
99
+ system("vim", "-Nu", "NONE", "-i", "NONE", "-es", "-c", "go #{pre.bytesize + 1}",
100
+ "-c", "exe \"norm! #{k}\"",
101
+ "-c", "call writefile([line2byte(line('.'))+col('.')-2], '#{d}/p')", "-c", "wq", f)
102
+ [File.read(f), File.read("#{d}/p").to_i]
103
+ }
104
+ end
105
+
106
+ def test_cases_match_real_vim
107
+ skip "vim not installed" unless system("command -v vim >/dev/null 2>&1")
108
+ fails = CASES.reject { |text, keys, want, want_pos|
109
+ next true if keys.include?("O") # vimlike-only motion
110
+ got, got_pos = vim_result(text, keys)
111
+ got == want && (inserts?(keys) || got_pos == want_pos)
112
+ }
113
+ assert fails.empty?, "expected values out of date for this vim: " +
114
+ fails.map { |c| [c[0], c[1], vim_result(c[0], c[1])] }.inspect
115
+ end
116
+ end
@@ -174,6 +174,7 @@ class TestWindowLayout < VmaTest
174
174
  # first starts with the default size, maximizes, shows two columns and the
175
175
  # file panel, and quits; the second reports what it restored.
176
176
  def test_restored_after_restart
177
+ skip "needs a window manager to maximize (--headless has none)" if ENV["VMA_HEADLESS"]
177
178
  skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
178
179
  Dir.mktmpdir { |dir|
179
180
  ud = "#{dir}/ud"
@@ -216,4 +217,86 @@ class TestWindowLayout < VmaTest
216
217
  "second start: #{second.inspect}\nsaved: #{Marshal.load(File.binread("#{ud}/#{VMAgui::LAYOUT_FILE}")).inspect}"
217
218
  }
218
219
  end
220
+
221
+ # custom.rb for a real startup: after 3 s, run the Ruby code in steps (a
222
+ # list of [delay ms, code] run one after another), then write the window
223
+ # layout to dir/name and quit
224
+ def layout_custom_rb(dir, name, steps = [])
225
+ chain = steps.reverse.inject("File.binwrite(#{"#{dir}/#{name}".inspect}, Marshal.dump(vma.gui.window_layout))\n" \
226
+ "GLib::Timeout.add(1000) { vma.shutdown; false }") { |inner, (ms, code)|
227
+ "#{code}\nGLib::Timeout.add(#{ms}) {\n#{inner}\nfalse }"
228
+ }
229
+ "def hook_custom_after_init\n GLib::Timeout.add(3000) {\n#{chain}\nfalse }\nend\n"
230
+ end
231
+
232
+ # Maximize (full display), then make the window somewhat narrower, keeping
233
+ # the full height (like dragging its side edge), and quit: the next starts
234
+ # get that size back, not the maximized one, and starting and quitting
235
+ # doesn't change it.
236
+ def test_resized_after_maximize_restored
237
+ skip "needs a window manager to maximize (--headless has none)" if ENV["VMA_HEADLESS"]
238
+ skip "needs a display" unless ENV["DISPLAY"] || ENV["WAYLAND_DISPLAY"]
239
+ Dir.mktmpdir { |dir|
240
+ ud = "#{dir}/ud"
241
+ Dir.mkdir(ud)
242
+ mw, mh = gui.monitor_size(gui.layout_monitor)
243
+ # Each step waits (up to 8 s) for the window manager to really
244
+ # maximize or unmaximize: with animations, or on a busy machine, that
245
+ # can take a while
246
+ File.write("#{ud}/custom.rb", <<~RUBY)
247
+ def hook_custom_after_init
248
+ win = vma.gui.window
249
+ save = ->(name) { File.binwrite(#{dir.inspect} + "/" + name, Marshal.dump(vma.gui.window_layout)) }
250
+ wait = ->(cond, done) {
251
+ t0 = Time.now
252
+ GLib::Timeout.add(100) { (cond.() || Time.now - t0 > 8) ? (done.(); false) : true }
253
+ }
254
+ GLib::Timeout.add(3000) {
255
+ win.maximize
256
+ wait.(-> { win.maximized? }, -> {
257
+ GLib::Timeout.add(500) { # let the maximized size settle
258
+ save.("max")
259
+ w, h = win.width, win.height
260
+ win.unmaximize
261
+ wait.(-> { !win.maximized? }, -> {
262
+ win.set_default_size((w * 0.85).to_i, h)
263
+ GLib::Timeout.add(1500) {
264
+ save.("run1")
265
+ GLib::Timeout.add(1000) { vma.shutdown; false }
266
+ false
267
+ }
268
+ })
269
+ false
270
+ }
271
+ })
272
+ false
273
+ }
274
+ end
275
+ RUBY
276
+ run_editor(ud)
277
+ max = Marshal.load(File.binread("#{dir}/max"))
278
+ assert_eq true, max[:maximized], "the window manager didn't maximize the window within 8 s: #{max.inspect}"
279
+ maxw = max[:win_width]
280
+ first = Marshal.load(File.binread("#{dir}/run1"))
281
+ assert_eq false, first[:maximized], "still maximized after unmaximize: #{first.inspect}"
282
+ fw, fh = first.values_at(:width, :height)
283
+ w = (maxw * 0.85).to_i
284
+ # The window manager may adjust it a little, but it must be narrower
285
+ # than the maximized window
286
+ assert fw < maxw && (fw - w).abs <= 50, "resized width #{fw}, asked #{w}, maximized #{maxw}, monitor #{mw}x#{mh}"
287
+
288
+ File.write("#{ud}/custom.rb", layout_custom_rb(dir, "run2"))
289
+ run_editor(ud)
290
+ second = Marshal.load(File.binread("#{dir}/run2"))
291
+ saved = Marshal.load(File.binread("#{ud}/#{VMAgui::LAYOUT_FILE}")).inspect
292
+ assert_eq [false, fw, fh], second.values_at(:maximized, :width, :height),
293
+ "second start: #{second.inspect}\nsaved: #{saved}"
294
+
295
+ File.write("#{ud}/custom.rb", layout_custom_rb(dir, "run3"))
296
+ run_editor(ud)
297
+ third = Marshal.load(File.binread("#{dir}/run3"))
298
+ assert_eq [false, fw, fh], third.values_at(:maximized, :width, :height),
299
+ "third start (after a plain start and stop): #{third.inspect}"
300
+ }
301
+ end
219
302
  end
data/vimamsa.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.bindir = "exe"
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib","ext"]
24
- spec.required_ruby_version = ">= 3.1"
24
+ spec.required_ruby_version = ">= 3.2"
25
25
 
26
26
  spec.add_development_dependency "bundler", ">= 2.4"
27
27
  spec.add_development_dependency "rake", "~> 13.1.0"
data/vm_guest_run.sh CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # Runs INSIDE the test VM guest (copied in and executed by run_tests_vm.sh via
2
+ # Runs INSIDE the test VM guest (copied in and executed by run_tests_vm.rb via
3
3
  # VBoxManage guestcontrol). Unpacks the synced working tree, provisions the box the
4
4
  # first time, builds the native extension, then runs the test suite on the real
5
5
  # desktop (DISPLAY :0) so the GTK window actually appears in the VM.
@@ -24,6 +24,17 @@ mkdir -p "$DEST"
24
24
  tar xzf "$SRC_TGZ" -C "$DEST"
25
25
  cd "$DEST"
26
26
 
27
+ # GNOME locks the screen after 5 min idle; a locked session draws no frames,
28
+ # so layout/redraw-dependent tests fail. Keep the session awake and unlocked.
29
+ if command -v gsettings >/dev/null 2>&1; then
30
+ export DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/$(id -u)/bus}"
31
+ gsettings set org.gnome.desktop.session idle-delay 0 2>/dev/null || true
32
+ gsettings set org.gnome.desktop.screensaver lock-enabled false 2>/dev/null || true
33
+ for s in $(loginctl list-sessions --no-legend 2>/dev/null | awk -v u="$(id -un)" '$3 == u {print $1}'); do
34
+ loginctl unlock-session "$s" 2>/dev/null || true
35
+ done
36
+ fi
37
+
27
38
  # 2. Provision (idempotent). apt + bundler only on the first run (or when forced).
28
39
  if [ ! -f "$MARKER" ] || [ "${FORCE_PROVISION:-}" = "1" ]; then
29
40
  echo ">> Provisioning guest (apt packages + bundler) — this is slow the first time"
@@ -34,7 +45,7 @@ if [ ! -f "$MARKER" ] || [ "${FORCE_PROVISION:-}" = "1" ]; then
34
45
  libgtk-4-dev libgtksourceview-5-dev \
35
46
  libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
36
47
  libvte-2.91-gtk4-dev libssl-dev \
37
- ack clang-format x11-xserver-utils vim
48
+ ack clang-format x11-xserver-utils vim xvfb
38
49
  sudo_do gem install bundler -v '~> 2.4'
39
50
  else
40
51
  echo ">> Guest already provisioned (marker $MARKER present) — skipping apt"
@@ -47,6 +58,15 @@ if ! command -v vim >/dev/null; then
47
58
  sudo_do env DEBIAN_FRONTEND=noninteractive apt-get install -y vim
48
59
  fi
49
60
 
61
+ # xvfb-run for `run_tests.rb --headless` (without it the tests fall back to
62
+ # GTK's Broadway backend, where nothing is laid out or drawn while no browser
63
+ # is connected: bracket matching, panel widths and window sizes fail there).
64
+ # Checked separately so boxes provisioned before it was added get it too.
65
+ if ! command -v xvfb-run >/dev/null; then
66
+ echo ">> Installing xvfb"
67
+ sudo_do env DEBIAN_FRONTEND=noninteractive apt-get install -y xvfb
68
+ fi
69
+
50
70
  # Enable the uinput virtual keyboard so the E2E tests can type real key events.
51
71
  # Do this every run (the module load / device perms don't survive a reboot).
52
72
  sudo_do modprobe uinput 2>/dev/null || true