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.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +93 -0
- data/.gitignore +4 -1
- data/Dockerfile +7 -4
- data/README.md +195 -99
- data/custom_example.rb +59 -17
- data/doc/TODO.md +678 -0
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +570 -0
- data/doc/delta_syntax_plan.md +293 -0
- data/doc/demo_recording_plan.md +288 -0
- data/doc/design_goals.md +27 -0
- data/doc/intro_page_plan.md +266 -0
- data/doc/key_bindings_report_plan.md +213 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +61 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +451 -0
- data/doc/vimlike_vim_conflicts.md +262 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/doc/wysiwyg_plan.md +231 -0
- data/exe/run_tests.rb +124 -3
- data/exe/vimamsa +68 -5
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +7 -1
- data/lib/vimamsa/ack.rb +13 -1
- data/lib/vimamsa/actions.rb +385 -37
- data/lib/vimamsa/appimage_env.rb +35 -0
- data/lib/vimamsa/audio.rb +2 -5
- data/lib/vimamsa/bookmarks.rb +302 -0
- data/lib/vimamsa/buffer.rb +675 -118
- data/lib/vimamsa/buffer_changetext.rb +150 -68
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +6 -2
- data/lib/vimamsa/buffer_manager.rb +10 -7
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +9 -3
- data/lib/vimamsa/conf.rb +68 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +6 -3
- data/lib/vimamsa/demo_player.rb +458 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +40 -11
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +57 -3
- data/lib/vimamsa/editor.rb +327 -78
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +4 -1
- data/lib/vimamsa/file_manager.rb +46 -31
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +603 -119
- data/lib/vimamsa/gui_command_line.rb +247 -0
- data/lib/vimamsa/gui_dialog.rb +94 -42
- data/lib/vimamsa/gui_file_panel.rb +356 -25
- data/lib/vimamsa/gui_form_generator.rb +75 -40
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +408 -0
- data/lib/vimamsa/gui_menu.rb +84 -53
- data/lib/vimamsa/gui_select_window.rb +80 -75
- data/lib/vimamsa/gui_settings.rb +86 -41
- data/lib/vimamsa/gui_sourceview.rb +280 -92
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +615 -0
- data/lib/vimamsa/hook.rb +5 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/intro_page.rb +368 -0
- data/lib/vimamsa/key_actions.rb +382 -193
- data/lib/vimamsa/key_binding_tree.rb +467 -273
- data/lib/vimamsa/key_bindings_notepad.rb +45 -0
- data/lib/vimamsa/key_bindings_report.rb +484 -0
- data/lib/vimamsa/key_bindings_vim.rb +104 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +23 -3
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +41 -1
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +15 -14
- data/lib/vimamsa/string_util.rb +134 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +11 -8
- data/lib/vimamsa/text_objects.rb +310 -0
- data/lib/vimamsa/text_transforms.rb +18 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_core.rb +355 -0
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/lib/vimamsa.rb +0 -1
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +118 -0
- data/modules/color_highlight/color_highlight_info.rb +3 -0
- data/modules/dictation/dictation.rb +1054 -0
- data/modules/dictation/dictation_info.rb +3 -0
- data/modules/dictation/whisper_worker.py +273 -0
- data/modules/ollama/ollama.rb +107 -0
- data/modules/ollama/ollama_info.rb +3 -0
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.rb +138 -0
- data/scripts/appimage/AppRun +54 -0
- data/scripts/appimage/Dockerfile +18 -0
- data/scripts/appimage/build.sh +19 -0
- data/scripts/appimage/build_in_container.sh +192 -0
- data/scripts/appimage/smoke_test.sh +27 -0
- data/scripts/demo/demo_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +67 -0
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +156 -0
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +29 -0
- data/scripts/demo/square/shapes.rb +29 -0
- data/scripts/demo/square/steps.txt +185 -0
- data/scripts/lib/perf_startup.rb +138 -0
- data/scripts/lib/script_helpers.rb +53 -0
- data/scripts/perf_compare.rb +34 -0
- data/scripts/profile_startup.rb +72 -0
- data/styles/134272-molokai.xml +3 -0
- data/styles/molokai_cyber.xml +48 -0
- data/styles/molokai_edit.xml +1 -0
- data/tests/support/virtual_keyboard.rb +254 -0
- data/tests/support/virtual_mic.rb +67 -0
- data/tests/test_ack.rb +22 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +122 -0
- data/tests/test_autocomplete.rb +211 -0
- data/tests/test_autosave.rb +145 -0
- data/tests/test_basic_editing.rb +46 -16
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +88 -0
- data/tests/test_bundling.rb +92 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +92 -0
- data/tests/test_command_line.rb +79 -0
- data/tests/test_command_line_file.rb +27 -0
- data/tests/test_context_menu_file.rb +147 -0
- data/tests/test_copy_paste.rb +106 -26
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -0
- data/tests/test_demo_player.rb +301 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dialog_callback_errors.rb +44 -0
- data/tests/test_dictation.rb +294 -0
- data/tests/test_diff_buffer_name.rb +51 -0
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_double_click.rb +41 -0
- data/tests/test_drag_selection.rb +125 -0
- data/tests/test_e2e_cmdline.rb +116 -0
- data/tests/test_e2e_dictation.rb +98 -0
- data/tests/test_e2e_replace_char.rb +58 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +55 -0
- data/tests/test_file_format.rb +217 -0
- data/tests/test_file_manager.rb +72 -0
- data/tests/test_file_panel.rb +269 -0
- data/tests/test_flash.rb +78 -0
- data/tests/test_fold.rb +111 -0
- data/tests/test_font_refresh.rb +56 -0
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +68 -0
- data/tests/test_grep_apply.rb +46 -0
- data/tests/test_gtk_sync.rb +126 -0
- data/tests/test_hpt_highlight_visible.rb +75 -0
- data/tests/test_hpt_link_highlight.rb +82 -0
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +261 -0
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +281 -0
- data/tests/test_lsp_jump.rb +87 -0
- data/tests/test_lsp_position_encoding.rb +49 -0
- data/tests/test_lsp_symbols.rb +68 -0
- data/tests/test_macro.rb +137 -0
- data/tests/test_markdown_highlight.rb +57 -0
- data/tests/test_mode_badge.rb +41 -0
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +67 -0
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_registers.rb +122 -0
- data/tests/test_revert.rb +127 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +58 -0
- data/tests/test_status_area.rb +50 -0
- data/tests/test_text_objects.rb +163 -0
- data/tests/test_text_transforms.rb +341 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +353 -0
- data/tests/test_vim_conflicts.rb +100 -0
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +302 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +129 -0
- metadata +167 -10
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
class TestDictation < VmaTest
|
|
2
|
+
def load_dictation
|
|
3
|
+
load ppath("modules/dictation/dictation_info.rb")
|
|
4
|
+
load ppath("modules/dictation/dictation.rb")
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def ensure_disabled
|
|
8
|
+
dictation_disable if vma.actions.include?("dictation.toggle")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# --- _info ---
|
|
12
|
+
|
|
13
|
+
def test_info_structure
|
|
14
|
+
load ppath("modules/dictation/dictation_info.rb")
|
|
15
|
+
info = dictation_info
|
|
16
|
+
assert info[:name].is_a?(String) && !info[:name].empty?, "name should be a non-empty String"
|
|
17
|
+
assert_eq true, info[:no_restart], "dictation should be no_restart"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# --- init / disable contract ---
|
|
21
|
+
|
|
22
|
+
def test_init_registers_action_and_menu
|
|
23
|
+
ensure_disabled
|
|
24
|
+
load_dictation
|
|
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"
|
|
28
|
+
ensure
|
|
29
|
+
dictation_disable
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# "Start/Stop Dictation" runs the `, k` action, so its menu label shows the key
|
|
33
|
+
def test_menu_item_shows_key_binding
|
|
34
|
+
ensure_disabled
|
|
35
|
+
load_dictation
|
|
36
|
+
dictation_init
|
|
37
|
+
hint = vma.gui.menu.kbd_hint("dictation.enter_mode")
|
|
38
|
+
assert hint.include?("[C]</span> , k"), "no , k hint: #{hint.inspect}"
|
|
39
|
+
ensure
|
|
40
|
+
dictation_disable
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_disable_unregisters
|
|
44
|
+
ensure_disabled
|
|
45
|
+
load_dictation
|
|
46
|
+
dictation_init
|
|
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"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_init_disable_cycle
|
|
53
|
+
ensure_disabled
|
|
54
|
+
load_dictation
|
|
55
|
+
3.times do |i|
|
|
56
|
+
dictation_init
|
|
57
|
+
assert vma.actions.include?("dictation.toggle"), "action missing after init (cycle #{i})"
|
|
58
|
+
dictation_disable
|
|
59
|
+
assert !vma.actions.include?("dictation.toggle"), "action present after disable (cycle #{i})"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# --- WAV header finalization (the one piece of nontrivial logic) ---
|
|
64
|
+
|
|
65
|
+
def test_wav_header_fix
|
|
66
|
+
load_dictation
|
|
67
|
+
|
|
68
|
+
# Build a WAV with placeholder size fields (as wavenc leaves them without EOS).
|
|
69
|
+
samples = "\x00\x00" * 8000 # 8000 frames of S16LE mono silence
|
|
70
|
+
fmt = ["fmt ", 16, 1, 1, 16000, 32000, 2, 16].pack("a4VvvVVvv")
|
|
71
|
+
data_chunk = "data" + [0x7FFF0000].pack("V") + samples
|
|
72
|
+
riff = "RIFF" + [0x7FFF0024].pack("V") + "WAVE" + fmt + data_chunk
|
|
73
|
+
|
|
74
|
+
path = File.join(Dir.tmpdir, "vma_dictation_test_#{Process.pid}.wav")
|
|
75
|
+
File.binwrite(path, riff)
|
|
76
|
+
|
|
77
|
+
vma_wav_fix_header!(path)
|
|
78
|
+
|
|
79
|
+
fixed = File.binread(path)
|
|
80
|
+
riff_sz = fixed[4, 4].unpack1("V")
|
|
81
|
+
data_sz = fixed[44 - 4, 4].unpack1("V")
|
|
82
|
+
assert_eq fixed.bytesize - 8, riff_sz, "RIFF size not finalized"
|
|
83
|
+
assert_eq fixed.bytesize - 44, data_sz, "data size not finalized"
|
|
84
|
+
ensure
|
|
85
|
+
File.delete(path) if path && File.exist?(path)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# PCM tail-slicing: a WAV written by vma_write_wav can be located and split into
|
|
89
|
+
# PCM halves that recombine to the original — the basis of the incremental pass.
|
|
90
|
+
def test_pcm_tail_slice
|
|
91
|
+
load_dictation
|
|
92
|
+
pcm = (0...4000).map { |i| (i % 256) - 128 }.pack("s<*") # 2000 frames S16LE
|
|
93
|
+
path = File.join(Dir.tmpdir, "vma_dict_slice_#{Process.pid}.wav")
|
|
94
|
+
vma_write_wav(path, pcm)
|
|
95
|
+
|
|
96
|
+
bytes = File.binread(path)
|
|
97
|
+
doff = vma_wav_data_offset(bytes)
|
|
98
|
+
assert !doff.nil?, "data offset not found"
|
|
99
|
+
assert_eq pcm.bytesize, bytes.bytesize - doff, "data size mismatch"
|
|
100
|
+
|
|
101
|
+
half = doff + (pcm.bytesize / 2 / DICT_FRAME) * DICT_FRAME
|
|
102
|
+
a = bytes[doff...half]
|
|
103
|
+
b = bytes[half...bytes.bytesize]
|
|
104
|
+
assert_eq pcm, a + b, "sliced PCM does not recombine to original"
|
|
105
|
+
ensure
|
|
106
|
+
File.delete(path) if path && File.exist?(path)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# --- status indicator ---
|
|
110
|
+
|
|
111
|
+
# The generic status slot the module drives: set, replace, and clear.
|
|
112
|
+
def test_status_indicator_slot
|
|
113
|
+
vma.gui.set_status_indicator(:_test_slot, "WORKING…", css_class: "status-busy")
|
|
114
|
+
assert_eq "WORKING…", vma.gui.status_indicator(:_test_slot)
|
|
115
|
+
|
|
116
|
+
vma.gui.set_status_indicator(:_test_slot, "DONE", css_class: "status-active")
|
|
117
|
+
assert_eq "DONE", vma.gui.status_indicator(:_test_slot)
|
|
118
|
+
|
|
119
|
+
vma.gui.set_status_indicator(:_test_slot, nil)
|
|
120
|
+
assert_eq nil, vma.gui.status_indicator(:_test_slot), "slot should be gone once cleared"
|
|
121
|
+
ensure
|
|
122
|
+
vma.gui.set_status_indicator(:_test_slot, nil)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Every phase must map to text, or the user gets a blank badge mid-dictation.
|
|
126
|
+
def test_status_phases_all_have_text
|
|
127
|
+
load_dictation
|
|
128
|
+
%i[loading listening transcribing failed].each do |phase|
|
|
129
|
+
text, css = VmaDictationSession::STATUS_PHASES[phase]
|
|
130
|
+
assert !text.to_s.empty?, "phase #{phase} has no text"
|
|
131
|
+
assert !css.to_s.empty?, "phase #{phase} has no css class"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# --- model selection ---
|
|
136
|
+
|
|
137
|
+
# Applying a preset must set the language too: a Finnish model left on "en"
|
|
138
|
+
# transcribes badly and nothing in the UI would show the mismatch.
|
|
139
|
+
def test_apply_model_sets_model_and_language
|
|
140
|
+
load_dictation
|
|
141
|
+
prev_model = cnf.dictation.model!
|
|
142
|
+
prev_lang = cnf.dictation.language!
|
|
143
|
+
|
|
144
|
+
vma_dict_apply_model("Finnish-NLP/whisper-large-finnish-v3-ct2", "fi")
|
|
145
|
+
assert_eq "Finnish-NLP/whisper-large-finnish-v3-ct2", cnf.dictation.model!
|
|
146
|
+
assert_eq "fi", cnf.dictation.language!
|
|
147
|
+
ensure
|
|
148
|
+
cnf.dictation.model = prev_model
|
|
149
|
+
cnf.dictation.language = prev_lang
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# A blank id must not wipe the current model.
|
|
153
|
+
def test_apply_model_ignores_blank
|
|
154
|
+
load_dictation
|
|
155
|
+
cnf.dictation.model = "large-v3"
|
|
156
|
+
vma_dict_apply_model(" ", "fi")
|
|
157
|
+
assert_eq "large-v3", cnf.dictation.model!, "blank model id should be ignored"
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# The Finnish model the presets are built around must be offered, with "fi".
|
|
161
|
+
def test_model_presets_include_finnish
|
|
162
|
+
load_dictation
|
|
163
|
+
entry = VMA_DICT_MODELS.find { |id, _l, _lang| id == "Finnish-NLP/whisper-large-finnish-v3-ct2" }
|
|
164
|
+
assert !entry.nil?, "Finnish large-v3 preset missing"
|
|
165
|
+
assert_eq "fi", entry[2], "Finnish preset should select the fi language"
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# --- cold start (model not loaded yet) ---
|
|
169
|
+
|
|
170
|
+
# A worker that hasn't loaded its model reports itself not ready, so the
|
|
171
|
+
# preliminary passes skip themselves instead of queueing on the worker mutex
|
|
172
|
+
# and stalling the final pass behind the load.
|
|
173
|
+
def test_worker_not_ready_before_model_loads
|
|
174
|
+
load_dictation
|
|
175
|
+
w = VmaWhisperWorker.new
|
|
176
|
+
assert_eq false, w.ready?, "a freshly built worker should not claim to be ready"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# A worker that never becomes ready must fail the request rather than block
|
|
180
|
+
# forever: an unbounded wait leaves every later request stuck behind it with
|
|
181
|
+
# the editor sitting on "finalizing…" and nothing to report.
|
|
182
|
+
def test_await_ready_gives_up_instead_of_hanging
|
|
183
|
+
load_dictation
|
|
184
|
+
prev = cnf.dictation.startup_timeout!
|
|
185
|
+
cnf.dictation.startup_timeout = 1
|
|
186
|
+
|
|
187
|
+
r, wr = IO.pipe # nothing is ever written -> never becomes ready
|
|
188
|
+
blocked = Thread.new { sleep 30 }
|
|
189
|
+
w = VmaWhisperWorker.new
|
|
190
|
+
w.instance_variable_set(:@stdout, r)
|
|
191
|
+
w.instance_variable_set(:@stdin, wr)
|
|
192
|
+
w.instance_variable_set(:@wait, blocked) # looks alive, so no respawn
|
|
193
|
+
|
|
194
|
+
t0 = Time.now
|
|
195
|
+
res = w.transcribe("/nonexistent.wav")
|
|
196
|
+
elapsed = Time.now - t0
|
|
197
|
+
|
|
198
|
+
assert_eq false, res[:ok], "transcribe should fail when the model never loads"
|
|
199
|
+
assert res[:error].to_s.include?("no progress"), "unexpected error: #{res[:error].inspect}"
|
|
200
|
+
assert elapsed < 10, "transcribe blocked #{elapsed.round(1)}s; should give up after the timeout"
|
|
201
|
+
ensure
|
|
202
|
+
cnf.dictation.startup_timeout = prev
|
|
203
|
+
blocked&.kill
|
|
204
|
+
r&.close
|
|
205
|
+
wr&.close
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# The span-replace approach: insert preliminary chunks into a buffer, then
|
|
209
|
+
# delete the whole tracked span and insert the final text in its place.
|
|
210
|
+
def test_span_replace
|
|
211
|
+
load_dictation
|
|
212
|
+
start = 0 # fresh test buffer is "\n"; dictate at the beginning
|
|
213
|
+
|
|
214
|
+
# Simulate preliminary inserts, tracking the span length.
|
|
215
|
+
len = 0
|
|
216
|
+
["hello", "there", "world"].each do |chunk|
|
|
217
|
+
t = (len > 0 ? " " : "") + chunk
|
|
218
|
+
act("buf.insert_txt_at(#{t.inspect}, #{start + len})")
|
|
219
|
+
len += t.size
|
|
220
|
+
end
|
|
221
|
+
assert_buf "hello there world\n", "preliminary text not assembled"
|
|
222
|
+
|
|
223
|
+
# Replace the whole span with the final transcript.
|
|
224
|
+
act("buf.delete_range(#{start}, #{start + len - 1})")
|
|
225
|
+
act("buf.insert_txt_at('Hello, there, world.', #{start})")
|
|
226
|
+
assert_buf "Hello, there, world.\n", "final replacement incorrect"
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
# --- dictation keyboard mode (no microphone / recorder involved) ---
|
|
230
|
+
|
|
231
|
+
def test_mode_actions_registered
|
|
232
|
+
ensure_disabled
|
|
233
|
+
load_dictation
|
|
234
|
+
dictation_init
|
|
235
|
+
["dictation.enter_mode", "dictation.toggle_stay",
|
|
236
|
+
"dictation.newline", "dictation.exit_mode"].each do |a|
|
|
237
|
+
assert vma.actions.include?(a), "#{a} not registered after init"
|
|
238
|
+
end
|
|
239
|
+
dictation_disable
|
|
240
|
+
["dictation.enter_mode", "dictation.toggle_stay",
|
|
241
|
+
"dictation.newline", "dictation.exit_mode"].each do |a|
|
|
242
|
+
assert !vma.actions.include?(a), "#{a} still registered after disable"
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# The menu item runs "dictation.enter_mode"; clicked while already in the
|
|
247
|
+
# mode it leaves the mode instead (session not active: no recorder starts).
|
|
248
|
+
def test_enter_mode_action_exits_when_in_mode
|
|
249
|
+
ensure_disabled
|
|
250
|
+
load_dictation
|
|
251
|
+
dictation_init
|
|
252
|
+
vma.kbd.set_mode(:dictation)
|
|
253
|
+
assert_eq :dictation, vma.kbd.get_mode
|
|
254
|
+
act("dictation.enter_mode")
|
|
255
|
+
assert_eq :command, vma.kbd.get_mode, "menu toggle did not leave dictation mode"
|
|
256
|
+
ensure
|
|
257
|
+
vma.kbd.set_mode(:command)
|
|
258
|
+
dictation_disable
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# The mode is a minor mode that inherits command mode, and exiting returns to
|
|
262
|
+
# the previous mode. Drive the mode machinery directly so no recorder starts.
|
|
263
|
+
def test_mode_enter_inherits_and_exit
|
|
264
|
+
ensure_disabled
|
|
265
|
+
load_dictation
|
|
266
|
+
dictation_init
|
|
267
|
+
vma.kbd.set_mode(:command)
|
|
268
|
+
vma.kbd.set_mode(:dictation)
|
|
269
|
+
assert_eq :dictation, vma.kbd.get_mode, "did not enter dictation mode"
|
|
270
|
+
assert vma.kbd.mode_root_state.major_modes.include?(:command),
|
|
271
|
+
"dictation mode should inherit command mode"
|
|
272
|
+
# Session is inactive, so exit is just a mode pop back to command.
|
|
273
|
+
assert !dictation_session.active?, "no dictation should be active in this test"
|
|
274
|
+
dictation_exit_mode
|
|
275
|
+
assert_eq :command, vma.kbd.get_mode, "did not return to command mode on exit"
|
|
276
|
+
ensure
|
|
277
|
+
vma.kbd.set_mode(:command)
|
|
278
|
+
dictation_disable
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Enter with no active dictation just inserts a newline at the cursor.
|
|
282
|
+
def test_newline_when_inactive_inserts_newline
|
|
283
|
+
ensure_disabled
|
|
284
|
+
load_dictation
|
|
285
|
+
dictation_init
|
|
286
|
+
act("buf.insert_txt_at('abc', 0)") # fresh buffer "\n" -> "abc\n"
|
|
287
|
+
act("buf.set_pos(3)") # end of "abc", before the trailing "\n"
|
|
288
|
+
assert !dictation_session.active?, "precondition: no active dictation"
|
|
289
|
+
act("dictation.newline")
|
|
290
|
+
assert_buf "abc\n\n", "Enter should insert a newline when not dictating"
|
|
291
|
+
ensure
|
|
292
|
+
dictation_disable
|
|
293
|
+
end
|
|
294
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
require "fileutils"
|
|
3
|
+
|
|
4
|
+
# Buffers produced by the diff actions are named after what they diff, with
|
|
5
|
+
# "diff" in the name, instead of the generic "*buf-N*".
|
|
6
|
+
class TestDiffBufferName < VmaTest
|
|
7
|
+
|
|
8
|
+
# Temp git repo with one committed file that is then modified on disk.
|
|
9
|
+
def with_dirty_repo
|
|
10
|
+
dir = Dir.mktmpdir("vma_diffname")
|
|
11
|
+
repo = File.join(dir, "myrepo")
|
|
12
|
+
Dir.mkdir(repo)
|
|
13
|
+
path = File.join(repo, "notes.txt")
|
|
14
|
+
File.write(path, "one\ntwo\n")
|
|
15
|
+
system("git", "-C", repo, "init", "-q")
|
|
16
|
+
system("git", "-C", repo, "add", "notes.txt")
|
|
17
|
+
system("git", "-C", repo, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "init")
|
|
18
|
+
File.write(path, "one\nTWO\n")
|
|
19
|
+
yield repo, path
|
|
20
|
+
ensure
|
|
21
|
+
FileUtils.rm_rf(dir) if dir
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_git_diff_buffer_name
|
|
25
|
+
return skip("git not installed") unless system("which git >/dev/null 2>&1")
|
|
26
|
+
with_dirty_repo do |repo, path|
|
|
27
|
+
jump_to_file(path, 1)
|
|
28
|
+
git_diff_buffer
|
|
29
|
+
assert_eq "*gitdiff-notes.txt-#{vma.buf.id}*", vma.buf.list_str
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_git_diff_w_name
|
|
34
|
+
return skip("git not installed") unless system("which git >/dev/null 2>&1")
|
|
35
|
+
with_dirty_repo do |repo, path|
|
|
36
|
+
jump_to_file(path, 1)
|
|
37
|
+
git_diff_w
|
|
38
|
+
assert_eq "*gitdiff-myrepo-#{vma.buf.id}*", vma.buf.list_str
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_unsaved_diff_name
|
|
43
|
+
return skip("diff not installed") unless system("which diff >/dev/null 2>&1")
|
|
44
|
+
with_dirty_repo do |repo, path|
|
|
45
|
+
jump_to_file(path, 1)
|
|
46
|
+
vma.buf.insert_txt("x")
|
|
47
|
+
diff_buffer
|
|
48
|
+
assert_eq "*diff-unsaved-notes.txt-#{vma.buf.id}*", vma.buf.list_str
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# "." repeats the last change (dot_repeat.rb, doc/vim_compatibility_plan.md
|
|
2
|
+
# step 4). The vim keymap has oracle tests against real vim in
|
|
3
|
+
# test_vim_bindings.rb.
|
|
4
|
+
class TestDotRepeat < VmaTest
|
|
5
|
+
def setup_text(s, pos = 0)
|
|
6
|
+
buf.set_content(s)
|
|
7
|
+
buf.set_pos(pos)
|
|
8
|
+
vma.kbd.set_mode(:command)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_repeat_delete
|
|
12
|
+
setup_text("a b c d\n")
|
|
13
|
+
keys("d w .")
|
|
14
|
+
assert_buf "c d\n"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def test_repeat_change_with_typed_text
|
|
18
|
+
setup_text("one two three\n")
|
|
19
|
+
keys("c w f o o esc w .")
|
|
20
|
+
assert_buf "foo foo three\n"
|
|
21
|
+
assert_mode :command
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_repeat_insert
|
|
25
|
+
setup_text("ab\n")
|
|
26
|
+
keys("i x y esc 0 .")
|
|
27
|
+
assert_buf "xyxyab\n"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_count_replaces_the_changes_count
|
|
31
|
+
setup_text("a b c d e\n")
|
|
32
|
+
keys("d w 2 .")
|
|
33
|
+
assert_buf "d e\n"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_repeat_is_one_undo_step
|
|
37
|
+
setup_text("one two three\n")
|
|
38
|
+
keys("c w f o o esc w .")
|
|
39
|
+
keys("u")
|
|
40
|
+
assert_buf "foo two three\n"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_motions_dont_replace_the_change
|
|
44
|
+
setup_text("a b c d e\n")
|
|
45
|
+
keys("d w w .")
|
|
46
|
+
assert_buf "b d e\n"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_repeat_uses_the_same_register
|
|
50
|
+
setup_text("1\n2\n3\n")
|
|
51
|
+
keys('" a d d .')
|
|
52
|
+
assert_buf "3\n"
|
|
53
|
+
assert_eq "2\n", vma.registers["a"].text
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_repeat_indent_and_case
|
|
57
|
+
setup_text("a\n")
|
|
58
|
+
keys("> > .")
|
|
59
|
+
assert_buf "\t\ta\n"
|
|
60
|
+
setup_text("foo bar\n")
|
|
61
|
+
keys("g U w w .")
|
|
62
|
+
assert_buf "FOO BAR\n"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_nothing_to_repeat
|
|
66
|
+
vma.dot.instance_variable_set(:@last, nil)
|
|
67
|
+
setup_text("abc\n")
|
|
68
|
+
keys(".")
|
|
69
|
+
assert_buf "abc\n"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# cnf.undo.insert_one_step: a pause while typing doesn't split the undo step
|
|
73
|
+
def test_insert_session_undo_step
|
|
74
|
+
saved = cnf.undo.insert_one_step?
|
|
75
|
+
[[true, "x\n"], [false, "abx\n"]].each { |one_step, after_undo|
|
|
76
|
+
cnf.undo.insert_one_step = one_step
|
|
77
|
+
setup_text("x\n")
|
|
78
|
+
keys("i a b")
|
|
79
|
+
buf.instance_variable_set(:@last_delta_time, Time.now - 60) # a long pause
|
|
80
|
+
keys("c d esc")
|
|
81
|
+
assert_buf "abcdx\n"
|
|
82
|
+
keys("u")
|
|
83
|
+
assert_buf after_undo, "insert_one_step=#{one_step}"
|
|
84
|
+
}
|
|
85
|
+
ensure
|
|
86
|
+
cnf.undo.insert_one_step = saved
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Double-clicking a line runs the buffer's line action, like Enter.
|
|
2
|
+
class TestDoubleClick < VmaTest
|
|
3
|
+
def dbl_click(pos)
|
|
4
|
+
v = vma.buf.view
|
|
5
|
+
x, y = v.pos_to_coord(pos)
|
|
6
|
+
v.instance_variable_get(:@click).signal_emit("pressed", 2, x + 2, y + 4)
|
|
7
|
+
drain_idle
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Ack (grep) result buffers set a handler that takes the line number;
|
|
11
|
+
# double-click used to call module.select_line without it and crash.
|
|
12
|
+
def test_calls_line_action_handler_with_line
|
|
13
|
+
b = vma.buf
|
|
14
|
+
b.set_content("first\nsecond\nthird\n")
|
|
15
|
+
drain_idle
|
|
16
|
+
got = nil
|
|
17
|
+
mod = Object.new
|
|
18
|
+
def mod.select_line(lineno) = raise("select_line called without the handler")
|
|
19
|
+
b.module = mod
|
|
20
|
+
b.line_action_handler = proc { |l| got = l }
|
|
21
|
+
dbl_click("first\nsecond\n".size + 1)
|
|
22
|
+
assert_eq 2, got
|
|
23
|
+
ensure
|
|
24
|
+
b.module = nil
|
|
25
|
+
b.line_action_handler = nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_module_select_line_without_args
|
|
29
|
+
b = vma.buf
|
|
30
|
+
b.set_content("a\nb\n")
|
|
31
|
+
drain_idle
|
|
32
|
+
called = false
|
|
33
|
+
mod = Object.new
|
|
34
|
+
mod.define_singleton_method(:select_line) { called = true }
|
|
35
|
+
b.module = mod
|
|
36
|
+
dbl_click(2)
|
|
37
|
+
assert called, "module.select_line not called"
|
|
38
|
+
ensure
|
|
39
|
+
b.module = nil
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Dragging selected text with the mouse moves it (cnf.mouse.drag_selection).
|
|
2
|
+
# The gestures are driven by emitting the controllers' signals directly.
|
|
3
|
+
class TestDragSelection < VmaTest
|
|
4
|
+
TEXT = "alpha beta gamma\nsecond line\n"
|
|
5
|
+
|
|
6
|
+
def setup_sel(from, len)
|
|
7
|
+
b = vma.buf
|
|
8
|
+
b.set_content(TEXT)
|
|
9
|
+
drain_idle
|
|
10
|
+
b.set_pos(from)
|
|
11
|
+
keys("v")
|
|
12
|
+
b.set_pos(from + len - 1)
|
|
13
|
+
drain_idle
|
|
14
|
+
b
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Widget coords of the middle of the char at offset
|
|
18
|
+
def xy(pos)
|
|
19
|
+
v = vma.buf.view
|
|
20
|
+
x, y = v.pos_to_coord(pos)
|
|
21
|
+
[x + 2, y + 4]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Press at offset from, release at offset to (or at from, a plain click)
|
|
25
|
+
def drag(from, to)
|
|
26
|
+
v = vma.buf.view
|
|
27
|
+
x, y = xy(from)
|
|
28
|
+
tx, ty = xy(to)
|
|
29
|
+
v.instance_variable_get(:@click).signal_emit("pressed", 1, x, y)
|
|
30
|
+
d = v.instance_variable_get(:@cnt_drag)
|
|
31
|
+
d.signal_emit("drag-begin", x, y)
|
|
32
|
+
if [x, y] != [tx, ty]
|
|
33
|
+
d.signal_emit("drag-update", tx - x, ty - y)
|
|
34
|
+
@marker_during_drag = v.drop_marker_pos
|
|
35
|
+
@marker_widget = v.instance_variable_get(:@drop_marker)
|
|
36
|
+
end
|
|
37
|
+
v.instance_variable_get(:@click).signal_emit("released", 1, tx, ty) if [x, y] == [tx, ty]
|
|
38
|
+
d.signal_emit("drag-end", tx - x, ty - y)
|
|
39
|
+
drain_idle
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def with_setting(val)
|
|
43
|
+
old = cnf.mouse.drag_selection?
|
|
44
|
+
cnf.mouse.drag_selection = val
|
|
45
|
+
yield
|
|
46
|
+
ensure
|
|
47
|
+
cnf.mouse.drag_selection = old
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_move_text_forward_and_back
|
|
51
|
+
b = vma.buf
|
|
52
|
+
b.set_content("abc def ghi\n")
|
|
53
|
+
assert_eq 4..6, b.move_text(0..2, 7) # "abc" before " ghi"
|
|
54
|
+
assert_buf " defabc ghi\n"
|
|
55
|
+
assert_eq 0..2, b.move_text(4..6, 0)
|
|
56
|
+
assert_buf "abc def ghi\n"
|
|
57
|
+
assert_eq nil, b.move_text(0..2, 3) # right after itself: no-op
|
|
58
|
+
assert_eq nil, b.move_text(0..2, 1) # inside itself
|
|
59
|
+
assert_buf "abc def ghi\n"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_move_text_is_one_undo_step
|
|
63
|
+
b = vma.buf
|
|
64
|
+
b.set_content("abc def ghi\n")
|
|
65
|
+
b.move_text(0..2, 8)
|
|
66
|
+
assert_buf " def abcghi\n"
|
|
67
|
+
b.undo
|
|
68
|
+
assert_buf "abc def ghi\n"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_drag_moves_selection
|
|
72
|
+
with_setting(true) do
|
|
73
|
+
b = setup_sel(TEXT.index("beta"), 5) # "beta "
|
|
74
|
+
assert_mode :visual
|
|
75
|
+
drag(TEXT.index("beta") + 1, TEXT.index("line"))
|
|
76
|
+
assert_eq TEXT.index("line"), @marker_during_drag, "drop marker not at drop point"
|
|
77
|
+
assert !@marker_widget.visible?, "drop marker still shown after the drop"
|
|
78
|
+
assert_buf "alpha gamma\nsecond beta line\n"
|
|
79
|
+
assert !b.visual_mode?, "selection still active after the drop"
|
|
80
|
+
assert_mode :command
|
|
81
|
+
assert_eq "alpha gamma\nsecond ".size, b.pos # at the moved text's start
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Right half of a char drops after it; past the end of a line drops before "\n"
|
|
86
|
+
def test_drop_pos_snaps_to_nearest_boundary
|
|
87
|
+
b = vma.buf
|
|
88
|
+
b.set_content(TEXT)
|
|
89
|
+
drain_idle
|
|
90
|
+
v = b.view
|
|
91
|
+
x, y = v.pos_to_coord(1)
|
|
92
|
+
w = v.get_iter_location(v.buffer.get_iter_at(:offset => 1)).width
|
|
93
|
+
assert_eq 1, v.drop_pos(x + 1, y + 4)
|
|
94
|
+
assert_eq 2, v.drop_pos(x + w - 1, y + 4)
|
|
95
|
+
assert_eq TEXT.index("\n"), v.drop_pos(x + 500, y + 4)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_no_marker_when_drop_would_not_move
|
|
99
|
+
with_setting(true) do
|
|
100
|
+
b = setup_sel(TEXT.index("beta"), 5)
|
|
101
|
+
drag(TEXT.index("beta") + 1, TEXT.index("beta") + 3)
|
|
102
|
+
assert_eq nil, @marker_during_drag
|
|
103
|
+
assert_buf TEXT
|
|
104
|
+
assert !b.visual_mode?, "selection still active after the drop"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def test_click_inside_selection_clears_it
|
|
109
|
+
with_setting(true) do
|
|
110
|
+
b = setup_sel(TEXT.index("beta"), 5)
|
|
111
|
+
drag(TEXT.index("beta") + 2, TEXT.index("beta") + 2)
|
|
112
|
+
assert_buf TEXT
|
|
113
|
+
assert !b.visual_mode?, "selection still active"
|
|
114
|
+
assert_pos 0, TEXT.index("beta") + 2
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_disabled_drag_starts_new_selection
|
|
119
|
+
with_setting(false) do
|
|
120
|
+
b = setup_sel(TEXT.index("beta"), 5)
|
|
121
|
+
drag(TEXT.index("beta") + 1, TEXT.index("line"))
|
|
122
|
+
assert_buf TEXT
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|