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.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +93 -0
  3. data/.gitignore +4 -1
  4. data/Dockerfile +7 -4
  5. data/README.md +62 -16
  6. data/custom_example.rb +43 -13
  7. data/doc/TODO.md +461 -0
  8. data/doc/bundling_plan.md +569 -0
  9. data/doc/key_bindings_report_plan.md +168 -0
  10. data/doc/missing_vim_bindings.md +71 -0
  11. data/doc/modules_settings_plan.md +433 -0
  12. data/doc/refactor_dedup_plan.md +117 -0
  13. data/doc/unused_code_plan.md +120 -0
  14. data/doc/vim_compatibility_plan.md +296 -0
  15. data/doc/vimlike_vim_conflicts.md +254 -0
  16. data/doc/vm_snapshots_plan.md +146 -0
  17. data/exe/run_tests.rb +117 -3
  18. data/exe/vimamsa +24 -4
  19. data/fonts/OFL-Oxanium.txt +93 -0
  20. data/fonts/Oxanium[wght].ttf +0 -0
  21. data/icon.png +0 -0
  22. data/img/demo.gif +0 -0
  23. data/lang/hyperplaintext.lang +6 -0
  24. data/lib/vimamsa/ack.rb +11 -1
  25. data/lib/vimamsa/actions.rb +4 -1
  26. data/lib/vimamsa/appimage_env.rb +35 -0
  27. data/lib/vimamsa/audio.rb +2 -5
  28. data/lib/vimamsa/bookmarks.rb +302 -0
  29. data/lib/vimamsa/buffer.rb +593 -82
  30. data/lib/vimamsa/buffer_changetext.rb +102 -42
  31. data/lib/vimamsa/buffer_cursor.rb +7 -0
  32. data/lib/vimamsa/buffer_list.rb +4 -0
  33. data/lib/vimamsa/buffer_manager.rb +4 -1
  34. data/lib/vimamsa/bundled_fonts.rb +32 -0
  35. data/lib/vimamsa/clipboard.rb +3 -0
  36. data/lib/vimamsa/conf.rb +59 -3
  37. data/lib/vimamsa/constants.rb +3 -0
  38. data/lib/vimamsa/crash_handler.rb +149 -0
  39. data/lib/vimamsa/debug.rb +4 -1
  40. data/lib/vimamsa/desktop_install.rb +96 -0
  41. data/lib/vimamsa/diff_buffer.rb +39 -10
  42. data/lib/vimamsa/easy_jump.rb +3 -0
  43. data/lib/vimamsa/editor.rb +263 -57
  44. data/lib/vimamsa/encrypt.rb +78 -29
  45. data/lib/vimamsa/file_finder.rb +4 -19
  46. data/lib/vimamsa/file_history.rb +3 -0
  47. data/lib/vimamsa/file_manager.rb +30 -15
  48. data/lib/vimamsa/fold.rb +226 -0
  49. data/lib/vimamsa/gui.rb +520 -106
  50. data/lib/vimamsa/gui_command_line.rb +208 -0
  51. data/lib/vimamsa/gui_dialog.rb +94 -42
  52. data/lib/vimamsa/gui_file_panel.rb +356 -25
  53. data/lib/vimamsa/gui_form_generator.rb +59 -35
  54. data/lib/vimamsa/gui_func_panel.rb +67 -22
  55. data/lib/vimamsa/gui_image.rb +3 -0
  56. data/lib/vimamsa/gui_keylog_panel.rb +246 -0
  57. data/lib/vimamsa/gui_menu.rb +23 -11
  58. data/lib/vimamsa/gui_select_window.rb +19 -48
  59. data/lib/vimamsa/gui_settings.rb +78 -37
  60. data/lib/vimamsa/gui_sourceview.rb +273 -19
  61. data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
  62. data/lib/vimamsa/gui_text.rb +63 -2
  63. data/lib/vimamsa/gui_theme.rb +606 -0
  64. data/lib/vimamsa/hook.rb +3 -0
  65. data/lib/vimamsa/hyper_plain_text.rb +3 -0
  66. data/lib/vimamsa/key_actions.rb +112 -13
  67. data/lib/vimamsa/key_binding_tree.rb +242 -215
  68. data/lib/vimamsa/key_bindings_notepad.rb +43 -0
  69. data/lib/vimamsa/key_bindings_report.rb +261 -0
  70. data/lib/vimamsa/key_bindings_vim.rb +354 -0
  71. data/lib/vimamsa/key_bindings_vimlike.rb +65 -9
  72. data/lib/vimamsa/langservp.rb +271 -54
  73. data/lib/vimamsa/macro.rb +3 -0
  74. data/lib/vimamsa/main.rb +14 -8
  75. data/lib/vimamsa/rbvma.rb +26 -1
  76. data/lib/vimamsa/search.rb +3 -0
  77. data/lib/vimamsa/search_replace.rb +11 -10
  78. data/lib/vimamsa/string_util.rb +120 -40
  79. data/lib/vimamsa/terminal.rb +3 -0
  80. data/lib/vimamsa/test_framework.rb +28 -2
  81. data/lib/vimamsa/tests.rb +3 -0
  82. data/lib/vimamsa/text_objects.rb +353 -0
  83. data/lib/vimamsa/text_transforms.rb +14 -0
  84. data/lib/vimamsa/util.rb +46 -7
  85. data/lib/vimamsa/version.rb +1 -1
  86. data/lib/vimamsa.rb +0 -1
  87. data/modules/color_highlight/color_highlight.rb +118 -0
  88. data/modules/color_highlight/color_highlight_info.rb +3 -0
  89. data/modules/dictation/dictation.rb +1054 -0
  90. data/modules/dictation/dictation_info.rb +3 -0
  91. data/modules/dictation/whisper_worker.py +273 -0
  92. data/modules/ollama/ollama.rb +107 -0
  93. data/modules/ollama/ollama_info.rb +3 -0
  94. data/modules/tts/tts.rb +119 -0
  95. data/modules/tts/tts_info.rb +3 -0
  96. data/run_e2e_vm.sh +28 -0
  97. data/run_tests_vm.sh +130 -0
  98. data/scripts/appimage/AppRun +54 -0
  99. data/scripts/appimage/Dockerfile +18 -0
  100. data/scripts/appimage/build.sh +19 -0
  101. data/scripts/appimage/build_in_container.sh +192 -0
  102. data/scripts/appimage/smoke_test.sh +27 -0
  103. data/scripts/demo/demo_steps.txt +59 -0
  104. data/scripts/demo/record_demo.rb +177 -0
  105. data/scripts/demo/shapes.rb +28 -0
  106. data/styles/134272-molokai.xml +3 -0
  107. data/styles/molokai_cyber.xml +48 -0
  108. data/styles/molokai_edit.xml +1 -0
  109. data/tests/support/virtual_keyboard.rb +254 -0
  110. data/tests/support/virtual_mic.rb +67 -0
  111. data/tests/test_ack.rb +22 -0
  112. data/tests/test_auto_format.rb +122 -0
  113. data/tests/test_autocomplete.rb +211 -0
  114. data/tests/test_autosave.rb +145 -0
  115. data/tests/test_basic_editing.rb +33 -3
  116. data/tests/test_bookmarks.rb +206 -0
  117. data/tests/test_bracket_match.rb +85 -0
  118. data/tests/test_bundling.rb +92 -0
  119. data/tests/test_color_highlight.rb +92 -0
  120. data/tests/test_command_line.rb +79 -0
  121. data/tests/test_command_line_file.rb +27 -0
  122. data/tests/test_context_menu_file.rb +129 -0
  123. data/tests/test_copy_paste.rb +80 -0
  124. data/tests/test_crash_handler.rb +39 -0
  125. data/tests/test_custom_two_phase.rb +92 -0
  126. data/tests/test_dialog_callback_errors.rb +44 -0
  127. data/tests/test_dictation.rb +294 -0
  128. data/tests/test_diff_buffer_name.rb +51 -0
  129. data/tests/test_double_click.rb +41 -0
  130. data/tests/test_drag_selection.rb +125 -0
  131. data/tests/test_e2e_cmdline.rb +116 -0
  132. data/tests/test_e2e_dictation.rb +98 -0
  133. data/tests/test_e2e_replace_char.rb +58 -0
  134. data/tests/test_extract_file_links.rb +55 -0
  135. data/tests/test_file_format.rb +217 -0
  136. data/tests/test_file_manager.rb +72 -0
  137. data/tests/test_file_panel.rb +269 -0
  138. data/tests/test_flash.rb +78 -0
  139. data/tests/test_fold.rb +111 -0
  140. data/tests/test_font_refresh.rb +56 -0
  141. data/tests/test_func_panel.rb +68 -0
  142. data/tests/test_grep_apply.rb +46 -0
  143. data/tests/test_gtk_sync.rb +126 -0
  144. data/tests/test_hpt_highlight_visible.rb +75 -0
  145. data/tests/test_hpt_link_highlight.rb +82 -0
  146. data/tests/test_jump_to_file.rb +41 -0
  147. data/tests/test_key_bindings.rb +208 -0
  148. data/tests/test_keylog_panel.rb +101 -0
  149. data/tests/test_lsp_clangd.rb +281 -0
  150. data/tests/test_lsp_jump.rb +87 -0
  151. data/tests/test_lsp_position_encoding.rb +49 -0
  152. data/tests/test_lsp_symbols.rb +68 -0
  153. data/tests/test_macro.rb +137 -0
  154. data/tests/test_markdown_highlight.rb +57 -0
  155. data/tests/test_mode_badge.rb +41 -0
  156. data/tests/test_notepad_bindings.rb +67 -0
  157. data/tests/test_popup_queue.rb +51 -0
  158. data/tests/test_random_edit.rb +109 -0
  159. data/tests/test_revert.rb +127 -0
  160. data/tests/test_startup_file.rb +58 -0
  161. data/tests/test_status_area.rb +50 -0
  162. data/tests/test_text_objects.rb +163 -0
  163. data/tests/test_text_transforms.rb +329 -0
  164. data/tests/test_tts.rb +68 -0
  165. data/tests/test_vim_bindings.rb +252 -0
  166. data/tests/test_vim_conflicts.rb +63 -0
  167. data/tests/test_window_layout.rb +219 -0
  168. data/vimamsa.gemspec +3 -1
  169. data/vm_guest_run.sh +109 -0
  170. metadata +112 -10
