vimamsa 0.1.26 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) 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 +195 -99
  6. data/custom_example.rb +59 -17
  7. data/doc/TODO.md +678 -0
  8. data/doc/action_names_plan.md +442 -0
  9. data/doc/bundling_plan.md +570 -0
  10. data/doc/delta_syntax_plan.md +293 -0
  11. data/doc/demo_recording_plan.md +288 -0
  12. data/doc/design_goals.md +27 -0
  13. data/doc/intro_page_plan.md +266 -0
  14. data/doc/key_bindings_report_plan.md +213 -0
  15. data/doc/line_tree_plan.md +89 -0
  16. data/doc/missing_vim_bindings.md +61 -0
  17. data/doc/modules_settings_plan.md +433 -0
  18. data/doc/refactor_dedup_plan.md +117 -0
  19. data/doc/registries_plan.md +202 -0
  20. data/doc/startup_speed_plan.md +97 -0
  21. data/doc/treap_visualizer.html +585 -0
  22. data/doc/unused_code_plan.md +120 -0
  23. data/doc/vim_compatibility_plan.md +451 -0
  24. data/doc/vimlike_vim_conflicts.md +262 -0
  25. data/doc/vm_snapshots_plan.md +146 -0
  26. data/doc/wysiwyg_plan.md +231 -0
  27. data/exe/run_tests.rb +124 -3
  28. data/exe/vimamsa +68 -5
  29. data/fonts/OFL-Oxanium.txt +93 -0
  30. data/fonts/Oxanium[wght].ttf +0 -0
  31. data/help/intro.txt +30 -0
  32. data/help/vim_intro.txt +31 -0
  33. data/icon.png +0 -0
  34. data/img/demo.gif +0 -0
  35. data/img/demo.mp4 +0 -0
  36. data/lang/hyperplaintext.lang +7 -1
  37. data/lib/vimamsa/ack.rb +13 -1
  38. data/lib/vimamsa/actions.rb +385 -37
  39. data/lib/vimamsa/appimage_env.rb +35 -0
  40. data/lib/vimamsa/audio.rb +2 -5
  41. data/lib/vimamsa/bookmarks.rb +302 -0
  42. data/lib/vimamsa/buffer.rb +675 -118
  43. data/lib/vimamsa/buffer_changetext.rb +150 -68
  44. data/lib/vimamsa/buffer_cursor.rb +7 -0
  45. data/lib/vimamsa/buffer_list.rb +6 -2
  46. data/lib/vimamsa/buffer_manager.rb +10 -7
  47. data/lib/vimamsa/bundled_fonts.rb +32 -0
  48. data/lib/vimamsa/cli_help.rb +75 -0
  49. data/lib/vimamsa/clipboard.rb +9 -3
  50. data/lib/vimamsa/conf.rb +68 -3
  51. data/lib/vimamsa/constants.rb +3 -0
  52. data/lib/vimamsa/crash_handler.rb +149 -0
  53. data/lib/vimamsa/debug.rb +6 -3
  54. data/lib/vimamsa/demo_player.rb +458 -0
  55. data/lib/vimamsa/demo_recorder.rb +277 -0
  56. data/lib/vimamsa/desktop_install.rb +96 -0
  57. data/lib/vimamsa/diff_buffer.rb +40 -11
  58. data/lib/vimamsa/dot_repeat.rb +104 -0
  59. data/lib/vimamsa/easy_jump.rb +57 -3
  60. data/lib/vimamsa/editor.rb +327 -78
  61. data/lib/vimamsa/encrypt.rb +78 -29
  62. data/lib/vimamsa/file_finder.rb +4 -19
  63. data/lib/vimamsa/file_history.rb +4 -1
  64. data/lib/vimamsa/file_manager.rb +46 -31
  65. data/lib/vimamsa/fold.rb +226 -0
  66. data/lib/vimamsa/form_input.rb +388 -0
  67. data/lib/vimamsa/gui.rb +603 -119
  68. data/lib/vimamsa/gui_command_line.rb +247 -0
  69. data/lib/vimamsa/gui_dialog.rb +94 -42
  70. data/lib/vimamsa/gui_file_panel.rb +356 -25
  71. data/lib/vimamsa/gui_form_generator.rb +75 -40
  72. data/lib/vimamsa/gui_func_panel.rb +67 -22
  73. data/lib/vimamsa/gui_image.rb +3 -0
  74. data/lib/vimamsa/gui_key_hint.rb +165 -0
  75. data/lib/vimamsa/gui_keylog_panel.rb +408 -0
  76. data/lib/vimamsa/gui_menu.rb +84 -53
  77. data/lib/vimamsa/gui_select_window.rb +80 -75
  78. data/lib/vimamsa/gui_settings.rb +86 -41
  79. data/lib/vimamsa/gui_sourceview.rb +280 -92
  80. data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
  81. data/lib/vimamsa/gui_text.rb +63 -2
  82. data/lib/vimamsa/gui_theme.rb +615 -0
  83. data/lib/vimamsa/hook.rb +5 -0
  84. data/lib/vimamsa/hyper_plain_text.rb +3 -0
  85. data/lib/vimamsa/intro_page.rb +368 -0
  86. data/lib/vimamsa/key_actions.rb +382 -193
  87. data/lib/vimamsa/key_binding_tree.rb +467 -273
  88. data/lib/vimamsa/key_bindings_notepad.rb +45 -0
  89. data/lib/vimamsa/key_bindings_report.rb +484 -0
  90. data/lib/vimamsa/key_bindings_vim.rb +104 -0
  91. data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
  92. data/lib/vimamsa/key_names.rb +80 -0
  93. data/lib/vimamsa/langservp.rb +271 -54
  94. data/lib/vimamsa/line_tree.rb +367 -0
  95. data/lib/vimamsa/macro.rb +23 -3
  96. data/lib/vimamsa/main.rb +14 -8
  97. data/lib/vimamsa/rbvma.rb +41 -1
  98. data/lib/vimamsa/registers.rb +125 -0
  99. data/lib/vimamsa/run_ruby.rb +64 -0
  100. data/lib/vimamsa/search.rb +3 -0
  101. data/lib/vimamsa/search_replace.rb +15 -14
  102. data/lib/vimamsa/string_util.rb +134 -40
  103. data/lib/vimamsa/terminal.rb +3 -0
  104. data/lib/vimamsa/test_framework.rb +28 -2
  105. data/lib/vimamsa/tests.rb +11 -8
  106. data/lib/vimamsa/text_objects.rb +310 -0
  107. data/lib/vimamsa/text_transforms.rb +18 -0
  108. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  109. data/lib/vimamsa/user_dirs.rb +83 -0
  110. data/lib/vimamsa/util.rb +46 -7
  111. data/lib/vimamsa/version.rb +1 -1
  112. data/lib/vimamsa/vim_core.rb +355 -0
  113. data/lib/vimamsa/vim_operators.rb +365 -0
  114. data/lib/vimamsa.rb +0 -1
  115. data/modules/calculator/calculator.rb +5 -5
  116. data/modules/color_highlight/color_highlight.rb +118 -0
  117. data/modules/color_highlight/color_highlight_info.rb +3 -0
  118. data/modules/dictation/dictation.rb +1054 -0
  119. data/modules/dictation/dictation_info.rb +3 -0
  120. data/modules/dictation/whisper_worker.py +273 -0
  121. data/modules/ollama/ollama.rb +107 -0
  122. data/modules/ollama/ollama_info.rb +3 -0
  123. data/modules/terminal/terminal.rb +5 -5
  124. data/modules/tts/tts.rb +119 -0
  125. data/modules/tts/tts_info.rb +3 -0
  126. data/run_e2e_vm.sh +28 -0
  127. data/run_tests_vm.rb +138 -0
  128. data/scripts/appimage/AppRun +54 -0
  129. data/scripts/appimage/Dockerfile +18 -0
  130. data/scripts/appimage/build.sh +19 -0
  131. data/scripts/appimage/build_in_container.sh +192 -0
  132. data/scripts/appimage/smoke_test.sh +27 -0
  133. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  134. data/scripts/demo/demo_files_steps.txt +52 -0
  135. data/scripts/demo/demo_steps.txt +67 -0
  136. data/scripts/demo/notes.txt +6 -0
  137. data/scripts/demo/record_demo.rb +156 -0
  138. data/scripts/demo/report.rb +7 -0
  139. data/scripts/demo/shapes.rb +29 -0
  140. data/scripts/demo/square/shapes.rb +29 -0
  141. data/scripts/demo/square/steps.txt +185 -0
  142. data/scripts/lib/perf_startup.rb +138 -0
  143. data/scripts/lib/script_helpers.rb +53 -0
  144. data/scripts/perf_compare.rb +34 -0
  145. data/scripts/profile_startup.rb +72 -0
  146. data/styles/134272-molokai.xml +3 -0
  147. data/styles/molokai_cyber.xml +48 -0
  148. data/styles/molokai_edit.xml +1 -0
  149. data/tests/support/virtual_keyboard.rb +254 -0
  150. data/tests/support/virtual_mic.rb +67 -0
  151. data/tests/test_ack.rb +22 -0
  152. data/tests/test_action_ids.rb +232 -0
  153. data/tests/test_auto_format.rb +122 -0
  154. data/tests/test_autocomplete.rb +211 -0
  155. data/tests/test_autosave.rb +145 -0
  156. data/tests/test_basic_editing.rb +46 -16
  157. data/tests/test_bookmarks.rb +206 -0
  158. data/tests/test_bracket_match.rb +88 -0
  159. data/tests/test_bundling.rb +92 -0
  160. data/tests/test_cli_help.rb +64 -0
  161. data/tests/test_color_highlight.rb +92 -0
  162. data/tests/test_command_line.rb +79 -0
  163. data/tests/test_command_line_file.rb +27 -0
  164. data/tests/test_context_menu_file.rb +147 -0
  165. data/tests/test_copy_paste.rb +106 -26
  166. data/tests/test_crash_handler.rb +39 -0
  167. data/tests/test_custom_two_phase.rb +92 -0
  168. data/tests/test_demo_player.rb +301 -0
  169. data/tests/test_demo_recorder.rb +202 -0
  170. data/tests/test_dialog_callback_errors.rb +44 -0
  171. data/tests/test_dictation.rb +294 -0
  172. data/tests/test_diff_buffer_name.rb +51 -0
  173. data/tests/test_dot_repeat.rb +88 -0
  174. data/tests/test_double_click.rb +41 -0
  175. data/tests/test_drag_selection.rb +125 -0
  176. data/tests/test_e2e_cmdline.rb +116 -0
  177. data/tests/test_e2e_dictation.rb +98 -0
  178. data/tests/test_e2e_replace_char.rb +58 -0
  179. data/tests/test_easy_jump.rb +93 -0
  180. data/tests/test_extract_file_links.rb +55 -0
  181. data/tests/test_file_format.rb +217 -0
  182. data/tests/test_file_manager.rb +72 -0
  183. data/tests/test_file_panel.rb +269 -0
  184. data/tests/test_flash.rb +78 -0
  185. data/tests/test_fold.rb +111 -0
  186. data/tests/test_font_refresh.rb +56 -0
  187. data/tests/test_form_input.rb +203 -0
  188. data/tests/test_func_panel.rb +68 -0
  189. data/tests/test_grep_apply.rb +46 -0
  190. data/tests/test_gtk_sync.rb +126 -0
  191. data/tests/test_hpt_highlight_visible.rb +75 -0
  192. data/tests/test_hpt_link_highlight.rb +82 -0
  193. data/tests/test_intro_page.rb +437 -0
  194. data/tests/test_jump_to_file.rb +41 -0
  195. data/tests/test_key_bindings.rb +208 -0
  196. data/tests/test_key_categories.rb +163 -0
  197. data/tests/test_keylog_panel.rb +261 -0
  198. data/tests/test_line_ends.rb +51 -0
  199. data/tests/test_line_tree.rb +86 -0
  200. data/tests/test_lsp_clangd.rb +281 -0
  201. data/tests/test_lsp_jump.rb +87 -0
  202. data/tests/test_lsp_position_encoding.rb +49 -0
  203. data/tests/test_lsp_symbols.rb +68 -0
  204. data/tests/test_macro.rb +137 -0
  205. data/tests/test_markdown_highlight.rb +57 -0
  206. data/tests/test_mode_badge.rb +41 -0
  207. data/tests/test_module_interface.rb +9 -9
  208. data/tests/test_notepad_bindings.rb +67 -0
  209. data/tests/test_perf_startup.rb +28 -0
  210. data/tests/test_popup_queue.rb +51 -0
  211. data/tests/test_random_edit.rb +109 -0
  212. data/tests/test_registers.rb +122 -0
  213. data/tests/test_revert.rb +127 -0
  214. data/tests/test_run_ruby.rb +77 -0
  215. data/tests/test_startup_file.rb +58 -0
  216. data/tests/test_status_area.rb +50 -0
  217. data/tests/test_text_objects.rb +163 -0
  218. data/tests/test_text_transforms.rb +341 -0
  219. data/tests/test_tmp_user_dir.rb +79 -0
  220. data/tests/test_tts.rb +68 -0
  221. data/tests/test_undo.rb +34 -34
  222. data/tests/test_user_dirs.rb +122 -0
  223. data/tests/test_vim_bindings.rb +353 -0
  224. data/tests/test_vim_conflicts.rb +100 -0
  225. data/tests/test_vim_operators.rb +116 -0
  226. data/tests/test_window_layout.rb +302 -0
  227. data/vimamsa.gemspec +3 -1
  228. data/vm_guest_run.sh +129 -0
  229. metadata +167 -10
