vimamsa 0.1.26 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +93 -0
  3. data/.gitignore +4 -1
  4. data/Dockerfile +7 -4
  5. data/README.md +195 -99
  6. data/custom_example.rb +59 -17
  7. data/doc/TODO.md +678 -0
  8. data/doc/action_names_plan.md +442 -0
  9. data/doc/bundling_plan.md +570 -0
  10. data/doc/delta_syntax_plan.md +293 -0
  11. data/doc/demo_recording_plan.md +288 -0
  12. data/doc/design_goals.md +27 -0
  13. data/doc/intro_page_plan.md +266 -0
  14. data/doc/key_bindings_report_plan.md +213 -0
  15. data/doc/line_tree_plan.md +89 -0
  16. data/doc/missing_vim_bindings.md +61 -0
  17. data/doc/modules_settings_plan.md +433 -0
  18. data/doc/refactor_dedup_plan.md +117 -0
  19. data/doc/registries_plan.md +202 -0
  20. data/doc/startup_speed_plan.md +97 -0
  21. data/doc/treap_visualizer.html +585 -0
  22. data/doc/unused_code_plan.md +120 -0
  23. data/doc/vim_compatibility_plan.md +451 -0
  24. data/doc/vimlike_vim_conflicts.md +262 -0
  25. data/doc/vm_snapshots_plan.md +146 -0
  26. data/doc/wysiwyg_plan.md +231 -0
  27. data/exe/run_tests.rb +124 -3
  28. data/exe/vimamsa +68 -5
  29. data/fonts/OFL-Oxanium.txt +93 -0
  30. data/fonts/Oxanium[wght].ttf +0 -0
  31. data/help/intro.txt +30 -0
  32. data/help/vim_intro.txt +31 -0
  33. data/icon.png +0 -0
  34. data/img/demo.gif +0 -0
  35. data/img/demo.mp4 +0 -0
  36. data/lang/hyperplaintext.lang +7 -1
  37. data/lib/vimamsa/ack.rb +13 -1
  38. data/lib/vimamsa/actions.rb +385 -37
  39. data/lib/vimamsa/appimage_env.rb +35 -0
  40. data/lib/vimamsa/audio.rb +2 -5
  41. data/lib/vimamsa/bookmarks.rb +302 -0
  42. data/lib/vimamsa/buffer.rb +675 -118
  43. data/lib/vimamsa/buffer_changetext.rb +150 -68
  44. data/lib/vimamsa/buffer_cursor.rb +7 -0
  45. data/lib/vimamsa/buffer_list.rb +6 -2
  46. data/lib/vimamsa/buffer_manager.rb +10 -7
  47. data/lib/vimamsa/bundled_fonts.rb +32 -0
  48. data/lib/vimamsa/cli_help.rb +75 -0
  49. data/lib/vimamsa/clipboard.rb +9 -3
  50. data/lib/vimamsa/conf.rb +68 -3
  51. data/lib/vimamsa/constants.rb +3 -0
  52. data/lib/vimamsa/crash_handler.rb +149 -0
  53. data/lib/vimamsa/debug.rb +6 -3
  54. data/lib/vimamsa/demo_player.rb +458 -0
  55. data/lib/vimamsa/demo_recorder.rb +277 -0
  56. data/lib/vimamsa/desktop_install.rb +96 -0
  57. data/lib/vimamsa/diff_buffer.rb +40 -11
  58. data/lib/vimamsa/dot_repeat.rb +104 -0
  59. data/lib/vimamsa/easy_jump.rb +57 -3
  60. data/lib/vimamsa/editor.rb +327 -78
  61. data/lib/vimamsa/encrypt.rb +78 -29
  62. data/lib/vimamsa/file_finder.rb +4 -19
  63. data/lib/vimamsa/file_history.rb +4 -1
  64. data/lib/vimamsa/file_manager.rb +46 -31
  65. data/lib/vimamsa/fold.rb +226 -0
  66. data/lib/vimamsa/form_input.rb +388 -0
  67. data/lib/vimamsa/gui.rb +603 -119
  68. data/lib/vimamsa/gui_command_line.rb +247 -0
  69. data/lib/vimamsa/gui_dialog.rb +94 -42
  70. data/lib/vimamsa/gui_file_panel.rb +356 -25
  71. data/lib/vimamsa/gui_form_generator.rb +75 -40
  72. data/lib/vimamsa/gui_func_panel.rb +67 -22
  73. data/lib/vimamsa/gui_image.rb +3 -0
  74. data/lib/vimamsa/gui_key_hint.rb +165 -0
  75. data/lib/vimamsa/gui_keylog_panel.rb +408 -0
  76. data/lib/vimamsa/gui_menu.rb +84 -53
  77. data/lib/vimamsa/gui_select_window.rb +80 -75
  78. data/lib/vimamsa/gui_settings.rb +86 -41
  79. data/lib/vimamsa/gui_sourceview.rb +280 -92
  80. data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
  81. data/lib/vimamsa/gui_text.rb +63 -2
  82. data/lib/vimamsa/gui_theme.rb +615 -0
  83. data/lib/vimamsa/hook.rb +5 -0
  84. data/lib/vimamsa/hyper_plain_text.rb +3 -0
  85. data/lib/vimamsa/intro_page.rb +368 -0
  86. data/lib/vimamsa/key_actions.rb +382 -193
  87. data/lib/vimamsa/key_binding_tree.rb +467 -273
  88. data/lib/vimamsa/key_bindings_notepad.rb +45 -0
  89. data/lib/vimamsa/key_bindings_report.rb +484 -0
  90. data/lib/vimamsa/key_bindings_vim.rb +104 -0
  91. data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
  92. data/lib/vimamsa/key_names.rb +80 -0
  93. data/lib/vimamsa/langservp.rb +271 -54
  94. data/lib/vimamsa/line_tree.rb +367 -0
  95. data/lib/vimamsa/macro.rb +23 -3
  96. data/lib/vimamsa/main.rb +14 -8
  97. data/lib/vimamsa/rbvma.rb +41 -1
  98. data/lib/vimamsa/registers.rb +125 -0
  99. data/lib/vimamsa/run_ruby.rb +64 -0
  100. data/lib/vimamsa/search.rb +3 -0
  101. data/lib/vimamsa/search_replace.rb +15 -14
  102. data/lib/vimamsa/string_util.rb +134 -40
  103. data/lib/vimamsa/terminal.rb +3 -0
  104. data/lib/vimamsa/test_framework.rb +28 -2
  105. data/lib/vimamsa/tests.rb +11 -8
  106. data/lib/vimamsa/text_objects.rb +310 -0
  107. data/lib/vimamsa/text_transforms.rb +18 -0
  108. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  109. data/lib/vimamsa/user_dirs.rb +83 -0
  110. data/lib/vimamsa/util.rb +46 -7
  111. data/lib/vimamsa/version.rb +1 -1
  112. data/lib/vimamsa/vim_core.rb +355 -0
  113. data/lib/vimamsa/vim_operators.rb +365 -0
  114. data/lib/vimamsa.rb +0 -1
  115. data/modules/calculator/calculator.rb +5 -5
  116. data/modules/color_highlight/color_highlight.rb +118 -0
  117. data/modules/color_highlight/color_highlight_info.rb +3 -0
  118. data/modules/dictation/dictation.rb +1054 -0
  119. data/modules/dictation/dictation_info.rb +3 -0
  120. data/modules/dictation/whisper_worker.py +273 -0
  121. data/modules/ollama/ollama.rb +107 -0
  122. data/modules/ollama/ollama_info.rb +3 -0
  123. data/modules/terminal/terminal.rb +5 -5
  124. data/modules/tts/tts.rb +119 -0
  125. data/modules/tts/tts_info.rb +3 -0
  126. data/run_e2e_vm.sh +28 -0
  127. data/run_tests_vm.rb +138 -0
  128. data/scripts/appimage/AppRun +54 -0
  129. data/scripts/appimage/Dockerfile +18 -0
  130. data/scripts/appimage/build.sh +19 -0
  131. data/scripts/appimage/build_in_container.sh +192 -0
  132. data/scripts/appimage/smoke_test.sh +27 -0
  133. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  134. data/scripts/demo/demo_files_steps.txt +52 -0
  135. data/scripts/demo/demo_steps.txt +67 -0
  136. data/scripts/demo/notes.txt +6 -0
  137. data/scripts/demo/record_demo.rb +156 -0
  138. data/scripts/demo/report.rb +7 -0
  139. data/scripts/demo/shapes.rb +29 -0
  140. data/scripts/demo/square/shapes.rb +29 -0
  141. data/scripts/demo/square/steps.txt +185 -0
  142. data/scripts/lib/perf_startup.rb +138 -0
  143. data/scripts/lib/script_helpers.rb +53 -0
  144. data/scripts/perf_compare.rb +34 -0
  145. data/scripts/profile_startup.rb +72 -0
  146. data/styles/134272-molokai.xml +3 -0
  147. data/styles/molokai_cyber.xml +48 -0
  148. data/styles/molokai_edit.xml +1 -0
  149. data/tests/support/virtual_keyboard.rb +254 -0
  150. data/tests/support/virtual_mic.rb +67 -0
  151. data/tests/test_ack.rb +22 -0
  152. data/tests/test_action_ids.rb +232 -0
  153. data/tests/test_auto_format.rb +122 -0
  154. data/tests/test_autocomplete.rb +211 -0
  155. data/tests/test_autosave.rb +145 -0
  156. data/tests/test_basic_editing.rb +46 -16
  157. data/tests/test_bookmarks.rb +206 -0
  158. data/tests/test_bracket_match.rb +88 -0
  159. data/tests/test_bundling.rb +92 -0
  160. data/tests/test_cli_help.rb +64 -0
  161. data/tests/test_color_highlight.rb +92 -0
  162. data/tests/test_command_line.rb +79 -0
  163. data/tests/test_command_line_file.rb +27 -0
  164. data/tests/test_context_menu_file.rb +147 -0
  165. data/tests/test_copy_paste.rb +106 -26
  166. data/tests/test_crash_handler.rb +39 -0
  167. data/tests/test_custom_two_phase.rb +92 -0
  168. data/tests/test_demo_player.rb +301 -0
  169. data/tests/test_demo_recorder.rb +202 -0
  170. data/tests/test_dialog_callback_errors.rb +44 -0
  171. data/tests/test_dictation.rb +294 -0
  172. data/tests/test_diff_buffer_name.rb +51 -0
  173. data/tests/test_dot_repeat.rb +88 -0
  174. data/tests/test_double_click.rb +41 -0
  175. data/tests/test_drag_selection.rb +125 -0
  176. data/tests/test_e2e_cmdline.rb +116 -0
  177. data/tests/test_e2e_dictation.rb +98 -0
  178. data/tests/test_e2e_replace_char.rb +58 -0
  179. data/tests/test_easy_jump.rb +93 -0
  180. data/tests/test_extract_file_links.rb +55 -0
  181. data/tests/test_file_format.rb +217 -0
  182. data/tests/test_file_manager.rb +72 -0
  183. data/tests/test_file_panel.rb +269 -0
  184. data/tests/test_flash.rb +78 -0
  185. data/tests/test_fold.rb +111 -0
  186. data/tests/test_font_refresh.rb +56 -0
  187. data/tests/test_form_input.rb +203 -0
  188. data/tests/test_func_panel.rb +68 -0
  189. data/tests/test_grep_apply.rb +46 -0
  190. data/tests/test_gtk_sync.rb +126 -0
  191. data/tests/test_hpt_highlight_visible.rb +75 -0
  192. data/tests/test_hpt_link_highlight.rb +82 -0
  193. data/tests/test_intro_page.rb +437 -0
  194. data/tests/test_jump_to_file.rb +41 -0
  195. data/tests/test_key_bindings.rb +208 -0
  196. data/tests/test_key_categories.rb +163 -0
  197. data/tests/test_keylog_panel.rb +261 -0
  198. data/tests/test_line_ends.rb +51 -0
  199. data/tests/test_line_tree.rb +86 -0
  200. data/tests/test_lsp_clangd.rb +281 -0
  201. data/tests/test_lsp_jump.rb +87 -0
  202. data/tests/test_lsp_position_encoding.rb +49 -0
  203. data/tests/test_lsp_symbols.rb +68 -0
  204. data/tests/test_macro.rb +137 -0
  205. data/tests/test_markdown_highlight.rb +57 -0
  206. data/tests/test_mode_badge.rb +41 -0
  207. data/tests/test_module_interface.rb +9 -9
  208. data/tests/test_notepad_bindings.rb +67 -0
  209. data/tests/test_perf_startup.rb +28 -0
  210. data/tests/test_popup_queue.rb +51 -0
  211. data/tests/test_random_edit.rb +109 -0
  212. data/tests/test_registers.rb +122 -0
  213. data/tests/test_revert.rb +127 -0
  214. data/tests/test_run_ruby.rb +77 -0
  215. data/tests/test_startup_file.rb +58 -0
  216. data/tests/test_status_area.rb +50 -0
  217. data/tests/test_text_objects.rb +163 -0
  218. data/tests/test_text_transforms.rb +341 -0
  219. data/tests/test_tmp_user_dir.rb +79 -0
  220. data/tests/test_tts.rb +68 -0
  221. data/tests/test_undo.rb +34 -34
  222. data/tests/test_user_dirs.rb +122 -0
  223. data/tests/test_vim_bindings.rb +353 -0
  224. data/tests/test_vim_conflicts.rb +100 -0
  225. data/tests/test_vim_operators.rb +116 -0
  226. data/tests/test_window_layout.rb +302 -0
  227. data/vimamsa.gemspec +3 -1
  228. data/vm_guest_run.sh +129 -0
  229. metadata +167 -10
