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,79 @@
|
|
|
1
|
+
class TestCommandLine < VmaTest
|
|
2
|
+
def cl
|
|
3
|
+
vma.gui.cmd_line
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def last_message
|
|
7
|
+
vma.gui.instance_variable_get(:@minibuf_messages).first.to_s
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_ruby_eval_echoes_result
|
|
11
|
+
cl.execute("21 * 2")
|
|
12
|
+
drain_idle
|
|
13
|
+
assert last_message.include?("=> 42"), "eval result echoed, got: #{last_message.inspect}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_ruby_can_edit_buffer
|
|
17
|
+
cl.execute("buf.insert_txt('hello')")
|
|
18
|
+
drain_idle
|
|
19
|
+
assert_buf "hello\n"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_config_change_via_ruby
|
|
23
|
+
prev = cnf.tab.width!
|
|
24
|
+
cl.execute("cnf.tab.width = 8")
|
|
25
|
+
assert_eq 8, cnf.tab.width!, "config changed via command line"
|
|
26
|
+
ensure
|
|
27
|
+
cnf.tab.width = prev
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_ruby_error_is_caught
|
|
31
|
+
cl.execute("nonexistent_method_xyz_123")
|
|
32
|
+
drain_idle
|
|
33
|
+
assert last_message.include?("ERROR:"), "error shown, got: #{last_message.inspect}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_ruby_syntax_error_is_caught
|
|
37
|
+
cl.execute("def broken(")
|
|
38
|
+
drain_idle
|
|
39
|
+
assert last_message.include?("ERROR:"), "syntax error shown, got: #{last_message.inspect}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_bare_number_jumps_to_line
|
|
43
|
+
vma.buf.set_content("one\ntwo\nthree\nfour\nfive\n")
|
|
44
|
+
drain_idle
|
|
45
|
+
cl.execute("3")
|
|
46
|
+
drain_idle
|
|
47
|
+
assert_eq 2, vma.buf.lpos, "jumped to line 3 (lpos 2)"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_shell_command_output_to_buffer
|
|
51
|
+
cl.execute("!echo vmatest_shell_output")
|
|
52
|
+
found = false
|
|
53
|
+
50.times do
|
|
54
|
+
drain_idle
|
|
55
|
+
if vma.buf.to_s.include?("vmatest_shell_output")
|
|
56
|
+
found = true
|
|
57
|
+
break
|
|
58
|
+
end
|
|
59
|
+
sleep 0.1
|
|
60
|
+
end
|
|
61
|
+
assert found, "shell output opened in a new buffer"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_history_records_commands
|
|
65
|
+
cl.execute("1 + 1")
|
|
66
|
+
cl.execute("2 + 2")
|
|
67
|
+
assert_eq "2 + 2", cl.history.last, "newest command last in history"
|
|
68
|
+
assert cl.history.include?("1 + 1"), "older command kept in history"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_open_and_close
|
|
72
|
+
act :start_cmd_line
|
|
73
|
+
stack = vma.gui.instance_variable_get(:@minibuf_stack)
|
|
74
|
+
assert_eq "cmdline", stack.visible_child_name, "command line shown"
|
|
75
|
+
cl.close
|
|
76
|
+
drain_idle
|
|
77
|
+
assert stack.visible_child_name != "cmdline", "command line hidden after close"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
|
|
3
|
+
class TestCommandLineFile < VmaTest
|
|
4
|
+
def test_missing_command_line_file_is_not_created
|
|
5
|
+
Dir.mktmpdir do |dir|
|
|
6
|
+
path = File.join(dir, "created.txt")
|
|
7
|
+
|
|
8
|
+
result = open_new_file(path)
|
|
9
|
+
|
|
10
|
+
assert !result, "opening a missing file should not return a buffer"
|
|
11
|
+
assert !File.exist?(path), "missing command-line path should not be created"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_existing_command_line_file_keeps_its_contents
|
|
16
|
+
Dir.mktmpdir do |dir|
|
|
17
|
+
path = File.join(dir, "existing.txt")
|
|
18
|
+
File.write(path, "existing contents\n")
|
|
19
|
+
|
|
20
|
+
open_new_file(path)
|
|
21
|
+
|
|
22
|
+
assert_eq path, vma.buf.fname
|
|
23
|
+
assert_eq "existing contents\n", vma.buf.to_s
|
|
24
|
+
assert_eq "existing contents\n", File.read(path)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
|
|
3
|
+
# Right-clicking text that names an existing file offers to open it.
|
|
4
|
+
class TestContextMenuFile < VmaTest
|
|
5
|
+
def menu_labels(view)
|
|
6
|
+
m = view.instance_variable_get(:@context_menu).menu_model
|
|
7
|
+
(0...m.n_items).map { |i| m.get_item_attribute_value(i, "label", GLib::VariantType::STRING) }
|
|
8
|
+
ensure
|
|
9
|
+
view.instance_variable_get(:@context_menu)&.popdown
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Buffer for dir/notes.txt whose first word is first_word; right-click on it.
|
|
13
|
+
def with_menu(first_word)
|
|
14
|
+
Dir.mktmpdir do |dir|
|
|
15
|
+
File.binwrite("#{dir}/foobar.pdf", "%PDF-1.4\n%\xE2\xE3\xCF\xD3\n\xFF\xFEbinary".b)
|
|
16
|
+
File.write("#{dir}/other.txt", "hello\n")
|
|
17
|
+
path = "#{dir}/notes.txt"
|
|
18
|
+
File.write(path, "#{first_word} rest of line\n")
|
|
19
|
+
b = open_new_file(path)
|
|
20
|
+
begin
|
|
21
|
+
drain_idle
|
|
22
|
+
# Point inside the first word (widget x 5 is in the line-number gutter)
|
|
23
|
+
x, y = b.view.buffer_to_window_coords(:widget, 5, 5)
|
|
24
|
+
b.view.show_context_menu(x, y)
|
|
25
|
+
drain_idle
|
|
26
|
+
yield b, menu_labels(b.view), dir
|
|
27
|
+
ensure
|
|
28
|
+
vma.buffers.close_buffer(b.id)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_binary_file_opens_externally
|
|
34
|
+
with_menu("foobar.pdf") do |b, labels, dir|
|
|
35
|
+
assert labels.include?("Open file (external)"), labels.inspect
|
|
36
|
+
assert !labels.include?("Open file"), labels.inspect
|
|
37
|
+
opened = nil
|
|
38
|
+
orig = Vimamsa.instance_method(:open_with_default_program)
|
|
39
|
+
Vimamsa.send(:define_method, :open_with_default_program) { |p| opened = p }
|
|
40
|
+
begin
|
|
41
|
+
vma.gui.app.lookup_action("ctx_open_file_external").activate(nil)
|
|
42
|
+
drain_idle
|
|
43
|
+
ensure
|
|
44
|
+
Vimamsa.send(:define_method, :open_with_default_program, orig)
|
|
45
|
+
end
|
|
46
|
+
assert_eq File.join(dir, "foobar.pdf"), opened
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_text_file_can_open_in_editor
|
|
51
|
+
with_menu("(other.txt).") do |b, labels, dir|
|
|
52
|
+
assert labels.include?("Open file"), labels.inspect
|
|
53
|
+
assert labels.include?("Open file (external)"), labels.inspect
|
|
54
|
+
vma.gui.app.lookup_action("ctx_open_file").activate(nil)
|
|
55
|
+
drain_idle
|
|
56
|
+
assert_eq File.join(dir, "other.txt"), vma.buf.fname
|
|
57
|
+
vma.buffers.close_buffer(vma.buf.id)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_no_item_for_missing_file
|
|
62
|
+
with_menu("missing.pdf") do |_b, labels, _dir|
|
|
63
|
+
assert !labels.any? { |l| l.start_with?("Open file") }, labels.inspect
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# gf opens the file whose path is under the cursor (like vim)
|
|
68
|
+
def test_gf_opens_file_under_cursor
|
|
69
|
+
Dir.mktmpdir do |dir|
|
|
70
|
+
File.write("#{dir}/other.txt", "hello\n")
|
|
71
|
+
File.write("#{dir}/n.txt", "see (other.txt). missing.txt\n")
|
|
72
|
+
b = open_new_file("#{dir}/n.txt")
|
|
73
|
+
begin
|
|
74
|
+
drain_idle
|
|
75
|
+
b.set_pos(b.to_s.index("other.txt") + 3)
|
|
76
|
+
keys("g f")
|
|
77
|
+
drain_idle
|
|
78
|
+
assert_eq File.join(dir, "other.txt"), vma.buf.fname
|
|
79
|
+
vma.buffers.close_buffer(vma.buf.id)
|
|
80
|
+
drain_idle
|
|
81
|
+
|
|
82
|
+
vma.buffers.set_current_buffer(b.id) if vma.buf != b
|
|
83
|
+
b.set_pos(b.to_s.index("missing.txt") + 2)
|
|
84
|
+
keys("g f")
|
|
85
|
+
drain_idle
|
|
86
|
+
assert_eq b.fname, vma.buf.fname
|
|
87
|
+
ensure
|
|
88
|
+
vma.buffers.close_buffer(b.id)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_gf_opens_binary_file_externally
|
|
94
|
+
Dir.mktmpdir do |dir|
|
|
95
|
+
File.binwrite("#{dir}/foobar.pdf", "%PDF-1.4\n%\xE2\xE3\xCF\xD3\n\xFF\xFEbinary".b)
|
|
96
|
+
File.write("#{dir}/n.txt", "foobar.pdf\n")
|
|
97
|
+
b = open_new_file("#{dir}/n.txt")
|
|
98
|
+
opened = nil
|
|
99
|
+
orig = Vimamsa.instance_method(:open_with_default_program)
|
|
100
|
+
Vimamsa.send(:define_method, :open_with_default_program) { |p| opened = p }
|
|
101
|
+
begin
|
|
102
|
+
drain_idle
|
|
103
|
+
b.set_pos(2)
|
|
104
|
+
keys("g f")
|
|
105
|
+
drain_idle
|
|
106
|
+
assert_eq File.join(dir, "foobar.pdf"), opened
|
|
107
|
+
ensure
|
|
108
|
+
Vimamsa.send(:define_method, :open_with_default_program, orig)
|
|
109
|
+
vma.buffers.close_buffer(b.id)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_file_path_at
|
|
115
|
+
Dir.mktmpdir do |dir|
|
|
116
|
+
File.write("#{dir}/a.pdf", "x")
|
|
117
|
+
b = open_new_file(File.write("#{dir}/n.txt", "see \"a.pdf\", and #{dir}/a.pdf b.pdf\n") && "#{dir}/n.txt")
|
|
118
|
+
begin
|
|
119
|
+
s = b.to_s
|
|
120
|
+
assert_eq "#{dir}/a.pdf", b.file_path_at(s.index("a.pdf"))
|
|
121
|
+
assert_eq "#{dir}/a.pdf", b.file_path_at(s.index("#{dir}/a.pdf") + 2)
|
|
122
|
+
assert_eq nil, b.file_path_at(s.index("b.pdf"))
|
|
123
|
+
assert_eq nil, b.file_path_at(s.index("see"))
|
|
124
|
+
ensure
|
|
125
|
+
vma.buffers.close_buffer(b.id)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
data/tests/test_copy_paste.rb
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
class TestCopyPaste < VmaTest
|
|
2
2
|
|
|
3
|
+
# On Wayland, read_text_async reads from whatever process currently owns the
|
|
4
|
+
# system clipboard. GTK processes Wayland events during drain_idle and may
|
|
5
|
+
# transfer clipboard ownership to another app between our set_system_clipboard
|
|
6
|
+
# call and the async read callback, returning stale external content.
|
|
7
|
+
#
|
|
8
|
+
# Tests only need to verify in-editor copy/paste logic, not cross-app
|
|
9
|
+
# clipboard round-trips, so we force the synchronous internal-clipboard path
|
|
10
|
+
# (the same one used during macro playback) for all paste actions.
|
|
11
|
+
PASTE_ACTIONS = %i[paste_after_cursor paste_before_cursor
|
|
12
|
+
paste_over_after paste_over_before].freeze
|
|
13
|
+
|
|
14
|
+
def act(action)
|
|
15
|
+
if PASTE_ACTIONS.include?(action)
|
|
16
|
+
vma.macro.instance_variable_set(:@running_macro, true)
|
|
17
|
+
exec_action(action)
|
|
18
|
+
vma.macro.instance_variable_set(:@running_macro, false)
|
|
19
|
+
drain_idle
|
|
20
|
+
else
|
|
21
|
+
super
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
3
25
|
def test_copy_line_paste_after
|
|
4
26
|
act 'buf.insert_txt("hello\n")'
|
|
5
27
|
act :jump_to_start_of_buffer
|
|
@@ -85,4 +107,62 @@ class TestCopyPaste < VmaTest
|
|
|
85
107
|
assert_buf "line1\nline2\nline3\nline1\n"
|
|
86
108
|
end
|
|
87
109
|
|
|
110
|
+
# --- Async paste position capture ------------------------------------------
|
|
111
|
+
# paste_start reads the clipboard asynchronously; its callback (paste_finish)
|
|
112
|
+
# may run after the cursor has moved. These tests drive paste_finish directly
|
|
113
|
+
# with the position/state captured at request time (ipos/paste_lines) while
|
|
114
|
+
# the live cursor sits elsewhere, simulating that race. The paste must land
|
|
115
|
+
# where it was initiated, not at the moved cursor.
|
|
116
|
+
|
|
117
|
+
def test_async_paste_inserts_at_captured_position
|
|
118
|
+
act 'buf.insert_txt("line one\nline two\n")'
|
|
119
|
+
act :jump_to_start_of_buffer
|
|
120
|
+
ipos = buf.pos # where the user pressed paste
|
|
121
|
+
vma.clipboard << "X"
|
|
122
|
+
act :jump_to_end_of_buffer # cursor moves away during the async read
|
|
123
|
+
buf.paste_finish("X", AFTER, nil, ipos: ipos)
|
|
124
|
+
assert_buf "lXine one\nline two\n\n"
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_async_paste_line_mode_uses_captured_state
|
|
128
|
+
act 'buf.insert_txt("AAA\nBBB\nCCC\n")'
|
|
129
|
+
act :jump_to_start_of_buffer
|
|
130
|
+
act :copy_cur_line # clipboard = "AAA\n", @paste_lines = true
|
|
131
|
+
ipos = buf.pos
|
|
132
|
+
act :jump_to_end_of_buffer # cursor moves to the last line
|
|
133
|
+
buf.paste_finish("AAA\n", AFTER, nil, ipos: ipos, paste_lines: true)
|
|
134
|
+
assert_buf "AAA\nAAA\nBBB\nCCC\n\n"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Without a captured position (synchronous/macro path) the live cursor is
|
|
138
|
+
# used, preserving prior behavior.
|
|
139
|
+
def test_paste_finish_without_capture_uses_live_cursor
|
|
140
|
+
act 'buf.insert_txt("line one\nline two\n")'
|
|
141
|
+
act :jump_to_start_of_buffer
|
|
142
|
+
vma.clipboard << "X"
|
|
143
|
+
buf.paste_finish("X", AFTER, nil)
|
|
144
|
+
assert_buf "lXine one\nline two\n\n"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# --- Copy to mark (y'a) ----------------------------------------------------
|
|
148
|
+
# copy(:to_mark) yanks the same range delete2(:to_mark) removes: from the end
|
|
149
|
+
# of the current line to the mark position.
|
|
150
|
+
def test_copy_to_mark
|
|
151
|
+
act 'buf.insert_txt("AAA\nBBB\nCCC\n")'
|
|
152
|
+
act "buf.set_pos(8)" # start of "CCC"
|
|
153
|
+
act "buf.mark_current_position('a')"
|
|
154
|
+
act :jump_to_start_of_buffer # cursor back on line 0
|
|
155
|
+
act "buf.copy(:to_mark, 'a')"
|
|
156
|
+
assert_eq "\nBBB\nC", vma.clipboard.get
|
|
157
|
+
assert_buf "AAA\nBBB\nCCC\n\n" # buffer unchanged by a copy
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_copy_to_undefined_mark_is_noop
|
|
161
|
+
act 'buf.insert_txt("hello")'
|
|
162
|
+
vma.clipboard.set("PREVIOUS")
|
|
163
|
+
act "buf.copy(:to_mark, 'z')" # mark 'z' was never set
|
|
164
|
+
assert_eq "PREVIOUS", vma.clipboard.get # clipboard untouched
|
|
165
|
+
assert_buf "hello\n"
|
|
166
|
+
end
|
|
167
|
+
|
|
88
168
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class TestCrashHandler < VmaTest
|
|
2
|
+
|
|
3
|
+
# report() writes a .txt and .json into the crash dir, then we clean up.
|
|
4
|
+
def test_report_writes_files
|
|
5
|
+
base = Vimamsa::CrashHandler.report("test", RuntimeError.new("kaboom"))
|
|
6
|
+
assert !base.nil?, "report should return a base path"
|
|
7
|
+
txt = "#{base}.txt"
|
|
8
|
+
json = "#{base}.json"
|
|
9
|
+
assert File.exist?(txt), "crash .txt should be written"
|
|
10
|
+
assert File.exist?(json), "crash .json should be written"
|
|
11
|
+
body = File.read(txt)
|
|
12
|
+
assert body.include?("RuntimeError: kaboom"), "exception line present"
|
|
13
|
+
assert body.include?("--- backtrace ---")
|
|
14
|
+
assert body.include?("--- current buffer ---")
|
|
15
|
+
ensure
|
|
16
|
+
File.delete(txt) if txt && File.exist?(txt)
|
|
17
|
+
File.delete(json) if json && File.exist?(json)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Each snapshot field is collected independently; a raising collector must
|
|
21
|
+
# not abort the report — it records a placeholder instead.
|
|
22
|
+
def test_add_degrades_gracefully
|
|
23
|
+
info = {}
|
|
24
|
+
Vimamsa::CrashHandler.add(info, "boom") { raise "nope" }
|
|
25
|
+
assert info["boom"].to_s.start_with?("<unavailable"), info["boom"].inspect
|
|
26
|
+
Vimamsa::CrashHandler.add(info, "ok") { 42 }
|
|
27
|
+
assert_eq 42, info["ok"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The report captures live editor state (current buffer contents).
|
|
31
|
+
def test_report_includes_buffer_state
|
|
32
|
+
vma.buf.set_content("crashy #ff0000 buffer\n")
|
|
33
|
+
base = Vimamsa::CrashHandler.report("test")
|
|
34
|
+
body = File.read("#{base}.txt")
|
|
35
|
+
assert body.include?("crashy #ff0000 buffer"), "buffer head should be captured"
|
|
36
|
+
ensure
|
|
37
|
+
["#{base}.txt", "#{base}.json"].each { |f| File.delete(f) if base && File.exist?(f) }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require "tmpdir"
|
|
2
|
+
require "rbconfig"
|
|
3
|
+
|
|
4
|
+
# custom.rb is loaded in two phases (see call_custom_after_init in editor.rb):
|
|
5
|
+
# the body of the file runs before Grep.init/FileManager.init/module loading, so
|
|
6
|
+
# that its cnf.* settings are visible to them, and hook_custom_after_init runs
|
|
7
|
+
# after everything is loaded, so it can bind keys for the modes they registered.
|
|
8
|
+
#
|
|
9
|
+
# That ordering can only be observed while an editor starts up, so this test
|
|
10
|
+
# boots a second editor process with VMA_USER_DIR pointing at a generated config
|
|
11
|
+
# and lets a probe test inside that process check the resulting binding tree.
|
|
12
|
+
class TestCustomTwoPhase < VmaTest
|
|
13
|
+
CUSTOM_RB = <<~'RUBY'
|
|
14
|
+
# Phase 1: must be visible to FileManager.init, which registers the
|
|
15
|
+
# experimental fexp bindings ("fexp d d" etc.) only when this is set.
|
|
16
|
+
cnf.fexp.experimental = true
|
|
17
|
+
|
|
18
|
+
# Phase 2: the fexp mode does not exist while the body of this file runs.
|
|
19
|
+
def hook_custom_after_init
|
|
20
|
+
reg_act(:_zz_probe_archive, proc { }, "probe")
|
|
21
|
+
bindkey "fexp , x", :_zz_probe_archive
|
|
22
|
+
end
|
|
23
|
+
RUBY
|
|
24
|
+
|
|
25
|
+
PROBE_RB = <<~'RUBY'
|
|
26
|
+
class TestZzTwoPhaseProbe < VmaTest
|
|
27
|
+
def test_hook_custom_after_init_bound_to_fexp
|
|
28
|
+
assert_eq ["fexp , x"], paths_of(:_zz_probe_archive),
|
|
29
|
+
"hook_custom_after_init should bind to the fexp mode, not leak elsewhere"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_phase1_settings_reached_module_init
|
|
33
|
+
assert_eq ["fexp d d"], paths_of(:fexp_cut_file),
|
|
34
|
+
"cnf.fexp.experimental from the body of custom.rb should reach FileManager.init"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def paths_of(action)
|
|
38
|
+
found = []
|
|
39
|
+
walk = lambda { |state, path|
|
|
40
|
+
state.children.each { |c|
|
|
41
|
+
p2 = path + [c.key_name]
|
|
42
|
+
found << p2.join(" ") if c.action == action
|
|
43
|
+
walk.call(c, p2)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
vma.kbd.root.children.each { |mode| walk.call(mode, [mode.key_name]) }
|
|
47
|
+
found
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
RUBY
|
|
51
|
+
|
|
52
|
+
def test_custom_rb_phases_run_in_order
|
|
53
|
+
# Set in the child so a copy of this test file there can never recurse.
|
|
54
|
+
skip "nested editor run" if ENV["VMA_TEST_CHILD"]
|
|
55
|
+
|
|
56
|
+
Dir.mktmpdir("vimamsa-two-phase-") do |dir|
|
|
57
|
+
File.write(File.join(dir, "custom.rb"), CUSTOM_RB)
|
|
58
|
+
probe = File.join(dir, "test_zz_two_phase_probe.rb")
|
|
59
|
+
File.write(probe, PROBE_RB)
|
|
60
|
+
|
|
61
|
+
args = [File.expand_path("exe/run_tests.rb", vma_root), probe]
|
|
62
|
+
# Reuse this run's display when it is already headless; open the child on
|
|
63
|
+
# its own invisible display when we are on the real desktop, so it cannot
|
|
64
|
+
# steal focus from e2e tests.
|
|
65
|
+
backend = Gdk::Display.default&.gtype&.name.to_s
|
|
66
|
+
args << "--headless" if backend.include?("Wayland")
|
|
67
|
+
|
|
68
|
+
env = { "VMA_USER_DIR" => dir, "VMA_TEST_CHILD" => "1" }
|
|
69
|
+
out_r, out_w = IO.pipe
|
|
70
|
+
pid = begin
|
|
71
|
+
Process.spawn(env, RbConfig.ruby, *args, chdir: vma_root,
|
|
72
|
+
out: out_w, err: out_w)
|
|
73
|
+
rescue SystemCallError => e
|
|
74
|
+
out_r.close
|
|
75
|
+
out_w.close
|
|
76
|
+
skip "could not start child editor: #{e}"
|
|
77
|
+
end
|
|
78
|
+
out_w.close
|
|
79
|
+
output = out_r.read
|
|
80
|
+
out_r.close
|
|
81
|
+
_, status = Process.waitpid2(pid)
|
|
82
|
+
|
|
83
|
+
assert status.success?, "child editor run failed:\n#{output}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
def vma_root
|
|
90
|
+
File.expand_path("..", File.dirname(__FILE__))
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# An exception raised by a dialog callback must not escape to GTK: ruby-gnome
|
|
2
|
+
# calls exit for exceptions leaving a signal handler, quitting the editor.
|
|
3
|
+
class TestDialogCallbackErrors < VmaTest
|
|
4
|
+
def test_run_dialog_callback_returns_nil_and_reports
|
|
5
|
+
r = run_dialog_callback("test cb") { raise ArgumentError, "boom" }
|
|
6
|
+
assert_eq nil, r
|
|
7
|
+
assert $vmag.instance_variable_get(:@minibuf_messages).first.include?("ERROR in test cb: boom")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_run_dialog_callback_returns_block_value
|
|
11
|
+
assert_eq 42, run_dialog_callback { 42 }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_run_dialog_callback_does_not_swallow_exit
|
|
15
|
+
raised = false
|
|
16
|
+
begin
|
|
17
|
+
run_dialog_callback { exit }
|
|
18
|
+
rescue SystemExit
|
|
19
|
+
raised = true
|
|
20
|
+
end
|
|
21
|
+
assert raised, "SystemExit must propagate"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_form_submit_with_raising_callback_closes_popup
|
|
25
|
+
PopupFormGenerator.reset_popup_queue
|
|
26
|
+
params = { "inputs" => { "q" => { :label => "Q", :type => :entry } },
|
|
27
|
+
:callback => proc { |_| raise "form boom" } }
|
|
28
|
+
p1 = PopupFormGenerator.new(params)
|
|
29
|
+
p1.run
|
|
30
|
+
drain_idle
|
|
31
|
+
p1.submit
|
|
32
|
+
drain_idle
|
|
33
|
+
assert !PopupFormGenerator.popup_active?, "popup should close even though callback raised"
|
|
34
|
+
ensure
|
|
35
|
+
PopupFormGenerator.reset_popup_queue
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_key_controller_submit_raising_is_caught
|
|
39
|
+
entry = Gtk::Entry.new
|
|
40
|
+
press = on_submit_escape(entry, submit: proc { raise "submit boom" })
|
|
41
|
+
handled = press.signal_emit("key-pressed", Gdk::Keyval::KEY_Return, 0, 0)
|
|
42
|
+
assert_eq true, handled
|
|
43
|
+
end
|
|
44
|
+
end
|