@@ -1,27 +1,46 @@
1
+
2
+ module Vimamsa
1
3
  class FileTreePanel
2
- COL_LABEL = 0
4
+ COL_LABEL = 0 # Pango markup
3
5
  COL_BUF_ID = 1 # 0 = folder row (not selectable)
6
+ COL_CLOSE = 2 # close button markup; nil on folder rows
7
+ COL_MARK = 3 # mark char on mark rows; "" on the "Marks" header; nil otherwise
8
+
9
+ CLOSE_GLYPH = "×"
4
10
 
5
11
  def initialize
6
- @store = Gtk::TreeStore.new(String, Integer)
7
- @tree = Gtk::TreeView.new(@store)
8
- @tree.headers_visible = false
9
- @tree.activate_on_single_click = true
10
- @tree.level_indentation = 7
11
-
12
- renderer = Gtk::CellRendererText.new
13
- renderer.ellipsize = Pango::EllipsizeMode::START
14
- col = Gtk::TreeViewColumn.new("", renderer, text: COL_LABEL)
15
- col.expand = true
16
- @tree.append_column(col)
17
-
18
- @tree.signal_connect("row-activated") do |tv, path, _col|
19
- iter = @store.get_iter(path)
20
- next if iter.nil?
12
+ @store = Gtk::TreeStore.new(String, Integer, String, String)
13
+ @tree, @sw = build_list_tree(@store, ellipsize: Pango::EllipsizeMode::START,
14
+ text_col: COL_LABEL, markup: true) do |iter|
15
+ mark = iter[COL_MARK]
16
+ if mark && !mark.empty?
17
+ vma.buf.jump_to_mark(mark)
18
+ next
19
+ end
21
20
  buf_id = iter[COL_BUF_ID]
