vimamsa 0.1.26 → 0.1.27
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 +62 -16
- data/custom_example.rb +43 -13
- data/doc/TODO.md +461 -0
- data/doc/bundling_plan.md +569 -0
- data/doc/key_bindings_report_plan.md +168 -0
- data/doc/missing_vim_bindings.md +71 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +296 -0
- data/doc/vimlike_vim_conflicts.md +254 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/exe/run_tests.rb +117 -3
- data/exe/vimamsa +24 -4
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/lang/hyperplaintext.lang +6 -0
- data/lib/vimamsa/ack.rb +11 -1
- data/lib/vimamsa/actions.rb +4 -1
- 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 +593 -82
- data/lib/vimamsa/buffer_changetext.rb +102 -42
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +4 -0
- data/lib/vimamsa/buffer_manager.rb +4 -1
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/clipboard.rb +3 -0
- data/lib/vimamsa/conf.rb +59 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +4 -1
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +39 -10
- data/lib/vimamsa/easy_jump.rb +3 -0
- data/lib/vimamsa/editor.rb +263 -57
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +3 -0
- data/lib/vimamsa/file_manager.rb +30 -15
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/gui.rb +520 -106
- data/lib/vimamsa/gui_command_line.rb +208 -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 +59 -35
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_keylog_panel.rb +246 -0
- data/lib/vimamsa/gui_menu.rb +23 -11
- data/lib/vimamsa/gui_select_window.rb +19 -48
- data/lib/vimamsa/gui_settings.rb +78 -37
- data/lib/vimamsa/gui_sourceview.rb +273 -19
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +606 -0
- data/lib/vimamsa/hook.rb +3 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/key_actions.rb +112 -13
- data/lib/vimamsa/key_binding_tree.rb +242 -215
- data/lib/vimamsa/key_bindings_notepad.rb +43 -0
- data/lib/vimamsa/key_bindings_report.rb +261 -0
- data/lib/vimamsa/key_bindings_vim.rb +354 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +65 -9
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/macro.rb +3 -0
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +26 -1
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +11 -10
- data/lib/vimamsa/string_util.rb +120 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +3 -0
- data/lib/vimamsa/text_objects.rb +353 -0
- data/lib/vimamsa/text_transforms.rb +14 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +0 -1
- 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/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.sh +130 -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_steps.txt +59 -0
- data/scripts/demo/record_demo.rb +177 -0
- data/scripts/demo/shapes.rb +28 -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_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 +33 -3
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +85 -0
- data/tests/test_bundling.rb +92 -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 +129 -0
- data/tests/test_copy_paste.rb +80 -0
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -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_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_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_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_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_keylog_panel.rb +101 -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_notepad_bindings.rb +67 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_revert.rb +127 -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 +329 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_vim_bindings.rb +252 -0
- data/tests/test_vim_conflicts.rb +63 -0
- data/tests/test_window_layout.rb +219 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +109 -0
- metadata +112 -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?("not loaded"), "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,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
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require_relative "support/virtual_keyboard"
|
|
2
|
+
|
|
3
|
+
# True end-to-end test of the ":" command line: a uinput virtual keyboard types
|
|
4
|
+
# real key events (kernel -> compositor -> this GTK window), verifying that
|
|
5
|
+
# focus enters the command line entry — via the @entry_has_focus bypass in the
|
|
6
|
+
# window key controller — and that a shell command executes into a new buffer.
|
|
7
|
+
#
|
|
8
|
+
# Skips when /dev/uinput is not writable, xmodmap is missing, or the editor
|
|
9
|
+
# window is not the focused window (never type into someone else's window).
|
|
10
|
+
class TestE2eCmdline < VmaTest
|
|
11
|
+
def test_colon_focuses_cmdline_and_executes_shell_command
|
|
12
|
+
with_vkb do |kb|
|
|
13
|
+
assert_mode :command
|
|
14
|
+
orig_buf_id = vma.buf.id
|
|
15
|
+
orig_text = vma.buf.to_s
|
|
16
|
+
|
|
17
|
+
kb.type(":")
|
|
18
|
+
assert wait_until(3) { stack.visible_child_name == "cmdline" },
|
|
19
|
+
"':' key opens the command line"
|
|
20
|
+
assert focus_inside?(vma.gui.cmd_line.entry),
|
|
21
|
+
"keyboard focus is inside the command line entry"
|
|
22
|
+
|
|
23
|
+
kb.type("!ls")
|
|
24
|
+
assert wait_until(3) { vma.gui.cmd_line.entry.text == "!ls" },
|
|
25
|
+
"typed keys land in the entry (entry has #{vma.gui.cmd_line.entry.text.inspect})"
|
|
26
|
+
assert_eq orig_text, vma.buf.to_s, "editor buffer untouched while typing in the command line"
|
|
27
|
+
|
|
28
|
+
kb.tap_keysym("Return")
|
|
29
|
+
ok = wait_until(5) {
|
|
30
|
+
vma.buf.id != orig_buf_id &&
|
|
31
|
+
Dir.children(Dir.pwd).any? { |f| vma.buf.to_s.include?(f) }
|
|
32
|
+
}
|
|
33
|
+
assert ok, "!ls output opened in a new buffer (current buffer starts: #{vma.buf.to_s[0, 80].inspect})"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_escape_closes_and_returns_focus_to_editor
|
|
38
|
+
with_vkb do |kb|
|
|
39
|
+
assert_mode :command
|
|
40
|
+
kb.type(":")
|
|
41
|
+
assert wait_until(3) { stack.visible_child_name == "cmdline" },
|
|
42
|
+
"':' key opens the command line"
|
|
43
|
+
|
|
44
|
+
kb.tap_keysym("Escape")
|
|
45
|
+
assert wait_until(3) { stack.visible_child_name != "cmdline" },
|
|
46
|
+
"Escape closes the command line"
|
|
47
|
+
assert !focus_inside?(vma.gui.cmd_line.entry), "focus left the entry"
|
|
48
|
+
|
|
49
|
+
# Keys must reach the editor again: 'i' should enter insert mode
|
|
50
|
+
kb.type("i")
|
|
51
|
+
assert wait_until(3) { vma.kbd.get_mode == :insert }, "editor receives keys again after Escape"
|
|
52
|
+
keys("esc")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
# Guard preconditions, open/close the uinput device around the block.
|
|
59
|
+
def with_vkb
|
|
60
|
+
# uinput events go to the real seat's focused window. Only type when this
|
|
61
|
+
# app is itself on the real Wayland session — never on a headless backend
|
|
62
|
+
# (Broadway/Xvfb), where the keystrokes would land in some other program.
|
|
63
|
+
# gtype.name: ruby-gnome has no named Ruby class for some backends.
|
|
64
|
+
backend = Gdk::Display.default&.gtype&.name.to_s
|
|
65
|
+
if !backend.include?("Wayland")
|
|
66
|
+
skip "not on a real Wayland seat (#{backend})"
|
|
67
|
+
end
|
|
68
|
+
skip "no writable /dev/uinput" if !VirtualKeyboard.available?
|
|
69
|
+
skip "xmodmap not available" if !KeyTyper.available?
|
|
70
|
+
vkb = nil
|
|
71
|
+
vma.gui.window.present
|
|
72
|
+
# Wayland won't let a non-interactively launched window steal focus. In the
|
|
73
|
+
# semi-interactive VM mode (VMA_E2E_INTERACTIVE), wait longer and prompt for a
|
|
74
|
+
# single click; a real user click legitimately focuses the window, after which
|
|
75
|
+
# every following test in the run finds it already active (no more clicks).
|
|
76
|
+
focus_wait = ENV["VMA_E2E_INTERACTIVE"] ? 90 : 3
|
|
77
|
+
if ENV["VMA_E2E_INTERACTIVE"] && !vma.gui.window.active?
|
|
78
|
+
puts "\n>>> [E2E] Click the vimamsa window in the VM to give it focus " \
|
|
79
|
+
"(waiting up to #{focus_wait}s)…"
|
|
80
|
+
$stdout.flush
|
|
81
|
+
end
|
|
82
|
+
if !wait_until(focus_wait) { vma.gui.window.active? }
|
|
83
|
+
skip "editor window is not focused; typing would go to another window"
|
|
84
|
+
end
|
|
85
|
+
vkb = VirtualKeyboard.new.open
|
|
86
|
+
yield KeyTyper.new(vkb)
|
|
87
|
+
ensure
|
|
88
|
+
vkb&.close
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Poll cond while letting the GTK main loop process the incoming key events.
|
|
92
|
+
def wait_until(timeout)
|
|
93
|
+
t0 = Time.now
|
|
94
|
+
loop do
|
|
95
|
+
drain_idle
|
|
96
|
+
return true if yield
|
|
97
|
+
return false if Time.now - t0 > timeout
|
|
98
|
+
sleep 0.05
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def stack
|
|
103
|
+
vma.gui.instance_variable_get(:@minibuf_stack)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# True if the window's focus widget is `widget` or one of its descendants
|
|
107
|
+
# (Gtk::Entry keeps focus on an internal GtkText child).
|
|
108
|
+
def focus_inside?(widget)
|
|
109
|
+
f = vma.gui.window.focus_widget
|
|
110
|
+
while f
|
|
111
|
+
return true if f == widget
|
|
112
|
+
f = f.parent
|
|
113
|
+
end
|
|
114
|
+
false
|
|
115
|
+
end
|
|
116
|
+
end
|