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,126 @@
|
|
|
1
|
+
|
|
2
|
+
# Tests that the Ruby buffer and GTK SourceView buffer stay in sync.
|
|
3
|
+
#
|
|
4
|
+
# assert_gtk_sync compares vma.buf.to_s (Ruby) with view.buffer.text (GTK).
|
|
5
|
+
# Most tests also exercise assert_buf so both sides are checked explicitly.
|
|
6
|
+
|
|
7
|
+
class TestGtkSync < VmaTest
|
|
8
|
+
|
|
9
|
+
# ── Helpers ─────────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
# Flush pending Ruby→GTK deltas in addition to GLib idle callbacks.
|
|
12
|
+
# In the test harness key events are bypassed so handle_deltas is never
|
|
13
|
+
# called from handle_key_event — we must call it explicitly.
|
|
14
|
+
def drain_idle
|
|
15
|
+
super
|
|
16
|
+
vma.buf.view.handle_deltas if vma.buf&.view
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def assert_gtk_sync(msg = nil)
|
|
20
|
+
ruby_text = vma.buf.to_s
|
|
21
|
+
gtk_text = vma.buf.view.buffer.text
|
|
22
|
+
return if ruby_text == gtk_text
|
|
23
|
+
raise VmaTestFailure, (msg || "Ruby/GTK buffer mismatch\n" \
|
|
24
|
+
" ruby: #{ruby_text.inspect}\n" \
|
|
25
|
+
" gtk: #{gtk_text.inspect}")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Insert text directly into the GTK buffer without going through key events,
|
|
29
|
+
# simulating a Wayland IM commit (e.g. AltGr+q → ä).
|
|
30
|
+
def im_commit(text)
|
|
31
|
+
gtbuf = vma.buf.view.buffer
|
|
32
|
+
iter = gtbuf.get_iter_at(:offset => vma.buf.pos)
|
|
33
|
+
gtbuf.insert(iter, text)
|
|
34
|
+
drain_idle
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# ── Basic editing ───────────────────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
def test_insert_syncs_gtk
|
|
40
|
+
act 'buf.insert_txt("hello")'
|
|
41
|
+
assert_buf "hello\n"
|
|
42
|
+
assert_gtk_sync
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_delete_syncs_gtk
|
|
46
|
+
act 'buf.insert_txt("abcde")'
|
|
47
|
+
act :jump_to_start_of_buffer
|
|
48
|
+
act :delete_char_forward
|
|
49
|
+
act :delete_char_forward
|
|
50
|
+
assert_buf "cde\n"
|
|
51
|
+
assert_gtk_sync
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_undo_syncs_gtk
|
|
55
|
+
act 'buf.insert_txt("hello")'
|
|
56
|
+
act :undo
|
|
57
|
+
assert_buf "\n"
|
|
58
|
+
assert_gtk_sync
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_newline_syncs_gtk
|
|
62
|
+
act 'buf.insert_txt("first")'
|
|
63
|
+
act 'buf.insert_txt("\n")'
|
|
64
|
+
act 'buf.insert_txt("second")'
|
|
65
|
+
assert_buf "first\nsecond\n"
|
|
66
|
+
assert_gtk_sync
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_key_sequence_syncs_gtk
|
|
70
|
+
keys "i"
|
|
71
|
+
"hello".each_char { |c| keys c }
|
|
72
|
+
keys "esc"
|
|
73
|
+
assert_buf "hello\n"
|
|
74
|
+
assert_gtk_sync
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def test_delete_line_syncs_gtk
|
|
78
|
+
act 'buf.insert_txt("first\n")'
|
|
79
|
+
act 'buf.insert_txt("second")'
|
|
80
|
+
act :jump_to_start_of_buffer
|
|
81
|
+
act :delete_line
|
|
82
|
+
assert_buf "second\n"
|
|
83
|
+
assert_gtk_sync
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# ── Simulated Wayland IM commit ─────────────────────────────────────────────
|
|
87
|
+
# Mimics the Wayland text-input protocol inserting a composed character
|
|
88
|
+
# (e.g. AltGr+q → ä) directly into the GTK buffer, bypassing key events.
|
|
89
|
+
# register_buffer_signals() must catch this via insert-text and mirror it
|
|
90
|
+
# into the Ruby buffer.
|
|
91
|
+
|
|
92
|
+
def test_im_commit_in_insert_mode
|
|
93
|
+
vma.kbd.set_mode(:insert)
|
|
94
|
+
drain_idle
|
|
95
|
+
|
|
96
|
+
im_commit("ä")
|
|
97
|
+
|
|
98
|
+
assert_buf "ä\n"
|
|
99
|
+
assert_gtk_sync
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_im_commit_mid_word
|
|
103
|
+
act 'buf.insert_txt("ac")'
|
|
104
|
+
act :jump_to_start_of_buffer
|
|
105
|
+
act "buf.move(FORWARD_CHAR)"
|
|
106
|
+
vma.kbd.set_mode(:insert)
|
|
107
|
+
drain_idle
|
|
108
|
+
|
|
109
|
+
im_commit("ö")
|
|
110
|
+
|
|
111
|
+
assert_buf "aöc\n"
|
|
112
|
+
assert_gtk_sync
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_im_commit_not_in_insert_mode
|
|
116
|
+
# In command mode the IM commit should be reverted from the GTK buffer.
|
|
117
|
+
vma.kbd.set_mode(:command)
|
|
118
|
+
drain_idle
|
|
119
|
+
|
|
120
|
+
im_commit("ä")
|
|
121
|
+
|
|
122
|
+
# Ruby buffer unchanged, GTK buffer reverted
|
|
123
|
+
assert_buf "\n"
|
|
124
|
+
assert_gtk_sync
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Checks that hyperplaintext syntax actually *looks* highlighted.
|
|
2
|
+
# test_hpt_link_highlight.rb only checks that a context tag exists, but
|
|
3
|
+
# GtkSourceView creates that tag even when the style scheme has no style
|
|
4
|
+
# for the lang's map-to id, leaving the text rendered as plain.
|
|
5
|
+
class TestHptHighlightVisible < VmaTest
|
|
6
|
+
|
|
7
|
+
def view
|
|
8
|
+
vma.buf.view
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def highlight_now
|
|
12
|
+
gb = view.buffer
|
|
13
|
+
gb.ensure_highlight(gb.start_iter, gb.end_iter)
|
|
14
|
+
drain_idle
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def style_tags_at(off)
|
|
18
|
+
itr = view.buffer.get_iter_at(:offset => off)
|
|
19
|
+
itr.tags.reject { |t| t.name.to_s.start_with?("gtksourceview:context-classes") }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
VISUAL_PROPS = %w(foreground-set background-set weight-set style-set
|
|
23
|
+
underline-set scale-set).freeze
|
|
24
|
+
|
|
25
|
+
# True if any tag at +off+ changes how the text is rendered.
|
|
26
|
+
def visibly_styled?(off)
|
|
27
|
+
style_tags_at(off).any? { |t| VISUAL_PROPS.any? { |p| t.get_property(p) } }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def setup_hpt(txt)
|
|
31
|
+
vma.buf.set_language("hyperplaintext")
|
|
32
|
+
vma.buf.set_content(txt)
|
|
33
|
+
highlight_now
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def bundled_scheme_ids
|
|
37
|
+
Dir[ppath("styles/*.xml")].map { |f| File.read(f)[/<style-scheme[^>]*\bid="([^"]+)"/, 1] }.compact
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def with_scheme(id)
|
|
41
|
+
ssm = GtkSource::StyleSchemeManager.new
|
|
42
|
+
ssm.set_search_path(ssm.search_path << ppath("styles/"))
|
|
43
|
+
sch = ssm.get_scheme(id)
|
|
44
|
+
assert !sch.nil?, "style scheme #{id} should load"
|
|
45
|
+
old = view.buffer.style_scheme
|
|
46
|
+
view.buffer.style_scheme = sch
|
|
47
|
+
highlight_now
|
|
48
|
+
yield
|
|
49
|
+
ensure
|
|
50
|
+
view.buffer.style_scheme = old if old
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_link_visible_in_active_scheme
|
|
54
|
+
setup_hpt("plain ⟦notes⟧ plain\n")
|
|
55
|
+
txt = vma.buf.to_s
|
|
56
|
+
assert !visibly_styled?(1), "plain text must not be styled"
|
|
57
|
+
assert visibly_styled?(txt.index("notes")), "⟦notes⟧ must be visibly highlighted"
|
|
58
|
+
assert visibly_styled?(txt.index("⟦")), "⟦ must be visibly highlighted"
|
|
59
|
+
assert visibly_styled?(txt.index("⟧")), "⟧ must be visibly highlighted"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_link_visible_in_every_bundled_scheme
|
|
63
|
+
setup_hpt("plain ⟦notes⟧ plain\n")
|
|
64
|
+
off = vma.buf.to_s.index("notes")
|
|
65
|
+
bad = bundled_scheme_ids.reject { |id| with_scheme(id) { visibly_styled?(off) } }
|
|
66
|
+
assert bad.empty?, "⟦notes⟧ not highlighted in scheme(s): #{bad.join(", ")}"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_other_markup_visible_in_active_scheme
|
|
70
|
+
setup_hpt("⦁bold⦁ ╱italic╱\n")
|
|
71
|
+
txt = vma.buf.to_s
|
|
72
|
+
assert visibly_styled?(txt.index("bold")), "⦁bold⦁ must be visibly highlighted"
|
|
73
|
+
assert visibly_styled?(txt.index("italic")), "╱italic╱ must be visibly highlighted"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
class TestHptLinkHighlight < VmaTest
|
|
2
|
+
|
|
3
|
+
def view
|
|
4
|
+
vma.buf.view
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
# Force GtkSourceView to run its (normally async) syntax highlighter
|
|
8
|
+
# over the whole buffer.
|
|
9
|
+
def highlight_now
|
|
10
|
+
gb = view.buffer
|
|
11
|
+
gb.ensure_highlight(gb.start_iter, gb.end_iter)
|
|
12
|
+
drain_idle
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Syntax-style tags at +off+. Context-class tags (e.g. the
|
|
16
|
+
# "no-spell-check" class on the main context) cover all text and are
|
|
17
|
+
# not highlighting, so leave them out.
|
|
18
|
+
def style_tags_at(off)
|
|
19
|
+
itr = view.buffer.get_iter_at(:offset => off)
|
|
20
|
+
itr.tags.reject { |t| t.name.to_s.start_with?("gtksourceview:context-classes") }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def setup_hpt(txt)
|
|
24
|
+
vma.buf.set_language("hyperplaintext")
|
|
25
|
+
vma.buf.set_content(txt)
|
|
26
|
+
highlight_now
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_hyperplaintext_language_loaded
|
|
30
|
+
vma.buf.set_language("hyperplaintext")
|
|
31
|
+
lang = view.buffer.language
|
|
32
|
+
assert !lang.nil?, "hyperplaintext.lang should be found under lang/"
|
|
33
|
+
assert_eq "hyperplaintext", lang.id
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_link_gets_highlight_tag
|
|
37
|
+
setup_hpt("plain ⟦link⟧ plain\n")
|
|
38
|
+
txt = vma.buf.to_s
|
|
39
|
+
link_off = txt.index("link")
|
|
40
|
+
plain_off = 1
|
|
41
|
+
|
|
42
|
+
assert style_tags_at(plain_off).empty?, "plain text must not be highlighted"
|
|
43
|
+
tags = style_tags_at(link_off)
|
|
44
|
+
assert !tags.empty?, "expected a syntax tag over ⟦link⟧"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_link_highlight_covers_brackets
|
|
48
|
+
setup_hpt("x ⟦link⟧ y\n")
|
|
49
|
+
txt = vma.buf.to_s
|
|
50
|
+
open_off = txt.index("⟦")
|
|
51
|
+
close_off = txt.index("⟧")
|
|
52
|
+
link_tags = style_tags_at(open_off + 1)
|
|
53
|
+
assert !link_tags.empty?, "expected a syntax tag over ⟦link⟧"
|
|
54
|
+
|
|
55
|
+
assert_eq link_tags, style_tags_at(open_off), "⟦ should share the link style"
|
|
56
|
+
assert_eq link_tags, style_tags_at(close_off), "⟧ should share the link style"
|
|
57
|
+
assert style_tags_at(open_off - 1).empty?, "text before ⟦ must not be highlighted"
|
|
58
|
+
assert style_tags_at(close_off + 1).empty?, "text after ⟧ must not be highlighted"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def test_link_style_differs_from_bold
|
|
62
|
+
setup_hpt("⦁bold⦁ ⟦link⟧\n")
|
|
63
|
+
txt = vma.buf.to_s
|
|
64
|
+
bold_tags = style_tags_at(txt.index("bold"))
|
|
65
|
+
link_tags = style_tags_at(txt.index("link"))
|
|
66
|
+
assert !link_tags.empty?, "expected a syntax tag over ⟦link⟧"
|
|
67
|
+
assert link_tags != bold_tags, "link must use its own style, not bold's"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_unclosed_link_not_highlighted
|
|
71
|
+
setup_hpt("plain ⟦link without end\n")
|
|
72
|
+
off = vma.buf.to_s.index("link")
|
|
73
|
+
assert style_tags_at(off).empty?, "unterminated ⟦ must not be highlighted"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_other_language_does_not_highlight_link
|
|
77
|
+
vma.buf.set_content("plain ⟦link⟧ plain\n")
|
|
78
|
+
highlight_now
|
|
79
|
+
off = vma.buf.to_s.index("link")
|
|
80
|
+
assert style_tags_at(off).empty?, "no lang => no link highlight"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "tempfile"
|
|
2
|
+
|
|
3
|
+
# Regression tests for jump_to_file / open_new_file.
|
|
4
|
+
#
|
|
5
|
+
# Bug: when the target file was not already open, open_new_file returned the
|
|
6
|
+
# buffer *id* (an Integer) instead of the Buffer object, so jump_to_file crashed
|
|
7
|
+
# with "undefined method `jump_to_line' for an instance of Integer". This is the
|
|
8
|
+
# path hit when jumping to source from a whole-repo git diff (diffview enter).
|
|
9
|
+
class TestJumpToFile < VmaTest
|
|
10
|
+
|
|
11
|
+
def make_temp_file(contents)
|
|
12
|
+
f = Tempfile.new(["jump_target", ".txt"])
|
|
13
|
+
f.write(contents)
|
|
14
|
+
f.flush
|
|
15
|
+
f
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# open_new_file must hand back a Buffer for a file that isn't open yet.
|
|
19
|
+
def test_open_new_file_returns_buffer_when_not_open
|
|
20
|
+
f = make_temp_file("line1\nline2\nline3\n")
|
|
21
|
+
path = File.expand_path(f.path)
|
|
22
|
+
b = open_new_file(path)
|
|
23
|
+
assert b.is_a?(Buffer), "open_new_file must return a Buffer, got #{b.class}: #{b.inspect}"
|
|
24
|
+
assert_eq path, b.fname
|
|
25
|
+
ensure
|
|
26
|
+
f.close
|
|
27
|
+
f.unlink
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# The end-to-end path that was crashing: jump to a line in a not-yet-open file.
|
|
31
|
+
def test_jump_to_file_positions_cursor
|
|
32
|
+
f = make_temp_file("line1\nline2\nline3\nline4\nline5\n")
|
|
33
|
+
path = File.expand_path(f.path)
|
|
34
|
+
jump_to_file(path, 3) # 1-based line 3
|
|
35
|
+
assert_eq path, vma.buf.fname
|
|
36
|
+
assert_eq 2, vma.buf.lpos # -> 0-based line 2
|
|
37
|
+
ensure
|
|
38
|
+
f.close
|
|
39
|
+
f.unlink
|
|
40
|
+
end
|
|
41
|
+
end
|
data/tests/test_key_bindings.rb
CHANGED
|
@@ -107,6 +107,69 @@ class TestKeyBindings < VmaTest
|
|
|
107
107
|
assert_eq 2, count, "neither binding should fire after unbind"
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
+
# include_child_nodes: clear every binding under a node in one call.
|
|
111
|
+
|
|
112
|
+
def test_unbindkey_include_child_nodes_clears_mode
|
|
113
|
+
count = 0
|
|
114
|
+
reg_act(:_test_uc1, proc { count += 1 }, "test")
|
|
115
|
+
reg_act(:_test_uc2, proc { count += 1 }, "test")
|
|
116
|
+
vma.kbd.add_minor_mode("tdictmode", :tdictmode, :command)
|
|
117
|
+
bindkey "tdictmode ctrl-F10", :_test_uc1
|
|
118
|
+
bindkey "tdictmode ctrl-F11 ctrl-F12", :_test_uc2
|
|
119
|
+
|
|
120
|
+
vma.kbd.set_mode(:tdictmode)
|
|
121
|
+
keys "ctrl-F10"
|
|
122
|
+
keys "ctrl-F11 ctrl-F12"
|
|
123
|
+
assert_eq 2, count, "both mode bindings should fire before unbind"
|
|
124
|
+
|
|
125
|
+
unbindkey "tdictmode", include_child_nodes: true
|
|
126
|
+
keys "ctrl-F10"
|
|
127
|
+
keys "ctrl-F11 ctrl-F12"
|
|
128
|
+
assert_eq 2, count, "no mode binding should fire after clearing children"
|
|
129
|
+
ensure
|
|
130
|
+
vma.kbd.set_mode(:command)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# A bare mode id (no chord) implies include_child_nodes.
|
|
134
|
+
def test_unbindkey_bare_mode_clears_children
|
|
135
|
+
count = 0
|
|
136
|
+
reg_act(:_test_ub_bare, proc { count += 1 }, "test")
|
|
137
|
+
vma.kbd.add_minor_mode("tbaremode", :tbaremode, :command)
|
|
138
|
+
bindkey "tbaremode ctrl-F9", :_test_ub_bare
|
|
139
|
+
|
|
140
|
+
vma.kbd.set_mode(:tbaremode)
|
|
141
|
+
keys "ctrl-F9"
|
|
142
|
+
assert_eq 1, count, "mode binding should fire before unbind"
|
|
143
|
+
|
|
144
|
+
unbindkey "tbaremode"
|
|
145
|
+
keys "ctrl-F9"
|
|
146
|
+
assert_eq 1, count, "bare-mode unbind should clear children"
|
|
147
|
+
ensure
|
|
148
|
+
vma.kbd.set_mode(:command)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Clearing a minor mode's children must leave the inherited (command) mode.
|
|
152
|
+
def test_unbindkey_include_child_nodes_keeps_parent_mode
|
|
153
|
+
parent_count = 0
|
|
154
|
+
child_count = 0
|
|
155
|
+
reg_act(:_test_parent, proc { parent_count += 1 }, "test")
|
|
156
|
+
reg_act(:_test_child, proc { child_count += 1 }, "test")
|
|
157
|
+
bindkey "C ctrl-F7", :_test_parent
|
|
158
|
+
vma.kbd.add_minor_mode("tdmodeb", :tdmodeb, :command)
|
|
159
|
+
bindkey "tdmodeb ctrl-F8", :_test_child
|
|
160
|
+
|
|
161
|
+
vma.kbd.set_mode(:tdmodeb)
|
|
162
|
+
unbindkey "tdmodeb", include_child_nodes: true
|
|
163
|
+
|
|
164
|
+
keys "ctrl-F8"
|
|
165
|
+
assert_eq 0, child_count, "child binding should be cleared"
|
|
166
|
+
keys "ctrl-F7"
|
|
167
|
+
assert_eq 1, parent_count, "inherited command binding should still fire"
|
|
168
|
+
ensure
|
|
169
|
+
vma.kbd.set_mode(:command)
|
|
170
|
+
unbindkey "C ctrl-F7"
|
|
171
|
+
end
|
|
172
|
+
|
|
110
173
|
# ── || (pipe) multi-binding syntax ───────────────────────────────────────
|
|
111
174
|
|
|
112
175
|
def test_pipe_syntax_both_keys_trigger_same_action
|
|
@@ -122,6 +185,48 @@ class TestKeyBindings < VmaTest
|
|
|
122
185
|
|
|
123
186
|
# ── repeat count ─────────────────────────────────────────────────────────
|
|
124
187
|
|
|
188
|
+
# Seed the buffer with `n` numbered lines ("line1".."lineN") and park the
|
|
189
|
+
# cursor at the top. The fresh test buffer is already "\n", so chomp.
|
|
190
|
+
def seed_numbered_lines(n)
|
|
191
|
+
text = (1..n).map { |i| "line#{i}" }.join("\n")
|
|
192
|
+
act "buf.insert_txt(#{text.inspect})"
|
|
193
|
+
act "buf.set_pos(0)"
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Text of the line the cursor is on.
|
|
197
|
+
def cur_line_text
|
|
198
|
+
vma.buf.to_s.lines[vma.buf.lpos].to_s.chomp
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# "20G" jumps to line 20. Exercises a multi-digit count: each digit folds into
|
|
202
|
+
# next_command_count, then G's counted variant routes to buf.jump_to_line.
|
|
203
|
+
# The "0" matters — it is bound separately from [1-9] (a leading "0" is
|
|
204
|
+
# jump-to-column-0, not a count), so a two-digit count is the case that breaks.
|
|
205
|
+
def test_count_20_G_jumps_to_line_20
|
|
206
|
+
seed_numbered_lines(30)
|
|
207
|
+
keys "2 0 G"
|
|
208
|
+
assert_eq "line20", cur_line_text, "20G should land on line 20"
|
|
209
|
+
assert_pos 19, 0, "20G should put the cursor at the start of line 20"
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Single-digit count, for contrast: proves the count path itself works, so a
|
|
213
|
+
# failure above is specific to accumulating a second digit.
|
|
214
|
+
def test_count_5_G_jumps_to_line_5
|
|
215
|
+
seed_numbered_lines(30)
|
|
216
|
+
keys "5 G"
|
|
217
|
+
assert_eq "line5", cur_line_text, "5G should land on line 5"
|
|
218
|
+
assert_pos 4, 0, "5G should put the cursor at the start of line 5"
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# esc aborts a count that is being typed, so the digits don't silently attach
|
|
222
|
+
# to the next command ("2 0 0 esc d d" must delete one line, not 200).
|
|
223
|
+
def test_esc_cancels_pending_count
|
|
224
|
+
keys "2 0 0"
|
|
225
|
+
assert_eq 200, vma.kbd.next_command_count, "digits should accumulate into a count"
|
|
226
|
+
keys "esc"
|
|
227
|
+
assert_eq nil, vma.kbd.next_command_count, "esc should cancel the pending count"
|
|
228
|
+
end
|
|
229
|
+
|
|
125
230
|
def test_repeat_count_executes_action_n_times
|
|
126
231
|
count = 0
|
|
127
232
|
reg_act(:_test_repeat, proc { count += 1 }, "test")
|
|
@@ -149,4 +254,107 @@ class TestKeyBindings < VmaTest
|
|
|
149
254
|
keys "esc"
|
|
150
255
|
end
|
|
151
256
|
|
|
257
|
+
# ── binding to a mode that does not exist ────────────────────────────────
|
|
258
|
+
|
|
259
|
+
# A binding for an unknown mode used to be installed silently into the
|
|
260
|
+
# current default mode instead: 'bindkey "fexp , x"' in custom.rb (loaded
|
|
261
|
+
# before FileManager.init creates the fexp mode) became "C , x" and fired in
|
|
262
|
+
# every buffer.
|
|
263
|
+
def test_bindkey_unknown_mode_is_reported_and_binds_nothing
|
|
264
|
+
errors = capture_kbd_errors {
|
|
265
|
+
bindkey "nosuchmode z z", :_test_unknown_mode_action
|
|
266
|
+
}
|
|
267
|
+
assert_eq 1, errors.size, "unknown mode should be reported once: #{errors.inspect}"
|
|
268
|
+
assert errors[0].include?("nosuchmode"), "error should name the mode: #{errors[0]}"
|
|
269
|
+
assert_eq [], find_binding_paths(:_test_unknown_mode_action),
|
|
270
|
+
"nothing should have been bound"
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Mode part neither all uppercase (major modes) nor all lowercase (minor
|
|
274
|
+
# modes): used to raise NoMethodError on nil while loading custom.rb.
|
|
275
|
+
def test_bindkey_mixed_case_mode_is_reported_and_binds_nothing
|
|
276
|
+
errors = capture_kbd_errors {
|
|
277
|
+
bindkey "Fexp z z", :_test_mixed_case_mode_action
|
|
278
|
+
}
|
|
279
|
+
assert_eq 1, errors.size, "invalid mode should be reported once: #{errors.inspect}"
|
|
280
|
+
assert_eq [], find_binding_paths(:_test_mixed_case_mode_action),
|
|
281
|
+
"nothing should have been bound"
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def test_bindkey_known_minor_mode_binds_to_that_mode
|
|
285
|
+
bindkey "fexp z z", :_test_fexp_action
|
|
286
|
+
assert_eq ["fexp z z"], find_binding_paths(:_test_fexp_action)
|
|
287
|
+
unbindkey "fexp z z"
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# ── count inside a sequence (<num>) ──────────────────────────────────────
|
|
291
|
+
|
|
292
|
+
def test_count_inside_delete_word
|
|
293
|
+
vma.buf.set_content("one two three four\n")
|
|
294
|
+
vma.buf.set_pos(0)
|
|
295
|
+
keys "d 3 e"
|
|
296
|
+
assert_buf " four\n"
|
|
297
|
+
assert_mode :command
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def test_count_inside_multiplies_outer_count
|
|
301
|
+
vma.buf.set_content("a b c d e f g h\n")
|
|
302
|
+
vma.buf.set_pos(0)
|
|
303
|
+
keys "2 d 3 e"
|
|
304
|
+
assert_buf " g h\n"
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
def test_count_inside_multi_digit
|
|
308
|
+
vma.buf.set_content((1..12).map(&:to_s).join(" ") + "\n")
|
|
309
|
+
vma.buf.set_pos(0)
|
|
310
|
+
keys "d 1 1 e"
|
|
311
|
+
assert_buf " 12\n"
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
def test_count_inside_aborted
|
|
315
|
+
vma.buf.set_content("one two three\n")
|
|
316
|
+
vma.buf.set_pos(0)
|
|
317
|
+
keys "d 2 esc"
|
|
318
|
+
keys "d e"
|
|
319
|
+
assert_buf " two three\n" # no count left over from the aborted sequence
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def test_count_inside_custom_binding
|
|
323
|
+
got = []
|
|
324
|
+
bindkey "C , x <num> y", "$test_num_y << 1"
|
|
325
|
+
$test_num_y = got
|
|
326
|
+
keys ", x 4 y"
|
|
327
|
+
assert_eq 4, got.size
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
private
|
|
331
|
+
|
|
332
|
+
# Collect the errors the key binding tree reports while running blk.
|
|
333
|
+
def capture_kbd_errors
|
|
334
|
+
errors = []
|
|
335
|
+
prev = vma.kbd.error_handler
|
|
336
|
+
vma.kbd.error_handler = proc { |msg| errors << msg }
|
|
337
|
+
begin
|
|
338
|
+
yield
|
|
339
|
+
ensure
|
|
340
|
+
vma.kbd.error_handler = prev
|
|
341
|
+
end
|
|
342
|
+
errors
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# Every key sequence in the whole tree bound to action, e.g. ["C , x"]
|
|
346
|
+
def find_binding_paths(action)
|
|
347
|
+
found = []
|
|
348
|
+
walk = lambda { |state, path|
|
|
349
|
+
state.children.each { |c|
|
|
350
|
+
p2 = path + [c.key_name]
|
|
351
|
+
found << p2.join(" ") if c.action == action
|
|
352
|
+
walk.call(c, p2)
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
vma.kbd.root.children.each { |mode| walk.call(mode, [mode.key_name]) }
|
|
356
|
+
found
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
|
|
152
360
|
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
class TestKeylogPanel < VmaTest
|
|
2
|
+
def panel
|
|
3
|
+
vma.gui.keylog_panel
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
# Show the panel, run the block with a clean log, always hide again so
|
|
7
|
+
# later tests (and other test files) start with logging off.
|
|
8
|
+
def with_panel
|
|
9
|
+
act :toggle_keylog_panel
|
|
10
|
+
panel.clear
|
|
11
|
+
yield
|
|
12
|
+
ensure
|
|
13
|
+
act :toggle_keylog_panel
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_chord_and_action_logged
|
|
17
|
+
with_panel do
|
|
18
|
+
keys("g g")
|
|
19
|
+
e = panel.entries.last
|
|
20
|
+
assert_eq :action, e[:kind]
|
|
21
|
+
assert_eq :jump_start_of_buffer, e[:action]
|
|
22
|
+
assert e[:chord].include?("g g"), "chord was #{e[:chord].inspect}"
|
|
23
|
+
assert e[:chord].include?("[COMMAND]"), "chord was #{e[:chord].inspect}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_pending_chord_shown
|
|
28
|
+
with_panel do
|
|
29
|
+
keys("g")
|
|
30
|
+
e = panel.entries.last
|
|
31
|
+
assert_eq :pending, e[:kind]
|
|
32
|
+
assert e[:chord].include?("g"), "chord was #{e[:chord].inspect}"
|
|
33
|
+
keys("g")
|
|
34
|
+
# Completing the chord replaces the pending row with the action row
|
|
35
|
+
assert_eq :action, panel.entries.last[:kind]
|
|
36
|
+
assert_eq 0, panel.entries.count { |x| x[:kind] == :pending }
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_insert_mode_coalesced
|
|
41
|
+
with_panel do
|
|
42
|
+
keys("i h e l l o")
|
|
43
|
+
ins = panel.entries.select { |e| e[:kind] == :insert }
|
|
44
|
+
assert_eq 1, ins.size
|
|
45
|
+
assert_eq "hello", ins.first[:text]
|
|
46
|
+
keys("esc")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_no_logging_when_hidden
|
|
51
|
+
n = panel.entries.size
|
|
52
|
+
keys("g g")
|
|
53
|
+
assert_eq n, panel.entries.size
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_newest_shown_at_top_and_highlighted
|
|
57
|
+
with_panel do
|
|
58
|
+
keys("j")
|
|
59
|
+
keys("k")
|
|
60
|
+
row = panel.newest_row
|
|
61
|
+
assert row.css_classes.include?("keylog-newest"), "newest row not highlighted"
|
|
62
|
+
assert_eq row, panel.top_row
|
|
63
|
+
assert_eq :action, panel.entries.last[:kind]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_entry_cap
|
|
68
|
+
with_panel do
|
|
69
|
+
210.times { keys("j") }
|
|
70
|
+
cap = Vimamsa::KeyLogPanel::MAX_ENTRIES
|
|
71
|
+
assert panel.entries.size <= cap, "#{panel.entries.size} entries exceeds cap #{cap}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Let GTK lay out the pane (set_keylog_width waits for an allocation)
|
|
76
|
+
def settle
|
|
77
|
+
t = Time.now
|
|
78
|
+
drain_idle
|
|
79
|
+
GLib::MainContext.default.iteration(false) while Time.now - t < 0.4
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# First show uses the default width, and long entries (even without
|
|
83
|
+
# spaces) don't widen it
|
|
84
|
+
def test_width_fixed_on_first_show
|
|
85
|
+
gui = vma.gui
|
|
86
|
+
old = gui.instance_variable_get(:@keylog_width)
|
|
87
|
+
gui.instance_variable_set(:@keylog_width, nil)
|
|
88
|
+
with_panel do
|
|
89
|
+
settle
|
|
90
|
+
w = gui.keylog_width
|
|
91
|
+
assert (w - VMAgui::PANEL_DEFAULT_WIDTH[:keylog]).abs <= 2, "first width #{w}"
|
|
92
|
+
5.times { keys("e") } # "Jump to the end of the next word"
|
|
93
|
+
keys("o esc") # a long action string without spaces
|
|
94
|
+
keys("g g")
|
|
95
|
+
settle
|
|
96
|
+
assert_eq w, gui.keylog_width
|
|
97
|
+
end
|
|
98
|
+
ensure
|
|
99
|
+
gui.instance_variable_set(:@keylog_width, old)
|
|
100
|
+
end
|
|
101
|
+
end
|