22
21
  next if buf_id.nil? || buf_id == 0
22
+ next if @close_click # this click belonged to the close button
23
23
  vma.buffers.set_current_buffer(buf_id)
24
24
  end
25
+ @tree.level_indentation = 7
26
+
27
+ # Small close (x) button directly in front of each file name: a glyph cell
28
+ # packed first into the name column, so it follows the row indentation.
29
+ # Its hover/pressed tint is a Pango span background, so it covers only the
30
+ # button (a cell background would also fill the indentation).
31
+ @close_renderer = Gtk::CellRendererText.new
32
+ col = @tree.get_column(0)
33
+ col.pack_start(@close_renderer, false)
34
+ col.reorder(@close_renderer, 0)
35
+ col.add_attribute(@close_renderer, "markup", COL_CLOSE)
36
+
37
+ # Paths are ellipsized at the start (keep the file name visible); mark
38
+ # rows at the end, so the mark char and line number stay visible.
39
+ text_renderer = col.cells.find { |c| !c.equal?(@close_renderer) }
40
+ col.set_cell_data_func(text_renderer) do |_col, r, _model, iter|
41
+ r.ellipsize = iter[COL_MARK].nil? ? Pango::EllipsizeMode::START : Pango::EllipsizeMode::END
42
+ end
43
+ init_close_button_events
25
44
 