@@ -0,0 +1,163 @@
1
+ # Structured binding records (KeyBindingTree#bindings) and the categories of
2
+ # the key bindings page (doc/key_bindings_report_plan.md steps 1-2).
3
+ class TestKeyCategories < VmaTest
4
+ def find(kbd, mode, keys)
5
+ kbd.bindings.find { |b| b[:mode] == mode && b[:keys].join(" ") == keys }
6
+ end
7
+
8
+ def test_binding_records
9
+ b = find(vma.kbd, "C", "d i <char>")
10
+ assert !b.nil?, "text object binding missing"
11
+ assert_eq "C <op> <textobj>", b[:template]
12
+ assert_eq({ op: :delete, textobj: :inner }, b[:args])
13
+ u = find(vma.kbd, "C", "u")
14
+ assert_eq "undo.last", u[:action]
15
+ assert_eq "Undo the last action", u[:desc] # dotted ids show their description
16
+ g = find(vma.kbd, "C", "G(vma.kbd.next_command_count!=nil)")
17
+ assert !g.nil?, "condition missing from keys"
18
+ # an action on a node that also has longer bindings below it
19
+ assert !find(vma.kbd, "C", "z").nil?, "C z (browse mode) not listed"
20
+ end
21
+
22
+ # Every binding of every keymap has a category, so nothing lands in a
23
+ # catch-all section. A new binding without one fails here: give it a named
24
+ # action, or put it in an add_keys block tagged "cat:<id>".
25
+ def test_every_binding_has_a_category
26
+ [["vimlike"], ["vim"], ["vimlike", "notepad"]].each { |scheme|
27
+ kbd = load_scheme_kbd(scheme)
28
+ bad = kbd.bindings.select { |b| key_binding_category(b, kbd).nil? }
29
+ assert bad.empty?, "#{scheme.join("+")}: no category for " +
30
+ bad.map { |b| "#{b[:mode]} #{b[:keys].join(" ")} => #{b[:action].inspect}" }.inspect
31
+ }
32
+ end
33
+
34
+ # The running tree also has the bindings of modules, minor modes and
35
+ # custom.rb (other tests leave ad-hoc bindings in it, so only those are checked)
36
+ def test_live_bindings_have_known_categories
37
+ ids = KEY_CATEGORIES.map(&:first)
38
+ vma.kbd.bindings.each { |b|
39
+ from_context = b[:mode].match?(/\A\p{Ll}/) || b[:keywords].any? { |k| k == "custom" || k.start_with?("module:") }
40
+ next if !from_context
41
+ c = key_binding_category(b)
42
+ assert !c.nil?, "no category: #{b[:mode]} #{b[:keys].join(" ")} => #{b[:action].inspect}"
43
+ assert ids.include?(c) || c.start_with?("module:", "mode:"), "unknown category #{c.inspect}"
44
+ }
45
+ end
46
+
47
+ def test_categories_from_namespace_mode_and_context
48
+ kbd = KeyBindingTree.new(actions: ActionList.new)
49
+ kbd.add_mode("C", :command)
50
+ kbd.add_minor_mode("fexp", :file_exp, :command)
51
+ kbd.bindkey("C , Q 1", "move.word.next")
52
+ kbd.bindkey("fexp , Q 2", "move.word.next")
53
+ kbd.with_keywords(["module:foo"]) { kbd.bindkey("C , Q 3", "foo_bar()") }
54
+ kbd.bindkey("C , Q 4", "foo_bar()", keywords: "cat:edit")
55
+ kbd.bindkey("C , Q 5", "foo_bar()")
56
+ cat = ->(k) { key_binding_category(find(kbd, k.split[0], k.split[1..].join(" ")), kbd) }
57
+ assert_eq "motion", cat.("C , Q 1")
58
+ assert_eq "mode:fexp", cat.("fexp , Q 2")
59
+ assert_eq "module:foo", cat.("C , Q 3")
60
+ assert_eq "edit", cat.("C , Q 4")
61
+ assert_eq nil, cat.("C , Q 5")
62
+ assert kbd.extra_keywords.empty?, "with_keywords leaked"
63
+ end
64
+
65
+ def test_page_sections
66
+ show_key_bindings
67
+ s = vma.buf.to_s
68
+ begin
69
+ heads = s.scan(/^◼ (.+)$/).flatten
70
+ assert heads.include?("Moving the cursor") && heads.include?("Text objects"), heads.inspect
71
+ assert heads.index("Moving the cursor") < heads.index("Text objects")
72
+ assert !heads.include?("Others"), heads.inspect
73
+ # bindings other tests left behind may be uncategorized: last, if at all
74
+ assert !heads.include?("Uncategorized") || heads.last == "Uncategorized", heads.inspect
75
+ assert s.include?("Undo the last action"), "descriptions missing"
76
+ ensure
77
+ vma.buffers.close_buffer(vma.buf.id)
78
+ end
79
+ end
80
+
81
+ # Step 3: rows merged across modes and keys, grouped by modes, conditions
82
+ # as text, definition order
83
+ def test_section_layout
84
+ kbd = KeyBindingTree.new(actions: ActionList.new)
85
+ kbd.add_mode("C", :command)
86
+ kbd.add_mode("V", :visual, :visual)
87
+ kbd.bindkey("VC , Q 2", "move.word.next")
88
+ kbd.bindkey("VC , Q 1", "move.word.next")
89
+ kbd.bindkey("C , Q 3(vma.kbd.next_command_count!=nil)", "move.word.next")
90
+ kbd.bindkey("C , Q 4(foo_bar)", "move.word.prev")
91
+ w = ", Q 2 / , Q 1".size
92
+ assert_eq ["◼◼ Command, Visual",
93
+ " , Q 2 / , Q 1 move.word.next",
94
+ "◼◼ Command",
95
+ " #{", Q 3".ljust(w)} move.word.next (with a count)",
96
+ " #{", Q 4".ljust(w)} move.word.prev (if foo_bar)"],
97
+ key_bindings_section(kbd.bindings)
98
+ end
99
+
100
+ def test_page_layout
101
+ s = key_bindings_page(vma.kbd, scheme: "vimlike")
102
+ assert s.start_with?("❙Key bindings — scheme: vimlike❙"), s[0, 80]
103
+ heads = s.scan(/^◼ (.+)$/).flatten
104
+ assert_eq "Basics", heads[0]
105
+ basics = s[/^◼ Basics\n(.*?)\n\n/m, 1]
106
+ assert basics.include?(vma.actions["undo.last"].method_name), basics
107
+ assert s.include?("(with a count)"), "condition text missing"
108
+ assert !s.include?("(vma.kbd.next_command_count"), "raw condition shown"
109
+ motion = s[/^◼ Moving the cursor\n(.*?)\n\n/m, 1]
110
+ e, b = %w[move.word.end move.word.prev].map { |id| motion.index(vma.actions[id].method_name) }
111
+ assert e && b && e < b, "not in definition order:\n#{motion}"
112
+ assert motion.include?("◼◼ Command, Visual"), motion
113
+ # templates: one line each, and the key sets listed
114
+ assert s.include?("<op> <motion>"), "template line missing"
115
+ assert !s.match?(/^ +c w /), "template expansions listed one by one"
116
+ assert s.include?("◼ Operators, motions and text objects"), "key sets missing"
117
+ end
118
+
119
+ # doc/action_names_plan.md step 6: every binding of every keymap runs a
120
+ # named action with a description, not Ruby code. A new Ruby-string
121
+ # binding fails here: register an action (reg_act) and bind its id.
122
+ # Readchar mode ("R <char>") is internal and not named.
123
+ def test_every_binding_has_a_description
124
+ [["vimlike"], ["vim"], ["vimlike", "notepad"]].each { |scheme|
125
+ kbd = load_scheme_kbd(scheme)
126
+ bad = kbd.bindings.reject { |b|
127
+ next true if b[:mode] == "R"
128
+ act = b[:action]
129
+ next false if act.class == Proc
130
+ r = [kbd.actions, vma.actions].map { |l| l[act] }.find { |x| x && !x.opt&.[](:code) }
131
+ r && !r.method_name.to_s.strip.empty? && r.method_name.to_s != act.to_s
132
+ }
133
+ assert bad.empty?, "#{scheme.join("+")}: no description for " +
134
+ bad.map { |b| "#{b[:mode]} #{b[:keys].join(" ")} => #{b[:action].inspect}" }.inspect
135
+ }
136
+ end
137
+
138
+ # A named action bound to a <char> key gets the typed character
139
+ def test_char_argument
140
+ buf.set_content("abc\n")
141
+ buf.set_pos(0)
142
+ keys("f c") # jump.char.next
143
+ assert_pos 0, 2
144
+ keys("r x") # edit.replace.char
145
+ assert_buf "abx\n"
146
+ keys("m q") # mark.set
147
+ keys("0")
148
+ keys("' q") # mark.jump
149
+ assert_pos 0, 2
150
+ keys("i z esc") # edit.insert.char
151
+ assert_buf "abzx\n"
152
+ end
153
+
154
+ # The character reaches the action also when a macro replays it
155
+ def test_char_argument_in_macro
156
+ buf.set_content("abc\n")
157
+ buf.set_pos(0)
158
+ keys("q w r y q") # macro.record w, edit.replace.char y, macro.record.stop
159
+ assert_buf "ybc\n"
160
+ keys("l @ w") # macro.run w
161
+ assert_buf "yyc\n"
162
+ end
163
+ end
@@ -0,0 +1,261 @@
1
+ class TestKeylogPanel < VmaTest
2
+ def panel
3
+ vma.gui.keylog_panel
4
+ end
5
+
6
+ # Show the panel, run the block with a clean log, always hide again so
7
+ # later tests (and other test files) start with logging off.
8
+ def with_panel
9
+ act "panel.keylog.toggle"
10
+ panel.clear
11
+ yield
12
+ ensure
13
+ act "panel.keylog.toggle"
14
+ end
15
+
16
+ def test_chord_and_action_logged
17
+ with_panel do
18
+ keys("g g")
19
+ e = panel.entries.last
20
+ assert_eq :action, e[:kind]
21
+ assert_eq "move.buf.start", e[:action]
22
+ assert e[:chord].include?("g g"), "chord was #{e[:chord].inspect}"
23
+ assert e[:chord].include?("[COMMAND]"), "chord was #{e[:chord].inspect}"
24
+ end
25
+ end
26
+
27
+ def test_pending_chord_shown
28
+ with_panel do
29
+ keys("g")
30
+ e = panel.entries.last
31
+ assert_eq :pending, e[:kind]
32
+ assert e[:chord].include?("g"), "chord was #{e[:chord].inspect}"
33
+ keys("g")
34
+ # Completing the chord replaces the pending row with the action row
35
+ assert_eq :action, panel.entries.last[:kind]
36
+ assert_eq 0, panel.entries.count { |x| x[:kind] == :pending }
37
+ end
38
+ end
39
+
40
+ def test_insert_mode_coalesced
41
+ with_panel do
42
+ keys("i h e l l o")
43
+ ins = panel.entries.select { |e| e[:kind] == :insert }
44
+ assert_eq 1, ins.size
45
+ assert_eq "hello", ins.first[:text]
46
+ keys("esc")
47
+ end
48
+ end
49
+
50
+ def test_no_logging_when_hidden
51
+ n = panel.entries.size
52
+ keys("g g")
53
+ assert_eq n, panel.entries.size
54
+ end
55
+
56
+ def test_newest_shown_at_top_and_highlighted
57
+ with_panel do
58
+ keys("j")
59
+ keys("k")
60
+ row = panel.newest_row
61
+ assert row.css_classes.include?("keylog-newest"), "newest row not highlighted"
62
+ assert_eq row, panel.top_row
63
+ assert_eq :action, panel.entries.last[:kind]
64
+ end
65
+ end
66
+
67
+ def test_entry_cap
68
+ with_panel do
69
+ 210.times { keys("j") }
70
+ cap = Vimamsa::KeyLogPanel::MAX_ENTRIES
71
+ assert panel.entries.size <= cap, "#{panel.entries.size} entries exceeds cap #{cap}"
72
+ end
73
+ end
74
+
75
+ # Let GTK lay out the pane (set_keylog_width waits for an allocation)
76
+ def settle
77
+ t = Time.now
78
+ drain_idle
79
+ GLib::MainContext.default.iteration(false) while Time.now - t < 0.4
80
+ end
81
+
82
+ # First show uses the default width, and long entries (even without
83
+ # spaces) don't widen it
84
+ def test_width_fixed_on_first_show
85
+ skip "no layout on the Broadway backend" if ENV["VMA_HEADLESS"] == "broadway"
86
+ gui = vma.gui
87
+ old = gui.instance_variable_get(:@keylog_width)
88
+ gui.instance_variable_set(:@keylog_width, nil)
89
+ with_panel do
90
+ settle
91
+ w = gui.keylog_width
92
+ assert (w - VMAgui::PANEL_DEFAULT_WIDTH[:keylog]).abs <= 2, "first width #{w}"
93
+ 5.times { keys("e") } # "Jump to the end of the next word"
94
+ keys("o esc") # a long action string without spaces
95
+ keys("g g")
96
+ settle
97
+ assert_eq w, gui.keylog_width
98
+ end
99
+ ensure
100
+ gui.instance_variable_set(:@keylog_width, old)
101
+ end
102
+ def drain_for(secs)
103
+ t = Time.now
104
+ while Time.now - t < secs
105
+ drain_idle
106
+ sleep 0.01
107
+ end
108
+ end
109
+
110
+ # The bubble next to the cursor (gui_key_hint.rb) shows the key and the
111
+ # action, without the mode badge, near the cursor's line
112
+ def test_hint_near_cursor
113
+ act 'buf.insert_txt("one\ntwo\nthree\nfour\n")'
114
+ keys "g g"
115
+ with_panel do
116
+ keys "j j"
117
+ drain_for(0.1)
118
+ h = panel.hint
119
+ assert h.visible?, "hint not shown"
120
+ assert h.markup.include?("<b>j</b>"), "hint was #{h.markup.inspect}"
121
+ assert !h.markup.include?("[COMMAND]"), "hint has the mode: #{h.markup.inspect}"
122
+ _x, y = vma.gui.view.pos_to_coord(vma.buf.pos)
123
+ top = h.widget.margin_top
124
+ assert (top - y).abs < 100, "hint at y #{top}, cursor at y #{y}"
125
+ assert h.widget.can_target? == false, "the hint takes mouse input"
126
+ end
127
+ end
128
+
129
+ # The bubble starts with the mode after the action: v shows VISUAL
130
+ def test_hint_shows_mode
131
+ with_panel do
132
+ keys "j"
133
+ drain_for(0.05)
134
+ assert panel.hint.markup.include?("COMMAND"), panel.hint.markup
135
+ keys "v"
136
+ drain_for(0.05)
137
+ assert panel.hint.markup.include?("VISUAL"), panel.hint.markup
138
+ # the badge's own CSS classes, as the status badge: same theme colors
139
+ ml = panel.hint.mode_label
140
+ assert ml.has_css_class?("mode-badge") && ml.has_css_class?("mode-visual"), ml.css_classes.inspect
141
+ assert !ml.has_css_class?("mode-command"), ml.css_classes.inspect
142
+ keys "esc"
143
+ keys "i"
144
+ drain_for(0.05)
145
+ assert panel.hint.markup.include?("INSERT"), panel.hint.markup
146
+ keys "esc"
147
+ end
148
+ end
149
+
150
+ # cnf.key_hint.y_offset px below the cursor's row, starting right of the
151
+ # text of the row it covers
152
+ def test_hint_below_row_by_offset
153
+ act 'buf.insert_txt("one\nsecond line here\nthree\nfour\n")'
154
+ keys "g g"
155
+ old = cnf.key_hint.y_offset!
156
+ with_panel do
157
+ [4, 20].each { |off|
158
+ cnf.key_hint.y_offset = off
159
+ keys "j k"
160
+ drain_for(0.1)
161
+ v = vma.gui.view
162
+ x, y = v.pos_to_coord(vma.buf.pos)
163
+ line_h = v.get_iter_location(v.buffer.get_iter_at(offset: vma.buf.pos)).height
164
+ w = panel.hint.widget
165
+ assert_eq y + line_h + off, w.margin_top, "offset #{off}"
166
+ xe, _ = v.pos_to_coord(vma.buf.line_ends[1]) # end of "second line here"
167
+ assert w.margin_start > xe, "hint at x #{w.margin_start} covers row 2 (ends at x #{xe})"
168
+ }
169
+ end
170
+ ensure
171
+ cnf.key_hint.y_offset = old
172
+ end
173
+
174
+ # A long bubble on a long line stays inside the editor (it used to be
175
+ # placed by the width of the previous, shorter text)
176
+ def test_hint_fits_in_view
177
+ with_panel do
178
+ keys "i"
179
+ keys ("a b c d e f g h " * 6).strip
180
+ drain_for(0.1)
181
+ w = panel.hint.widget
182
+ ov = vma.gui.active_window[:overlay]
183
+ right = w.measure(:horizontal, -1)[1] - w.margin_end # measure counts margin_start
184
+ assert right <= ov.width + 1, "hint ends at x #{right}, editor is #{ov.width} wide"
185
+ keys "esc"
186
+ end
187
+ end
188
+
189
+ # A buffer switch by a key doesn't cover the hint: the new scrolled window
190
+ # is the overlay's main child, drawn below the hint (gui.rb
191
+ # set_current_buffer)
192
+ def test_hint_stays_above_after_buffer_switch
193
+ create_new_buffer("first buffer\n", "hint_a")
194
+ create_new_buffer("second buffer\n", "hint_b")
195
+ with_panel do
196
+ keys "tab"
197
+ drain_for(0.1)
198
+ assert_eq "first buffer\n", vma.buf.to_s, "tab didn't switch buffers"
199
+ ov = vma.gui.active_window[:overlay]
200
+ sw = vma.gui.active_window[:sw]
201
+ w = panel.hint.widget
202
+ assert w.visible?, "hint not shown"
203
+ assert_eq ov, w.parent
204
+ assert_eq sw, ov.child, "scrolled window not the overlay's main child"
205
+ kids = []
206
+ c = ov.first_child
207
+ while c
208
+ kids << c
209
+ c = c.next_sibling
210
+ end
211
+ assert kids.index(w) > kids.index(sw), "hint drawn below the text: #{kids.map { |k| k.class }.inspect}"
212
+ end
213
+ end
214
+
215
+ def test_hint_typed_text_and_pending
216
+ with_panel do
217
+ keys "g"
218
+ assert panel.hint.markup.include?("<b>g</b> …"), panel.hint.markup
219
+ keys "esc i a b c"
220
+ assert panel.hint.markup.include?("typed"), panel.hint.markup
221
+ assert panel.hint.markup.include?("abc"), panel.hint.markup
222
+ keys "esc"
223
+ end
224
+ end
225
+
226
+ def test_hint_fades_and_hides_with_panel
227
+ with_panel do
228
+ keys "j"
229
+ assert panel.hint.visible?
230
+ drain_for(KeyHint::SHOW_SECS + KeyHint::FADE_SECS + 0.4)
231
+ assert !panel.hint.visible?, "hint didn't fade out"
232
+ keys "k"
233
+ assert panel.hint.visible?
234
+ end
235
+ assert !panel.hint.visible?, "hint still shown with the panel hidden"
236
+ end
237
+ # Easy jump reads its label keys itself; they are logged as one row
238
+ def test_easy_jump_label_logged
239
+ act 'buf.insert_txt("one\ntwo\nthree\nfour\n")'
240
+ keys "g g"
241
+ vma.buf.view.handle_deltas
242
+ with_panel do
243
+ 20.times { drain_idle; sleep 0.02 } # laid out: easy jump labels only what's visible
244
+ keys "s"
245
+ ej = EasyJump.class_variable_get(:@@cur)
246
+ marks = ej.instance_variable_get(:@easy_jump_wsmarks)
247
+ seq = ej.instance_variable_get(:@jump_sequence)
248
+ n = marks.index(vma.buf.line_ends[1] + 1) # the start of line 3
249
+ assert n, "no label for line 3: marks #{marks.first(10).inspect}"
250
+ label = seq[n].downcase
251
+ keys label.chars.join(" ")
252
+ e = panel.entries.last
253
+ assert_eq :jump, e[:kind]
254
+ assert_eq label, e[:text]
255
+ assert_eq :jumped, e[:state]
256
+ assert_eq 3, e[:line]
257
+ assert_eq 1, panel.entries.count { |x| x[:kind] == :jump }, "one row per label"
258
+ assert panel.hint.markup.include?(label), panel.hint.markup
259
+ end
260
+ end
261
+ end
@@ -0,0 +1,51 @@
1
+ require "benchmark"
2
+
3
+ # scan_indexes / line ends on non-ASCII text (scan_indexes used to be O(n^2)
4
+ # there), and get_line_end (used to scan all line ends).
5
+ class TestLineEnds < VmaTest
6
+ # The old implementation, kept as the reference.
7
+ def ref_scan_indexes(txt, regex)
8
+ txt.enum_for(:scan, regex).map { Regexp.last_match.begin(0) }
9
+ end
10
+
11
+ def test_scan_indexes_matches_reference_on_utf8
12
+ txt = "äö foo\nbär baz\n\n€ x\ty\nlast"
13
+ [/\n/, /\S/, /(?<=[^\p{Word}])\p{Word}|\Z/, /(?<=\p{Word})[^\p{Word}]/, /\n[ \t]*\n/, /z/].each do |re|
14
+ assert_eq ref_scan_indexes(txt, re), scan_indexes(txt, re), "regex #{re.inspect}"
15
+ end
16
+ end
17
+
18
+ def test_scan_indexes_ascii_unchanged
19
+ txt = "foo bar\nbaz\n"
20
+ assert_eq ref_scan_indexes(txt, /\n/), scan_indexes(txt, /\n/)
21
+ end
22
+
23
+ def test_line_ends_of_utf8_buffer
24
+ act 'buf.insert_txt("äb\nc€d\n\nlast")'
25
+ b = vma.buf
26
+ assert_eq ref_scan_indexes(b.to_s, /\n/), b.line_ends.to_a
27
+ assert_eq 2, b.get_line_end(0)
28
+ assert_eq 6, b.get_line_end(3)
29
+ assert_eq 7, b.get_line_end(6)
30
+ end
31
+
32
+ def test_get_line_end_matches_select
33
+ act 'buf.insert_txt("a\nbb\n\nccc\nd")'
34
+ b = vma.buf
35
+ (0...b.size).each do |pos|
36
+ assert_eq b.line_ends.to_a.select { |x| x > pos }.min, b.get_line_end(pos), "pos #{pos}"
37
+ end
38
+ end
39
+
40
+ # 3 MB with one non-ASCII character: the old code took seconds (13 s at
41
+ # 5.5 MB), the new one well under 0.1 s. The bound is loose for slow
42
+ # machines (the test VM once took 1.0 s).
43
+ def test_scan_indexes_utf8_is_not_quadratic
44
+ txt = "ä" + ("the quick brown fox jumps over the lazy dog 0123456789\n" * 55_000)
45
+ res = nil
46
+ t = Benchmark.realtime { res = scan_indexes(txt, /\n/) }
47
+ assert_eq 55_000, res.size
48
+ assert_eq txt.size - 1, res.last
49
+ assert t < 2.0, "scan_indexes took #{t.round(2)} s for 3 MB of UTF-8"
50
+ end
51
+ end
@@ -0,0 +1,86 @@
1
+ require "benchmark"
2
+
3
+ # LineTree: the treap that holds a buffer's line ends (lib/vimamsa/line_tree.rb,
4
+ # doc/line_tree_plan.md).
5
+ class TestLineTree < VmaTest
6
+ def newline_positions(s)
7
+ out = []
8
+ s.each_char.with_index { |c, i| out << i if c == "\n" }
9
+ out
10
+ end
11
+
12
+ def test_from_string
13
+ assert_eq [], LineTree.from_string("").to_a
14
+ assert_eq [2], LineTree.from_string("ab\n").to_a
15
+ assert_eq [2, 3], LineTree.from_string("ab\n\ncd").to_a
16
+ t = LineTree.from_string("ab\n\ncd")
17
+ assert_eq 2, t.size
18
+ assert_eq 6, t.total
19
+ assert_eq [2, 1], t.line_at(5)
20
+ assert_eq [2, 2], t.line_at(6) # the end belongs to the last line
21
+ end
22
+
23
+ # Random inserts and deletes, including non-ASCII text and newlines, compared
24
+ # with the newline positions of a String after every step.
25
+ def test_random_edits_match_string
26
+ rng = Random.new(7)
27
+ alpha = ["a", "b", "ä", "€", "\n", "\n", "xy", "\n\n", "q\nr", "ö\nä\n"]
28
+ 40.times do
29
+ s = Array.new(rng.rand(0..20)) { alpha.sample(random: rng) }.join
30
+ t = LineTree.from_string(s)
31
+ 40.times do
32
+ if rng.rand < 0.55 || s.empty?
33
+ pos = rng.rand(0..s.size)
34
+ txt = Array.new(rng.rand(1..4)) { alpha.sample(random: rng) }.join
35
+ s.insert(pos, txt)
36
+ t.insert(pos, txt)
37
+ else
38
+ pos = rng.rand(0...s.size)
39
+ removed = s.slice!(pos, rng.rand(1..[6, s.size - pos].min))
40
+ t.delete(pos, removed)
41
+ end
42
+ ref = newline_positions(s)
43
+ assert_eq ref, t.to_a, "after edits, text #{s.inspect}"
44
+ assert t.check!
45
+ assert_eq s.size, t.total
46
+ end
47
+ end
48
+ end
49
+
50
+ def test_array_interface_matches_array
51
+ s = "ab\n\nc€d\nx\n\nlast"
52
+ ref = newline_positions(s)
53
+ t = LineTree.from_string(s)
54
+ assert_eq ref.size, t.size
55
+ (-ref.size - 1..ref.size).each { |i| assert_eq ref[i], t[i], "[#{i}]" }
56
+ (0..s.size + 1).each do |p|
57
+ assert_eq ref.bsearch_index { |x| x >= p }, t.bsearch_index { |x| x >= p }, "bsearch_index #{p}"
58
+ assert_eq ref.bsearch { |x| x > p }, t.bsearch { |x| x > p }, "bsearch #{p}"
59
+ end
60
+ end
61
+
62
+ def test_buffer_edits_keep_line_ends
63
+ act 'buf.insert_txt("one\ntwo\nthree\n")'
64
+ keys "g g d d"
65
+ keys "p"
66
+ act 'buf.insert_txt("x\ny")'
67
+ b = vma.buf
68
+ assert_eq newline_positions(b.to_s), b.line_ends.to_a
69
+ act "undo.last"
70
+ act "undo.last"
71
+ b = vma.buf
72
+ assert_eq newline_positions(b.to_s), b.line_ends.to_a
73
+ end
74
+
75
+ # The old Array took about 6 ms per edit at 100k lines (it shifted every later
76
+ # entry); the tree needs microseconds. The bound is loose for slow machines.
77
+ def test_edit_cost_does_not_grow_with_lines
78
+ t = LineTree.from_string("the quick brown fox jumps over the lazy dog 0123456789\n" * 100_000)
79
+ mid = t.total / 2
80
+ sec = Benchmark.realtime { 1000.times { |k| t.insert(mid + k, "x") } }
81
+ assert sec < 0.5, "1000 inserts took #{sec.round(3)} s"
82
+ sec = Benchmark.realtime { 200.times { t.insert(mid, "ab\ncd\n") } }
83
+ assert sec < 0.5, "200 newline inserts took #{sec.round(3)} s"
84
+ assert_eq 100_400, t.size
85
+ end
86
+ end