@@ -0,0 +1,41 @@
1
+ # Regression tests for the mode badge (e.g. COMMAND) shown in the status area.
2
+ #
3
+ # Bug: the badge stayed blank on startup because show_state_trail was only ever
4
+ # called from key handling — so the mode was not displayed until the first
5
+ # keypress. Editor#start now calls set_state_to_root + show_state_trail after
6
+ # init to paint it immediately.
7
+ class TestModeBadge < VmaTest
8
+
9
+ def badge_text
10
+ vma.gui.statnfo.text
11
+ end
12
+
13
+ # Force a re-render regardless of the last painted value (update_mode_badge
14
+ # skips the update when the text is unchanged).
15
+ def render_badge
16
+ vma.gui.instance_variable_set(:@last_badge_text, nil)
17
+ vma.kbd.set_state_to_root
18
+ vma.kbd.show_state_trail
19
+ end
20
+
21
+ # The exact sequence Editor#start runs must paint a non-blank badge, even
22
+ # starting from the pre-fix state where the label is empty.
23
+ def test_startup_sequence_paints_badge
24
+ vma.kbd.set_mode(:command)
25
+ vma.gui.statnfo.text = "" # simulate the blank pre-fix state
26
+ render_badge
27
+ assert !badge_text.empty?, "mode badge should be painted, was blank"
28
+ assert_eq "COMMAND", badge_text
29
+ end
30
+
31
+ # Badge reflects the active mode.
32
+ def test_badge_reflects_mode
33
+ vma.kbd.set_mode(:insert)
34
+ render_badge
35
+ assert_eq "INSERT", badge_text
36
+
37
+ vma.kbd.set_mode(:command)
38
+ render_badge
39
+ assert_eq "COMMAND", badge_text
40
+ end
41
+ end
@@ -0,0 +1,67 @@
1
+ # Tests for the notepad keybinding scheme.
2
+ #
3
+ # Run separately: ruby exe/run_tests.rb notepad_bindings
4
+ # Excluded from the default suite (see exe/run_tests.rb): loading the
5
+ # notepad scheme permanently rebinds keys in the shared test process.
6
+ load "vimamsa/key_bindings_notepad.rb" # vimlike already required; applies overrides
7
+
8
+ class TestNotepadBindings < VmaTest
9
+ def test_typing_inserts_in_default_mode
10
+ keys "h i"
11
+ assert_mode :insert
12
+ assert_buf "hi\n"
13
+ end
14
+
15
+ def test_esc_clears_selection_stays_insert
16
+ act 'buf.insert_txt("abc")'
17
+ keys "shift-left shift-left"
18
+ assert vma.buf.selection_active?, "shift-left should select"
19
+ keys "esc"
20
+ assert_mode :insert
21
+ assert !vma.buf.selection_active?, "esc should clear selection"
22
+ end
23
+
24
+ def test_ctrl_a_selects_all
25
+ act 'buf.insert_txt("hello world")'
26
+ keys "ctrl-a"
27
+ assert vma.buf.selection_active?, "ctrl-a should activate selection"
28
+ r = vma.buf.get_visual_mode_range
29
+ assert_eq 0, r.begin
30
+ assert_eq vma.buf.size - 1, r.end
31
+ end
32
+
33
+ def test_delete_forward
34
+ act 'buf.insert_txt("abc")'
35
+ act :jump_to_start_of_buffer
36
+ keys "delete"
37
+ assert_buf "bc\n"
38
+ end
39
+
40
+ def test_home_end_keys
41
+ act 'buf.insert_txt("hello")'
42
+ keys "home"
43
+ assert_pos 0, 0
44
+ keys "end"
45
+ assert_eq 5, vma.buf.pos
46
+ end
47
+
48
+ def test_rebound_dispatch
49
+ # Assert rebinds without invoking GUI dialogs / quit
50
+ assert_eq "ctrl-f", vma.kbd.act_bindings["I"][:find_in_buffer]
51
+ assert_eq "ctrl-h", vma.kbd.act_bindings["I"][:gui_search_replace]
52
+ assert_eq "ctrl-q", vma.kbd.act_bindings["I"][:quit]
53
+ keys "ctrl-n" # safe to execute: creates a new buffer
54
+ assert_eq :buf_new, vma.kbd.cur_action
55
+ assert_mode :insert
56
+ end
57
+
58
+ private
59
+
60
+ # Framework default sets :command mode; the notepad scheme is
61
+ # insert-mode based, so make that explicit for each test.
62
+ def _setup_test
63
+ create_new_buffer("\n", "test", true)
64
+ vma.kbd.set_mode(:insert) rescue nil
65
+ drain_idle
66
+ end
67
+ end
@@ -0,0 +1,51 @@
1
+ # PopupFormGenerator serializes modal popups: only one shows at a time, the
2
+ # rest queue and appear as each closes. This prevents two modal dialogs (e.g.
3
+ # the session-restore dialog and a startup file's autosave dialog at startup)
4
+ # from grabbing input simultaneously and getting stuck.
5
+
6
+ class TestPopupQueue < VmaTest
7
+ def popup_params
8
+ { "inputs" => { "ok" => { :label => "OK", :type => :button } }, :callback => proc {} }
9
+ end
10
+
11
+ def test_second_popup_queues_until_first_closes
12
+ PopupFormGenerator.reset_popup_queue
13
+
14
+ p1 = PopupFormGenerator.new(popup_params)
15
+ p1.run
16
+ assert(PopupFormGenerator.popup_active?, "first popup should be active")
17
+ assert_eq(0, PopupFormGenerator.popup_queue_size)
18
+
19
+ # Second popup requested while the first is open -> queued, not shown.
20
+ p2 = PopupFormGenerator.new(popup_params)
21
+ p2.run
22
+ assert(PopupFormGenerator.popup_active?, "first popup still active")
23
+ assert_eq(1, PopupFormGenerator.popup_queue_size, "second popup should be queued")
24
+
25
+ # Close the first -> the queued popup is presented.
26
+ p1.close
27
+ drain_idle
28
+ assert(PopupFormGenerator.popup_active?, "queued popup should now be active")
29
+ assert_eq(0, PopupFormGenerator.popup_queue_size, "queue should be drained")
30
+
31
+ # Close the second -> nothing left active.
32
+ p2.close
33
+ drain_idle
34
+ assert(!PopupFormGenerator.popup_active?, "no popup should remain active")
35
+ ensure
36
+ PopupFormGenerator.reset_popup_queue
37
+ end
38
+
39
+ def test_single_popup_shows_immediately
40
+ PopupFormGenerator.reset_popup_queue
41
+ p1 = PopupFormGenerator.new(popup_params)
42
+ p1.run
43
+ assert(PopupFormGenerator.popup_active?)
44
+ assert_eq(0, PopupFormGenerator.popup_queue_size)
45
+ p1.close
46
+ drain_idle
47
+ assert(!PopupFormGenerator.popup_active?)
48
+ ensure
49
+ PopupFormGenerator.reset_popup_queue
50
+ end
51
+ end
@@ -0,0 +1,109 @@
1
+ # Random edit stress test — NOT part of the normal test suite.
2
+ # Run explicitly: vimamsa --test tests/test_random_edit.rb
3
+ #
4
+ # Executes editor actions at random for 30 seconds and fails if any
5
+ # action raises an unhandled exception (i.e. the editor crashes).
6
+
7
+ class TestRandomEdit < VmaTest
8
+
9
+ DURATION = 300 # seconds — override with duration=N on the command line
10
+
11
+ # Safe actions: no file dialogs, no eval, no close/save operations.
12
+ SAFE_ACTIONS = [
13
+ :e_move_forward_char,
14
+ :e_move_backward_char,
15
+ :move_next_line,
16
+ :move_prev_line,
17
+ :jump_to_start_of_buffer,
18
+ :jump_to_end_of_buffer,
19
+ :jump_end_of_line,
20
+ :jump_beginning_of_line,
21
+ :jump_next_word_end,
22
+ :jump_prev_word_start,
23
+ :jump_next_word_start,
24
+ :delete_char_forward,
25
+ :insert_backspace,
26
+ :delete_to_word_end,
27
+ :delete_to_next_word_start,
28
+ :delete_to_line_start,
29
+ :undo,
30
+ :redo,
31
+ :copy_cur_line,
32
+ :paste_after_cursor,
33
+ :paste_before_cursor,
34
+ :insert_new_line,
35
+ :page_down,
36
+ :page_up,
37
+ :center_on_current_line,
38
+ :gui_refresh_cursor,
39
+ ].freeze
40
+
41
+ RANDOM_TEXTS = [
42
+ "hello world",
43
+ "foo bar baz",
44
+ "test 123",
45
+ "abc def ghi",
46
+ " indented ",
47
+ "line\nbreak",
48
+ "x",
49
+ "longer text with spaces and stuff",
50
+ ].freeze
51
+
52
+ MODES = [:insert, :command, :visual].freeze
53
+
54
+ def test_random_editing_stress
55
+ duration = $vma_test_duration || DURATION
56
+ start_time = Time.now
57
+ iteration = 0
58
+ errors = []
59
+
60
+ # Seed the buffer with some content to work with
61
+ act 'buf.insert_txt("alpha\nbeta\ngamma\ndelta\nepsilon\nzeta\neta\n")'
62
+
63
+ while Time.now - start_time < duration
64
+ iteration += 1
65
+
66
+ begin
67
+ case rand(12)
68
+ when 0..5 then act_fast(SAFE_ACTIONS.sample)
69
+ when 6..7 then act_fast("buf.insert_txt(#{RANDOM_TEXTS.sample.inspect})")
70
+ when 8 then act_fast("vma.kbd.set_mode(:insert)")
71
+ when 9 then act_fast("vma.kbd.set_mode(:command)")
72
+ when 10 then act_fast("buf.start_selection; vma.kbd.set_mode(:visual)")
73
+ when 11 then act_fast(:jump_to_random)
74
+ end
75
+ rescue => e
76
+ errors << "iter #{iteration}: #{e.class}: #{e.message}"
77
+ end
78
+
79
+ if (iteration % 20).zero?
80
+ drain_idle
81
+ # Flush pending deltas to GTK before comparing — handle_deltas is not
82
+ # called by act_fast or drain_idle, so the GTK buffer lags otherwise.
83
+ vma.buf.view.handle_deltas
84
+
85
+ # Verify GTK and Ruby buffers are in sync
86
+ gtk_text = vma.buf.view.buffer.text
87
+ ruby_text = vma.buf.to_s
88
+ unless gtk_text == ruby_text
89
+ errors << "iter #{iteration}: GTK/Ruby buffer mismatch " \
90
+ "(gtk #{gtk_text.bytesize}B != ruby #{ruby_text.bytesize}B)"
91
+ end
92
+ end
93
+ end
94
+
95
+ # Restore a clean state
96
+ act("vma.kbd.set_mode(:command)") rescue nil
97
+ drain_idle
98
+
99
+ elapsed = (Time.now - start_time).round(1)
100
+ puts " Random edit stress: #{iteration} actions in #{elapsed}s"
101
+
102
+ unless errors.empty?
103
+ sample = errors.first(5).join("\n ")
104
+ raise VmaTestFailure,
105
+ "#{errors.size} error(s) during random editing:\n #{sample}"
106
+ end
107
+ end
108
+
109
+ end
@@ -0,0 +1,127 @@
1
+ require "tempfile"
2
+
3
+ # Reloading a file that was changed by an external program (buf.revert) must
4
+ # keep the cursor, the view and the edit positions on the same text.
5
+ class TestRevert < VmaTest
6
+
7
+ def open_temp(contents)
8
+ @tmp = Tempfile.new(["revert_test", ".txt"])
9
+ @tmp.write(contents)
10
+ @tmp.flush
11
+ open_new_file(File.expand_path(@tmp.path))
12
+ drain_idle
13
+ end
14
+
15
+ def write_external(contents)
16
+ File.write(@tmp.path, contents)
17
+ end
18
+
19
+ def revert
20
+ act "buf.revert"
21
+ drain_idle
22
+ end
23
+
24
+ def teardown_tmp
25
+ return if @tmp.nil?
26
+ @tmp.close
27
+ @tmp.unlink
28
+ @tmp = nil
29
+ end
30
+
31
+ def edit_pos_history
32
+ vma.buf.instance_variable_get(:@edit_pos_history)
33
+ end
34
+
35
+ def test_cursor_follows_lines_inserted_above
36
+ open_temp("aaa\nbbb\nccc\n")
37
+ act "buf.set_line_and_column_pos(2, 1)"
38
+ write_external("new1\nnew2\naaa\nbbb\nccc\n")
39
+ revert
40
+ assert_buf "new1\nnew2\naaa\nbbb\nccc\n"
41
+ assert_pos(4, 1)
42
+ ensure
43
+ teardown_tmp
44
+ end
45
+
46
+ def test_cursor_follows_edit_on_same_line
47
+ open_temp("foo bar baz\n")
48
+ act "buf.set_pos(8)" # on "baz"
49
+ write_external("foo XXXXX bar baz\n")
50
+ revert
51
+ assert_pos(0, 14)
52
+ assert_eq "baz", vma.buf.to_s[vma.buf.pos, 3]
53
+ ensure
54
+ teardown_tmp
55
+ end
56
+
57
+ def test_cursor_on_deleted_line
58
+ open_temp("aaa\nbbb\nccc\n")
59
+ act "buf.set_line_and_column_pos(1, 2)"
60
+ write_external("aaa\nccc\n")
61
+ revert
62
+ assert_buf "aaa\nccc\n"
63
+ assert_pos(1, 0)
64
+ ensure
65
+ teardown_tmp
66
+ end
67
+
68
+ def test_edit_positions_kept_and_shifted
69
+ open_temp("aaa\nbbb\nccc\n")
70
+ act "buf.set_line_and_column_pos(2, 0)"
71
+ keys("i x esc")
72
+ act "buf.save"
73
+ drain_idle
74
+ hist = edit_pos_history.dup
75
+ assert_eq [8], hist
76
+ write_external("top\n" + File.read(@tmp.path) + "end\n")
77
+ revert
78
+ # Shifted by the inserted line, and the external edits are not recorded
79
+ assert_eq [12], edit_pos_history
80
+ assert !vma.buf.unsaved_changes?, "buffer should match disk after reload"
81
+ ensure
82
+ teardown_tmp
83
+ end
84
+
85
+ def test_reload_is_one_undo_step
86
+ open_temp("aaa\nbbb\n")
87
+ write_external("x\naaa\ny\nbbb\nz\n")
88
+ revert
89
+ assert_buf "x\naaa\ny\nbbb\nz\n"
90
+ act "buf.undo"
91
+ assert_buf "aaa\nbbb\n"
92
+ ensure
93
+ teardown_tmp
94
+ end
95
+
96
+ def test_view_top_line_kept
97
+ lines = (0...300).map { |i| "line #{i}\n" }
98
+ open_temp(lines.join)
99
+ view = vma.buf.view
100
+ act "buf.set_line_and_column_pos(103, 0)"
101
+ view.scroll_to_top_pos(vma.buf.to_s.index("line 100\n"))
102
+ drain_idle
103
+ top = view.top_visible_pos
104
+ skip("view has no layout (headless?)") if top.nil? || vma.buf.to_s[top, 9] != "line 100\n"
105
+ nvis = view.visible_line_count
106
+ skip("window too small to show the cursor below the top line") if nvis.nil? || nvis < 10
107
+ write_external((0...10).map { |i| "added #{i}\n" }.join + lines.join)
108
+ revert
109
+ top = view.top_visible_pos
110
+ assert_eq "line 100\n", vma.buf.to_s[top, 9]
111
+ assert_pos(113, 0)
112
+ ensure
113
+ teardown_tmp
114
+ end
115
+
116
+ # Folded buffers can't be diffed against disk; the cursor is kept by line.
117
+ def test_folded_buffer_keeps_line
118
+ open_temp("a\nb\nc\n{{{\nx\n}}}\n")
119
+ act "buf.set_line_and_column_pos(2, 0)"
120
+ write_external("a\nb\nc\n{{{\nx\ny\n}}}\nd\n")
121
+ revert
122
+ assert_eq "a\nb\nc\n{{{\nx\ny\n}}}\nd\n", vma.buf.content_for_disk
123
+ assert_pos(2, 0)
124
+ ensure
125
+ teardown_tmp
126
+ end
127
+ end
@@ -0,0 +1,58 @@
1
+ require "tmpdir"
2
+
3
+ # cnf.startup_file is the buffer shown on startup even when the previous
4
+ # session is restored (restoring would otherwise leave its last file current).
5
+ class TestStartupFile < VmaTest
6
+ def test_startup_file_stays_current_after_session_restore
7
+ Dir.mktmpdir do |dir|
8
+ startup = "#{dir}/startup.txt"
9
+ a = "#{dir}/a.txt"
10
+ b = "#{dir}/b.txt"
11
+ File.write(startup, "startup\n")
12
+ File.write(a, "a\n")
13
+ File.write(b, "b\n")
14
+ session = get_dot_path("session.txt")
15
+ File.write(session, "#{a}\n#{b}\n")
16
+
17
+ open_new_file(startup)
18
+ vma.instance_variable_set(:@startup_fname, startup)
19
+ ENV["VIMAMSA_RESTORE_SESSION"] = "1"
20
+ begin
21
+ vma.check_session_restore
22
+ drain_idle
23
+ assert_eq startup, vma.buf.fname
24
+ assert vma.buffers.get_buffer_by_filename(a), "session file a restored"
25
+ assert vma.buffers.get_buffer_by_filename(b), "session file b restored"
26
+ ensure
27
+ ENV.delete("VIMAMSA_RESTORE_SESSION")
28
+ vma.instance_variable_set(:@startup_fname, nil)
29
+ File.delete(session) if File.exist?(session)
30
+ [b, a, startup].each { |f|
31
+ id = vma.buffers.get_buffer_by_filename(f)
32
+ vma.buffers.close_buffer(id) if id
33
+ }
34
+ drain_idle
35
+ end
36
+ end
37
+ end
38
+
39
+ def test_without_startup_file_last_session_file_is_current
40
+ Dir.mktmpdir do |dir|
41
+ a = "#{dir}/a.txt"
42
+ b = "#{dir}/b.txt"
43
+ File.write(a, "a\n")
44
+ File.write(b, "b\n")
45
+ begin
46
+ vma.restore_session_files([a, b])
47
+ drain_idle
48
+ assert_eq b, vma.buf.fname
49
+ ensure
50
+ [b, a].each { |f|
51
+ id = vma.buffers.get_buffer_by_filename(f)
52
+ vma.buffers.close_buffer(id) if id
53
+ }
54
+ drain_idle
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,50 @@
1
+ class TestStatusArea < VmaTest
2
+
3
+ # ── Mode badge CSS class + text ──────────────────────────────────────────
4
+
5
+ def test_badge_insert_mode
6
+ keys "i"
7
+ assert vma.gui.statnfo.css_classes.include?("mode-insert"), "badge should have mode-insert class"
8
+ assert_eq "INSERT", vma.gui.statnfo.text
9
+ keys "esc"
10
+ end
11
+
12
+ def test_badge_command_mode
13
+ keys "i esc"
14
+ assert vma.gui.statnfo.css_classes.include?("mode-command"), "badge should have mode-command class"
15
+ assert !vma.gui.statnfo.css_classes.include?("mode-insert"), "mode-insert class should be removed"
16
+ assert_eq "COMMAND", vma.gui.statnfo.text
17
+ end
18
+
19
+ def test_badge_visual_mode
20
+ keys "v"
21
+ assert vma.gui.statnfo.css_classes.include?("mode-visual"), "badge should have mode-visual class"
22
+ assert_eq "VISUAL", vma.gui.statnfo.text
23
+ keys "esc"
24
+ end
25
+
26
+ # ── Pending key trail ────────────────────────────────────────────────────
27
+
28
+ def test_keytrail_shows_pending_chord
29
+ keys ","
30
+ assert vma.gui.keytrail.text.include?(","), "keytrail should show pending chord key"
31
+ keys "esc"
32
+ assert_eq "", vma.gui.keytrail.text
33
+ end
34
+
35
+ def test_keytrail_shows_repeat_count
36
+ keys "3"
37
+ assert vma.gui.keytrail.text.include?("3"), "keytrail should show repeat count"
38
+ keys "esc"
39
+ end
40
+
41
+ # ── Modified marker in subtitle ──────────────────────────────────────────
42
+
43
+ def test_modified_marker_appears_on_edit
44
+ act 'buf.insert_txt("hello")'
45
+ act "buf.refresh_title"
46
+ drain_idle
47
+ assert vma.gui.subtitle.text.start_with?("+ "), "subtitle should start with \"+ \" after edit"
48
+ assert !vma.gui.subtitle.label.include?("foreground"), "modified marker should use the theme color"
49
+ end
50
+ end
@@ -0,0 +1,163 @@
1
+ require "tmpdir"
2
+
3
+ # Vim text objects (text_objects.rb). Each case: [text with "|" at the
4
+ # cursor, vim keys, expected text, expected cursor offset]. The expected
5
+ # values come from vim 9.1 (vim -Nu NONE); test_cases_match_real_vim checks
6
+ # them again when vim is installed.
7
+ class TestTextObjects < VmaTest
8
+ CASES = [
9
+ ["foo b|ar baz", "diw", "foo baz\n", 4],
10
+ ["foo b|ar baz", "daw", "foo baz\n", 4],
11
+ ["foo b|ar", "daw", "foo\n", 2],
12
+ [" |foo", "daw", " \n", 1],
13
+ ["foo | bar", "daw", "foo\n", 2],
14
+ ["foo | bar", "diw", "foobar\n", 3],
15
+ ["foo.b|ar", "diw", "foo.\n", 3],
16
+ ["foo x.b|ar(1) z", "diW", "foo z\n", 4],
17
+ ["foo x.b|ar(1) z", "daW", "foo z\n", 4],
18
+ ["foo bar |\n", "daw", "foo bar \n", 8],
19
+ ["say \"h|i\" now", "di\"", "say \"\" now\n", 5],
20
+ ["say \"h|i\" now", "da\"", "say now\n", 4],
21
+ ["say \"hi|\"", "da\"", "say\n", 2],
22
+ ["\"a\" |x \"b\"", "di\"", "\"a\"\"b\"\n", 3],
23
+ ["x |y \"a\" \"b\"", "di\"", "x y \"\" \"b\"\n", 5],
24
+ ["a \"q\" |b", "da\"", "a \"q\" b\n", 6],
25
+ ["it's |a 'q'", "di'", "it''q'\n", 3],
26
+ ["a `c|d` b", "di`", "a `` b\n", 3],
27
+ ["say \"|\"", "ci\"Z", "say \"Z\"\n", 5],
28
+ ["a(b,|c)d", "di(", "a()d\n", 2],
29
+ ["a(b,|c)d", "da(", "ad\n", 1],
30
+ ["a(b,|c)d", "dib", "a()d\n", 2],
31
+ ["a(b,|c)d", "di)", "a()d\n", 2],
32
+ ["a|(b)d", "di(", "a()d\n", 2],
33
+ ["x (a) |y (b)", "di(", "x (a) y ()\n", 9],
34
+ ["x (a (|b) c)", "2di(", "x ()\n", 3],
35
+ ["a [x|y] b", "di[", "a [] b\n", 3],
36
+ ["a [x|y] b", "da]", "a b\n", 2],
37
+ ["f {\n a|b\n c\n}\nz", "di{", "f {\n}\nz\n", 4],
38
+ ["f {\n a|b\n c\n}\nz", "da{", "f \nz\n", 1],
39
+ ["f { a|b }\nz", "diB", "f {}\nz\n", 3],
40
+ ["x <a|b> y", "di<", "x <> y\n", 3],
41
+ ["x\nf(a,\n |b)\nz", "di(", "x\nf()\nz\n", 4],
42
+ ["a(|)b", "ci(Z", "a(Z)b\n", 2],
43
+ ["f {\n a|b\n}\nz", "ci{Z", "f {\nZ\n}\nz\n", 4],
44
+ ["x()|y", "di(", "x()y\n", 3],
45
+ ["<a><b>x|y</b></a>", "dit", "<a><b></b></a>\n", 6],
46
+ ["<a><b>x|y</b></a>", "dat", "<a></a>\n", 3],
47
+ ["<a><b>xy</b>|z</a>", "dit", "<a></a>\n", 3],
48
+ ["<a x=\"1\">|<br>q</a>", "dit", "<a x=\"1\"></a>\n", 9],
49
+ ["<a><b>x|y</b></a>", "2dit", "<a></a>\n", 3],
50
+ ["Hi there. This |is it. And more.", "dis", "Hi there. And more.\n", 10],
51
+ ["Hi there. This |is it. And more.", "das", "Hi there. And more.\n", 10],
52
+ ["Hi there. This is it. And |more.", "das", "Hi there. This is it.\n", 20],
53
+ ["p1\np|1b\n\n\np2", "dip", "\n\np2\n", 0],
54
+ ["p1\np|1b\n\n\np2", "dap", "p2\n", 0],
55
+ ["p1\n\np2\np|2b", "dap", "p1\n", 0],
56
+ ["p1\n|\n\np2", "dip", "p1\np2\n", 3],
57
+ ["p1\n|\n\np2", "dap", "p1\n", 0],
58
+ ["p1\np|1b\n\np2", "cipZ", "Z\n\np2\n", 0],
59
+ ["ab|c d", "gUiw", "ABC d\n", 0],
60
+ ["x (a|B) y", "g~i(", "x (Ab) y\n", 3],
61
+ ["X 'A|B'", "gua'", "X 'ab'\n", 1],
62
+ ["a [x|y] b", "vi[d", "a [] b\n", 3],
63
+ ["foo b|ar baz", "vawd", "foo baz\n", 4],
64
+ ["p1\np|1b\n\np2", "vipd", "\np2\n", 0],
65
+ ["say \"h|i\" now", "va\"d", "say now\n", 4],
66
+ ]
67
+
68
+ # Cases that end in Insert mode: the cursor after esc differs from vim's
69
+ # (vim -es stays in Insert mode), so only the text is compared.
70
+ def inserts?(keys)
71
+ keys =~ /^(\d*)c/
72
+ end
73
+
74
+ def run_case(text, keys)
75
+ pre, rest = text.split("|", 2)
76
+ s = pre + rest
77
+ s += "\n" unless s.end_with?("\n")
78
+ pos = pre.size
79
+ # vim's Normal mode cursor can't be on the newline of a non-empty line
80
+ pos -= 1 if s[pos] == "\n" && pos > 0 && s[pos - 1] != "\n"
81
+ b = vma.buf
82
+ b.set_content(s)
83
+ b.set_pos(pos)
84
+ vma.kbd.set_mode(:command)
85
+ k = keys.chars
86
+ k << "esc" if inserts?(keys)
87
+ keys(k.join(" "))
88
+ [b.to_s, b.pos]
89
+ end
90
+
91
+ def test_cases
92
+ fails = []
93
+ CASES.each { |text, keys, want, want_pos|
94
+ got, got_pos = run_case(text, keys)
95
+ ok = got == want && (inserts?(keys) || got_pos == want_pos)
96
+ fails << "#{text.inspect} #{keys}: got #{got.inspect} pos #{got_pos}, vim #{want.inspect} pos #{want_pos}" if !ok
97
+ vma.kbd.set_mode(:command)
98
+ }
99
+ assert fails.empty?, "#{fails.size} of #{CASES.size} cases differ from vim:\n " + fails.join("\n ")
100
+ end
101
+
102
+ def test_yank_word
103
+ run_case("x foo|bar y", "yiw")
104
+ assert_eq "foobar", vma.clipboard.get
105
+ assert_eq 2, vma.buf.pos
106
+ assert_buf "x foobar y\n"
107
+ end
108
+
109
+ def test_yank_paragraph_is_linewise
110
+ run_case("p1\np|1b\n\np2", "yip")
111
+ assert_eq "p1\np1b\n", vma.clipboard.get
112
+ assert vma.buf.instance_variable_get(:@paste_lines), "yip should yank whole lines"
113
+ end
114
+
115
+ def test_delete_puts_text_in_clipboard
116
+ run_case('say "h|i" now', 'di"')
117
+ assert_eq "hi", vma.clipboard.get
118
+ end
119
+
120
+ def test_change_enters_insert_mode
121
+ vma.buf.set_content("a(b,c)d\n")
122
+ vma.buf.set_pos(4)
123
+ keys("c i (")
124
+ assert_mode :insert
125
+ assert_buf "a()d\n"
126
+ assert_eq 2, vma.buf.pos
127
+ end
128
+
129
+ def test_no_object_changes_nothing
130
+ run_case("plain| text", "di(")
131
+ assert_buf "plain text\n"
132
+ assert_mode :command
133
+ end
134
+
135
+ def test_visual_append_bindings_still_work
136
+ # vimlike's Visual "a y" (copy, append to clipboard) shares the "a" prefix
137
+ vma.clipboard.set("old")
138
+ run_case("ab|cd", "v")
139
+ keys("l a y")
140
+ assert_eq "cd\nold", vma.clipboard.get
141
+ end
142
+
143
+ def vim_result(text, keys)
144
+ pre, rest = text.split("|", 2)
145
+ Dir.mktmpdir { |d|
146
+ f = "#{d}/f.txt"
147
+ File.write(f, pre + rest + (rest.end_with?("\n") ? "" : "\n"))
148
+ k = keys.gsub("\\", "\\\\\\\\").gsub('"', '\\"')
149
+ system("vim", "-Nu", "NONE", "-i", "NONE", "-es", "-c", "go #{pre.bytesize + 1}",
150
+ "-c", "exe \"norm! #{k}\"",
151
+ "-c", "call writefile([line2byte(line('.'))+col('.')-2], '#{d}/p')", "-c", "wq", f)
152
+ [File.read(f), File.read("#{d}/p").to_i]
153
+ }
154
+ end
155
+
156
+ def test_cases_match_real_vim
157
+ skip "vim not installed" unless system("command -v vim >/dev/null 2>&1")
158
+ fails = CASES.reject { |text, keys, want, want_pos|
159
+ vim_result(text, keys) == [want, want_pos]
160
+ }
161
+ assert fails.empty?, "expected values out of date for this vim: #{fails.map { |c| c[0, 2] }.inspect}"
162
+ end
163
+ end