26
45
  @context_menu = nil
27
46
  rightclick = Gtk::GestureClick.new
@@ -38,17 +57,151 @@ class FileTreePanel
38
57
  show_context_menu(x, y)
39
58
  end
40
59
 
41
- @sw = Gtk::ScrolledWindow.new
42
- @sw.set_policy(:never, :automatic)
43
- @sw.set_child(@tree)
44
60
  @sw.set_size_request(180, -1)
45
61
  @sw.vexpand = true
62
+ @sw.add_css_class("side-panel")
46
63
  end
47
64
 
48
65
  def widget
49
66
  @sw
50
67
  end
51
68
 
69
+ # { buf_id => label markup } for the file rows (tests / introspection).
70
+ def row_labels
71
+ file_rows.transform_values { |iter| iter[COL_LABEL] }
72
+ end
73
+
74
+ def file_rows
75
+ h = {}
76
+ @store.each do |_model, _path, iter|
77
+ next if iter[COL_BUF_ID] == 0
78
+ h[iter[COL_BUF_ID]] = iter
79
+ end
80
+ h
81
+ end
82
+
83
+ # Button-like feedback for the close icon: tinted on hover, darker while
84
+ # pressed; the file closes on release over the same button (dragging off
85
+ # cancels, like a real button).
86
+ def init_close_button_events
87
+ @close_hover = nil
88
+ @close_pressed = nil
89
+
90
+ click = Gtk::GestureClick.new
91
+ click.button = 1
92
+ # Capture phase + claim: the tree's own click handling (select/activate
93
+ # row) must not see presses on the close button.
94
+ click.propagation_phase = :capture
95
+ @tree.add_controller(click)
96
+ click.signal_connect("pressed") do |gesture, _n, x, y|
97
+ id = close_hit(x, y)
98
+ @close_click = !id.nil?
99
+ next unless id
100
+ gesture.set_state(:claimed)
101
+ close_press(id)
102
+ end
103
+ click.signal_connect("released") do |_g, _n, x, y|
104
+ close_release(close_hit(x, y))
105
+ end
106
+ click.signal_connect("stopped") { close_release(nil) if @close_pressed }
107
+
108
+ motion = Gtk::EventControllerMotion.new
109
+ @tree.add_controller(motion)
110
+ motion.signal_connect("motion") { |_c, x, y| set_close_hover(close_hit(x, y)) }
111
+ motion.signal_connect("leave") { set_close_hover(nil) }
112
+ end
113
+
114
+ # buf_id of the file row whose close button is at widget coords (x, y), else nil.
115
+ def close_hit(x, y)
116
+ bx, by = @tree.convert_widget_to_bin_window_coords(x.to_i, y.to_i)
117
+ path, col, = @tree.get_path_at_pos(bx, by)
118
+ return nil unless path && col
119
+ iter = @store.get_iter(path)
120
+ return nil unless iter && iter[COL_BUF_ID].to_i != 0
121
+ area = @tree.get_cell_area(path, col)
122
+ (bx >= area.x && bx < area.x + close_w) ? iter[COL_BUF_ID] : nil
123
+ end
124
+
125
+ # Width of the close button cell, px (its natural width: the glyph + padding).
126
+ def close_w
127
+ @close_renderer.markup = close_markup(nil)
128
+ @close_renderer.get_preferred_width(@tree)[1]
129
+ end
130
+
131
+ # Widget coords of the center of a file row's close button (tests).
132
+ def close_button_center(buf_id)
133
+ path = file_rows[buf_id]&.path
134
+ return nil unless path
135
+ area = @tree.get_cell_area(path, @tree.get_column(0))
136
+ @tree.convert_bin_window_to_widget_coords(area.x + close_w / 2, area.y + area.height / 2)
137
+ end
138
+
139
+ def close_press(buf_id)
140
+ @close_pressed = buf_id
141
+ update_close_bg
142
+ end
143
+
144
+ # Release over buf_id's close button (nil = elsewhere): closes the file only
145
+ # if it is the one that was pressed.
146
+ def close_release(buf_id)
147
+ pressed = @close_pressed
148
+ @close_pressed = nil
149
+ update_close_bg
150
+ # @close_click suppresses the row activation of this same click; clear it
151
+ # once the click's other handlers have run.
152
+ GLib::Idle.add { @close_click = false; false }
153
+ close_buffer_from_panel(pressed) if pressed && pressed == buf_id
154
+ end
155
+
156
+ def set_close_hover(buf_id)
157
+ return if buf_id == @close_hover
158
+ @close_hover = buf_id
159
+ update_close_bg
160
+ end
161
+
162
+ # :pressed, :hover or :normal
163
+ def close_state(buf_id)
164
+ if buf_id == @close_pressed
165
+ :pressed
166
+ elsif buf_id == @close_hover && @close_pressed.nil?
167
+ :hover
168
+ else
169
+ :normal
170
+ end
171
+ end
172
+
173
+ def close_markup(buf_id)
174
+ case close_state(buf_id)
175
+ when :pressed
176
+ "<span background=\"#{panel_color(:file_panel_close_pressed_bg)}\" weight=\"bold\"> #{CLOSE_GLYPH} </span>"
177
+ when :hover
178
+ "<span background=\"#{panel_color(:file_panel_close_hover_bg)}\"> #{CLOSE_GLYPH} </span>"
179
+ else
180
+ "<span fgalpha=\"55%\"> #{CLOSE_GLYPH} </span>"
181
+ end
182
+ end
183
+
184
+ def update_close_bg
185
+ file_rows.each do |id, iter|
186
+ m = close_markup(id)
187
+ iter[COL_CLOSE] = m if iter[COL_CLOSE] != m
188
+ end
189
+ end
190
+
191
+ # Deferred: closing refreshes (clears) the store, which must not happen
192
+ # inside the tree's own row-activated emission. A non-current file is
193
+ # closed in the background so the current file stays in view.
194
+ def close_buffer_from_panel(buf_id)
195
+ GLib::Idle.add do
196
+ if vma.buf&.id == buf_id
197
+ vma.buffers.close_buffer(buf_id)
198
+ else
199
+ vma.buffers.close_other_buffer(buf_id)
200
+ end
201
+ false
202
+ end
203
+ end
204
+
52
205
  def init_context_menu
53
206
  act = Gio::SimpleAction.new("fp_close_buffer")
54
207
  vma.gui.app.add_action(act)
@@ -67,8 +220,9 @@ class FileTreePanel
67
220
  @context_menu.popup
68
221
  end
69
222
 
70
- def refresh
71
- @store.clear
223
+ # Buffers grouped by directory in the panel's display order:
224
+ # [[dirname, [{bname:, buf:}, ...]], ...], dirs and files sorted by name.
225
+ def grouped_buffers
72
226
  bh = {}
73
227
  vma.buffers.list.each do |b|
74
228
  dname = b.fname ? File.dirname(b.fname) : "*"
@@ -76,19 +230,196 @@ class FileTreePanel
76
230
  bh[dname] ||= []
77
231
  bh[dname] << { bname: bname, buf: b }
78
232
  end
233
+ bh.keys.sort.map { |dname| [dname, bh[dname].sort_by { |x| x[:bname] }] }
234
+ end
235
+
236
+ # Switch to the file `delta` rows away (±1) from the current buffer in the
237
+ # panel's display order, wrapping at the ends.
238
+ def select_adjacent(delta)
239
+ ids = grouped_buffers.flat_map { |_, files| files.map { |x| x[:buf].id } }
240
+ return if ids.empty?
241
+ i = ids.index(vma.buf&.id)
242
+ target = i.nil? ? ids.first : ids[(i + delta) % ids.size]
243
+ vma.buffers.set_current_buffer(target)
244
+ end
79
245
 
80
- bh.keys.sort.each do |dname|
246
+ # ── Easy jump: label file rows, switch to the file whose label is typed ──
247
+ # Same mechanism as EasyJump (easy_jump.rb): a whole-keyboard override
248
+ # captures label input; labels are rendered by prefixing the row text.
249
+
250
+ EJ_CHARS = "ASDFJKLGHQWERUIOPTYZXCVBNM".split("")
251
+
252
+ def easy_jump_active?
253
+ !@ej_targets.nil?
254
+ end
255
+
256
+ # Single-char labels while they suffice, else all 2-char pairs — never mixed
257
+ # lengths, so no label is a prefix of another.
258
+ def ej_labels(n)
259
+ return EJ_CHARS.first(n) if n <= EJ_CHARS.size
260
+ EJ_CHARS.product(EJ_CHARS).map(&:join).first(n)
261
+ end
262
+
263
+ def easy_jump_start
264
+ easy_jump_cancel if easy_jump_active?
265
+ file_rows = grouped_buffers.flat_map { |_, files| files }
266
+ return if file_rows.empty?
267
+
268
+ labels = ej_labels(file_rows.size)
269
+ @ej_targets = {}
270
+ file_rows.each_with_index { |bnfo, i| @ej_targets[labels[i]] = bnfo[:buf].id }
271
+ @ej_input = ""
272
+
273
+ # Prefix each file row's label in the store; row order matches
274
+ # grouped_buffers (refresh builds the store from it).
275
+ i = 0
276
+ @store.each do |_model, _path, iter|
277
+ next if iter[COL_BUF_ID] == 0
278
+ iter[COL_LABEL] = "#{ej_label_markup(labels[i])} #{iter[COL_LABEL]}"
279
+ i += 1
280
+ end
281
+
282
+ vma.kbd.set_keyhandling_override(self.method(:easy_jump_input_char))
283
+ end
284
+
285
+ def easy_jump_input_char(c, event_type)
286
+ return true if event_type != :key_press
287
+ # esc or any non-plain key (ctrl-x, alt-x, ...) aborts
288
+ if c.size != 1
289
+ easy_jump_cancel
290
+ return true
291
+ end
292
+
293
+ @ej_input << c.upcase
294
+ id = @ej_targets[@ej_input]
295
+ if id
296
+ target = id
297
+ easy_jump_cancel # remove override before switching; switch refreshes
298
+ vma.buffers.set_current_buffer(target)
299
+ elsif @ej_targets.keys.none? { |l| l.start_with?(@ej_input) }
300
+ easy_jump_cancel
301
+ end
302
+ return true
303
+ end
304
+
305
+ def easy_jump_cancel
306
+ vma.kbd.remove_keyhandling_override
307
+ @ej_targets = nil
308
+ refresh # rebuild rows without label prefixes
309
+ end
310
+
311
+ def panel_color(name)
312
+ cnf.theme.cyberpunk_glow? ? cyber_color(name) : theme_color(name)
313
+ end
314
+
315
+ # Current file: bold + brighter fg. Kept in the markup (not a cell-wide
316
+ # attribute) so an easy-jump label span keeps its own color on this row.
317
+ def current_markup(escaped)
318
+ "<span foreground=\"#{panel_color(:file_panel_current_fg)}\" weight=\"bold\">#{escaped}</span>"
319
+ end
320
+
321
+ # Reddish bold label; a TreeView cell cannot do a CSS text-shadow, so the
322
+ # "glow" is a translucent background tint around the label.
323
+ def ej_label_markup(label)
324
+ "<span foreground=\"#{panel_color(:file_panel_ej_label_fg)}\" weight=\"bold\" " \
325
+ "background=\"#{panel_color(:file_panel_ej_label_glow)}\" bgalpha=\"30%\"> #{label} </span>"
326
+ end
327
+
328
+ # ── Marks of the current file (m <char>), shown above the files ──
329
+
330
+ MARK_TEXT_MAX = 40 # chars of the marked line shown after the line number
331
+ MARK_NEAR_MAX = 50 # how far to look for text when a mark is on an empty line
332
+
333
+ # { char => [lpos (0-based), text, dir] } of vma.buf's user marks, by char.
334
+ # text is the marked line's, or for an empty line the nearest non-empty
335
+ # line's, with dir :below / :above saying where it is (nil: the marked line).
336
+ def current_marks
337
+ b = vma.buf
338
+ return {} unless b
339
+ b.user_marks.to_h do |c, pos|
340
+ lpos = b.get_line_pos(pos)
341
+ [c, [lpos, *mark_text(b, lpos)]]
342
+ end
343
+ end
344
+
345
+ # [text, dir] for the mark list; see current_marks. Ties go to the line
346
+ # below, which is usually what a mark before a paragraph is for.
347
+ def mark_text(b, lpos)
348
+ text = b.line(lpos).to_s.strip
349
+ return [text, nil] unless text.empty?
350
+ nlines = b.line_ends.size
351
+ (1..MARK_NEAR_MAX).each do |d|
352
+ [[lpos + d, :below], [lpos - d, :above]].each do |l, dir|
353
+ next if l < 0 or l >= nlines
354
+ t = b.line(l).to_s.strip
355
+ return [t, dir] unless t.empty?
356
+ end
357
+ end
358
+ ["", nil]
359
+ end
360
+
361
+ def mark_label(c, lpos, text, dir = nil)
362
+ text = text[0, MARK_TEXT_MAX] + "…" if text.size > MARK_TEXT_MAX
363
+ arrow = { below: "↓ ", above: "↑ " }[dir].to_s
364
+ "<b>#{CGI.escapeHTML(c)}</b> #{lpos + 1}: #{arrow}#{CGI.escapeHTML(text)}"
365
+ end
366
+
367
+ # { char => label markup } for the mark rows (tests / introspection).
368
+ def mark_rows
369
+ h = {}
370
+ @store.each do |_m, _p, iter|
371
+ m = iter[COL_MARK]
372
+ h[m] = iter[COL_LABEL] if m && !m.empty?
373
+ end
374
+ h
375
+ end
376
+
377
+ # Rebuild only the marks section (first top-level row), leaving the file
378
+ # rows and the scroll position alone.
379
+ def refresh_marks
380
+ first = @store.iter_first
381
+ @store.remove(first) if first && first[COL_MARK] == ""
382
+ marks = current_marks
383
+ return if marks.empty?
384
+ head = @store.insert(nil, 0)
385
+ head[COL_LABEL] = CGI.escapeHTML("📌 Marks")
386
+ head[COL_BUF_ID] = 0
387
+ head[COL_MARK] = ""
388
+ marks.each do |c, (lpos, text, dir)|
389
+ it = @store.append(head)
390
+ it[COL_LABEL] = mark_label(c, lpos, text, dir)
391
+ it[COL_BUF_ID] = 0
392
+ it[COL_MARK] = c
393
+ end
394
+ @tree.expand_row(head.path, true)
395
+ end
396
+
397
+ def refresh
398
+ # A buffer-list change mid-pick must not leave a stale override installed
399
+ # or labels pointing at rows that no longer exist.
400
+ if easy_jump_active?
401
+ vma.kbd.remove_keyhandling_override
402
+ @ej_targets = nil
403
+ end
404
+
405
+ @store.clear
406
+ grouped_buffers.each do |dname, files|
81
407
  dir_iter = @store.append(nil)
82
- dir_iter[COL_LABEL] = "📂 #{tilde_path(dname)}"
408
+ dir_iter[COL_LABEL] = CGI.escapeHTML("📂 #{tilde_path(dname)}")
83
409
  dir_iter[COL_BUF_ID] = 0
84
- bh[dname].sort_by { |x| x[:bname] }.each do |bnfo|
410
+ files.each do |bnfo|
85
411
  active_mark = bnfo[:buf].is_active? ? "● " : " "
412
+ current = bnfo[:buf].equal?(vma.buf) # Buffer < String: == compares text
86
413
  file_iter = @store.append(dir_iter)
87
- file_iter[COL_LABEL] = "#{active_mark}#{bnfo[:bname]}"
414
+ label = CGI.escapeHTML("#{active_mark}#{bnfo[:bname]}")
415
+ file_iter[COL_LABEL] = current ? current_markup(label) : label
88
416
  file_iter[COL_BUF_ID] = bnfo[:buf].id
417
+ file_iter[COL_CLOSE] = close_markup(bnfo[:buf].id)
89
418
  end
90
419
  end
91
420
 
92
421
  @tree.expand_all
422
+ refresh_marks
93
423
  end
94
424
  end
425
+ end # module Vimamsa
@@ -1,20 +1,58 @@
1
+
2
+ module Vimamsa
1
3
  # PopupFormGenerator.new().run
2
4
  class PopupFormGenerator
5
+ # Modal popups are serialized: only one is visible at a time. Presenting two
6
+ # transient modal windows together (e.g. the session-restore dialog and a
7
+ # startup file's autosave dialog at startup) makes them grab input from each
8
+ # other and get stuck, so queue any popup requested while another is active
9
+ # and show it once the active one closes.
10
+ @@popup_active = nil
11
+ @@popup_queue = []
12
+
13
+ # Present the next queued popup, if any. Called when the active popup closes.
14
+ def self.advance_popup_queue
15
+ @@popup_active = nil
16
+ nxt = @@popup_queue.shift
17
+ nxt&.present_now
18
+ end
19
+
20
+ # Test/utility hook: forget any queued/active popups.
21
+ def self.reset_popup_queue
22
+ @@popup_active = nil
23
+ @@popup_queue = []
24
+ end
25
+
26
+ def self.popup_active? = !@@popup_active.nil?
27
+ def self.popup_queue_size = @@popup_queue.size
28
+
29
+ # The form's keys go through the key bindings, in form mode (form_input.rb)
30
+ attr_reader :form
31
+
3
32
  def submit()
4
- for id, entry in @vals
5
- @ret[id] = entry.text
33
+ for id, field in @vals
34
+ @ret[id] = field.text
6
35
  end
36
+ # Back to the editor's mode before the callback, which may change it
37
+ @form.deactivate
7
38
  if !@callback.nil?
8
- @callback.call(@ret)
39
+ run_dialog_callback("form submit") { @callback.call(@ret) }
9
40
  end
41
+ close
42
+ end
43
+
44
+ # Close this popup and present the next queued one, if any. All close paths
45
+ # (submit, cancel, escape, window close) route through here. GTK4 has no
46
+ # widget "destroy" signal to hook, so the queue is advanced explicitly.
47
+ def close
48
+ @form.deactivate
10
49
  @window.destroy
50
+ PopupFormGenerator.advance_popup_queue if @@popup_active.equal?(self)
11
51
  end
12
52
 
13
53
  def initialize(params = nil)
14
54
  @ret = {}
15
- @window = Gtk::Window.new()
16
- # @window.screen = main_window.screen
17
- # @window.title = title
55
+ @window = make_modal_window()
18
56
  # params = {}
19
57
  # params["inputs"] = {}
20
58
  # params["inputs"]["search"] = { :label => "Search", :type => :entry }
@@ -22,17 +60,18 @@ class PopupFormGenerator
22
60
  # params["inputs"]["btn1"] = { :label => "Replace all", :type => :button }
23
61
  # params[:callback] = proc { |x| puts "====="; puts x.inspect; puts "=====" }
24
62
 
25
-
26
63
  @callback = params[:callback]
27
- @window.title = ""
28
- @window.set_transient_for($vmag.window) if $vmag&.window
29
- @window.modal = true
64
+ @form = FormInput.new(@window, submit: method(:submit), cancel: method(:close))
65
+ # Window manager close (title-bar X): advance the queue too, then let GTK
66
+ # destroy the window (return false). Programmatic closes go through #close.
67
+ @window.signal_connect("close-request") do
68
+ @form.deactivate
69
+ PopupFormGenerator.advance_popup_queue if @@popup_active.equal?(self)
70
+ false
71
+ end
30
72
 
31
73
  frame = Gtk::Frame.new()
32
- frame.margin_bottom = 8
33
- frame.margin_top = 8
34
- frame.margin_end = 8
35
- frame.margin_start = 8
74
+ frame.margin = 8
36
75
 
37
76
  @window.set_child(frame)
38
77
 
@@ -41,10 +80,7 @@ class PopupFormGenerator
41
80
  # @callback = params["callback"]
42
81
 
43
82
  vbox = Gtk::Box.new(:vertical, 8)
44
- vbox.margin_bottom = 8
45
- vbox.margin_top = 8
46
- vbox.margin_end = 8
47
- vbox.margin_start = 8
83
+ vbox.margin = 8
48
84
 
49
85
  frame.set_child(vbox)
50
86
 
@@ -69,6 +105,7 @@ class PopupFormGenerator
69
105
  @ret[id] = "submit"
70
106
  submit
71
107
  end
108
+ @form.add_button(button)
72
109
  elsif elem[:type] == :entry
73
110
  label = Gtk::Label.new(elem[:label])
74
111
  entry = Gtk::Entry.new
@@ -77,22 +114,7 @@ class PopupFormGenerator
77
114
  end
78
115
  hbox.append(label)
79
116
  hbox.append(entry)
80
- @vals[id] = entry
81
-
82
- press = Gtk::EventControllerKey.new
83
- press.set_propagation_phase(Gtk::PropagationPhase::CAPTURE)
84
- entry.add_controller(press)
85
- press.signal_connect "key-pressed" do |gesture, keyval, keycode, y|
86
- if keyval == Gdk::Keyval::KEY_Return
87
- submit
88
- true
89
- elsif keyval == Gdk::Keyval::KEY_Escape
90
- @window.destroy
91
- true
92
- else
93
- false
94
- end
95
- end
117
+ @vals[id] = @form.add_field(entry)
96
118
  end
97
119
  end # each
98
120
 
@@ -100,23 +122,36 @@ class PopupFormGenerator
100
122
 
101
123
  cancel_button = Gtk::Button.new(:label => "Cancel")
102
124
  cancel_button.signal_connect "clicked" do
103
- @window.destroy
125
+ close
104
126
  end
105
127
  hbox.append(cancel_button)
128
+ @form.add_button(cancel_button)
106
129
  @cancel_button = cancel_button
107
130
  return
108
131
  end
109
132
 
110
133
  def run
111
- if !@window.visible?
112
- @window.show
113
- else
114
- @window.destroy
134
+ # If another popup is already showing, queue this one; it is presented when
135
+ # the active popup closes (see advance_popup_queue).
136
+ if @@popup_active && !@@popup_active.instance_variable_get(:@window).destroyed?
137
+ @@popup_queue << self
138
+ return @window
115
139
  end
140
+ present_now
141
+ end
142
+
143
+ # Actually show the window now and mark it as the active popup.
144
+ def present_now
145
+ @@popup_active = self
146
+ @window.present
147
+ @form.activate
116
148
  if !@default_button.nil?
117
- @default_button.grab_focus
149
+ @form.focus_item(@default_button)
150
+ else
151
+ @form.focus(0)
118
152
  end
119
153
  @window.set_focus_visible(true)
120
154
  @window
121
155
  end
122
156
  end
157
+ end # module Vimamsa