vimamsa 0.1.27 → 0.1.29

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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/appimage.yml +17 -10
  3. data/Dockerfile +2 -2
  4. data/README.md +162 -90
  5. data/custom_example.rb +33 -15
  6. data/doc/TODO.md +334 -110
  7. data/doc/action_names_plan.md +442 -0
  8. data/doc/bundling_plan.md +2 -1
  9. data/doc/delta_syntax_plan.md +293 -0
  10. data/doc/demo_recording_plan.md +288 -0
  11. data/doc/design_goals.md +27 -0
  12. data/doc/intro_page_plan.md +266 -0
  13. data/doc/key_bindings_report_plan.md +45 -0
  14. data/doc/line_tree_plan.md +89 -0
  15. data/doc/missing_vim_bindings.md +34 -44
  16. data/doc/modules_settings_plan.md +1 -1
  17. data/doc/registries_plan.md +202 -0
  18. data/doc/startup_speed_plan.md +97 -0
  19. data/doc/test_commands.md +232 -0
  20. data/doc/treap_visualizer.html +585 -0
  21. data/doc/vim_compatibility_plan.md +186 -31
  22. data/doc/vimlike_vim_conflicts.md +236 -228
  23. data/doc/vm_snapshots_plan.md +4 -4
  24. data/doc/wysiwyg_plan.md +231 -0
  25. data/docker_cmd.sh +1 -1
  26. data/exe/run_tests.rb +85 -3
  27. data/exe/vimamsa +49 -6
  28. data/help/intro.txt +30 -0
  29. data/help/vim_intro.txt +31 -0
  30. data/img/demo.gif +0 -0
  31. data/img/demo.mp4 +0 -0
  32. data/lang/hyperplaintext.lang +1 -1
  33. data/lib/vimamsa/ack.rb +2 -0
  34. data/lib/vimamsa/actions.rb +381 -36
  35. data/lib/vimamsa/bookmarks.rb +8 -8
  36. data/lib/vimamsa/buffer.rb +84 -38
  37. data/lib/vimamsa/buffer_changetext.rb +58 -36
  38. data/lib/vimamsa/buffer_list.rb +2 -2
  39. data/lib/vimamsa/buffer_manager.rb +6 -6
  40. data/lib/vimamsa/cli_help.rb +75 -0
  41. data/lib/vimamsa/clipboard.rb +6 -3
  42. data/lib/vimamsa/conf.rb +9 -0
  43. data/lib/vimamsa/crash_handler.rb +2 -2
  44. data/lib/vimamsa/debug.rb +2 -2
  45. data/lib/vimamsa/demo_player.rb +494 -0
  46. data/lib/vimamsa/demo_recorder.rb +277 -0
  47. data/lib/vimamsa/diff_buffer.rb +1 -1
  48. data/lib/vimamsa/dot_repeat.rb +104 -0
  49. data/lib/vimamsa/easy_jump.rb +54 -3
  50. data/lib/vimamsa/editor.rb +136 -65
  51. data/lib/vimamsa/file_history.rb +1 -1
  52. data/lib/vimamsa/file_manager.rb +23 -23
  53. data/lib/vimamsa/form_input.rb +388 -0
  54. data/lib/vimamsa/gui.rb +89 -13
  55. data/lib/vimamsa/gui_command_line.rb +44 -5
  56. data/lib/vimamsa/gui_form_generator.rb +17 -6
  57. data/lib/vimamsa/gui_func_panel.rb +1 -1
  58. data/lib/vimamsa/gui_key_hint.rb +165 -0
  59. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  60. data/lib/vimamsa/gui_menu.rb +69 -50
  61. data/lib/vimamsa/gui_select_window.rb +77 -43
  62. data/lib/vimamsa/gui_settings.rb +9 -5
  63. data/lib/vimamsa/gui_sourceview.rb +28 -81
  64. data/lib/vimamsa/gui_theme.rb +11 -2
  65. data/lib/vimamsa/hook.rb +2 -0
  66. data/lib/vimamsa/intro_page.rb +367 -0
  67. data/lib/vimamsa/key_actions.rb +315 -225
  68. data/lib/vimamsa/key_binding_tree.rb +228 -61
  69. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  70. data/lib/vimamsa/key_bindings_report.rb +290 -67
  71. data/lib/vimamsa/key_bindings_vim.rb +43 -297
  72. data/lib/vimamsa/key_bindings_vim_core.rb +356 -0
  73. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  74. data/lib/vimamsa/key_names.rb +80 -0
  75. data/lib/vimamsa/langservp.rb +62 -7
  76. data/lib/vimamsa/line_tree.rb +367 -0
  77. data/lib/vimamsa/macro.rb +20 -3
  78. data/lib/vimamsa/rbvma.rb +15 -0
  79. data/lib/vimamsa/registers.rb +125 -0
  80. data/lib/vimamsa/run_ruby.rb +64 -0
  81. data/lib/vimamsa/search_replace.rb +4 -4
  82. data/lib/vimamsa/string_util.rb +17 -3
  83. data/lib/vimamsa/tests.rb +8 -8
  84. data/lib/vimamsa/text_objects.rb +11 -54
  85. data/lib/vimamsa/text_transforms.rb +4 -0
  86. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  87. data/lib/vimamsa/user_dirs.rb +83 -0
  88. data/lib/vimamsa/version.rb +1 -1
  89. data/lib/vimamsa/vim_operators.rb +365 -0
  90. data/modules/calculator/calculator.rb +5 -5
  91. data/modules/color_highlight/color_highlight.rb +3 -3
  92. data/modules/dictation/dictation.rb +32 -32
  93. data/modules/ollama/ollama.rb +5 -5
  94. data/modules/terminal/terminal.rb +5 -5
  95. data/modules/tts/tts.rb +10 -10
  96. data/run_e2e_vm.sh +3 -3
  97. data/run_tests_vm.rb +163 -0
  98. data/scripts/appimage/AppRun +7 -0
  99. data/scripts/appimage/build_in_container.sh +11 -1
  100. data/scripts/appimage/smoke_test.sh +1 -1
  101. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  102. data/scripts/demo/demo_files_steps.txt +52 -0
  103. data/scripts/demo/demo_steps.txt +9 -1
  104. data/scripts/demo/notes.txt +6 -0
  105. data/scripts/demo/record_demo.rb +60 -81
  106. data/scripts/demo/report.rb +7 -0
  107. data/scripts/demo/shapes.rb +1 -0
  108. data/scripts/demo/square/shapes.rb +29 -0
  109. data/scripts/demo/square/steps.txt +185 -0
  110. data/scripts/lib/perf_startup.rb +138 -0
  111. data/scripts/lib/script_helpers.rb +53 -0
  112. data/scripts/perf_compare.rb +34 -0
  113. data/scripts/profile_startup.rb +72 -0
  114. data/tests/test_action_ids.rb +232 -0
  115. data/tests/test_auto_format.rb +2 -2
  116. data/tests/test_autocomplete.rb +1 -1
  117. data/tests/test_basic_editing.rb +18 -18
  118. data/tests/test_bookmarks.rb +6 -6
  119. data/tests/test_bracket_match.rb +3 -0
  120. data/tests/test_cli_help.rb +64 -0
  121. data/tests/test_color_highlight.rb +2 -2
  122. data/tests/test_command_line.rb +1 -1
  123. data/tests/test_context_menu_file.rb +18 -0
  124. data/tests/test_copy_paste.rb +33 -33
  125. data/tests/test_custom_two_phase.rb +1 -1
  126. data/tests/test_demo_player.rb +355 -0
  127. data/tests/test_demo_recorder.rb +202 -0
  128. data/tests/test_dictation.rb +16 -16
  129. data/tests/test_dot_repeat.rb +88 -0
  130. data/tests/test_easy_jump.rb +93 -0
  131. data/tests/test_extract_file_links.rb +3 -3
  132. data/tests/test_file_panel.rb +2 -2
  133. data/tests/test_flash.rb +1 -1
  134. data/tests/test_fold.rb +1 -1
  135. data/tests/test_form_input.rb +203 -0
  136. data/tests/test_func_panel.rb +2 -2
  137. data/tests/test_gtk_sync.rb +7 -7
  138. data/tests/test_intro_page.rb +437 -0
  139. data/tests/test_key_categories.rb +163 -0
  140. data/tests/test_keylog_panel.rb +163 -3
  141. data/tests/test_line_ends.rb +51 -0
  142. data/tests/test_line_tree.rb +86 -0
  143. data/tests/test_lsp_clangd.rb +2 -2
  144. data/tests/test_lsp_root.rb +43 -0
  145. data/tests/test_macro.rb +2 -2
  146. data/tests/test_module_interface.rb +9 -9
  147. data/tests/test_notepad_bindings.rb +5 -5
  148. data/tests/test_perf_startup.rb +28 -0
  149. data/tests/test_random_edit.rb +27 -27
  150. data/tests/test_registers.rb +131 -0
  151. data/tests/test_run_ruby.rb +77 -0
  152. data/tests/test_startup_file.rb +45 -4
  153. data/tests/test_text_objects.rb +1 -1
  154. data/tests/test_text_transforms.rb +12 -0
  155. data/tests/test_tmp_user_dir.rb +79 -0
  156. data/tests/test_tts.rb +10 -10
  157. data/tests/test_undo.rb +34 -34
  158. data/tests/test_user_dirs.rb +122 -0
  159. data/tests/test_vim_bindings.rb +107 -6
  160. data/tests/test_vim_conflicts.rb +41 -4
  161. data/tests/test_vim_operators.rb +116 -0
  162. data/tests/test_window_layout.rb +83 -0
  163. data/vimamsa.gemspec +1 -1
  164. data/vm_guest_run.sh +75 -28
  165. metadata +60 -4
  166. data/run_tests.rb +0 -89
  167. data/run_tests_vm.sh +0 -130
@@ -0,0 +1,388 @@
1
+ module Vimamsa
2
+ # Form input mode (doc/demo_recording_plan.md, part 1): typing in a form goes
3
+ # through the key bindings, so the key log shows it and a demo can record and
4
+ # replay it.
5
+ #
6
+ # A form field is a normal GTK widget (Gtk::Entry) that only shows the text;
7
+ # the text and cursor are in a vimamsa Buffer (FormField). The form window's
8
+ # keys never reach the widgets: a capture-phase controller turns them into the
9
+ # editor's key names (key_names.rb) and gives them to the key bindings, in
10
+ # mode F (:form) while the form is up. The form.* actions edit the current
11
+ # field's buffer and then show it in the widget.
12
+ #
13
+ # Changes the widget makes itself (a paste from the right-click menu, a middle
14
+ # click, an input method) are copied into the buffer; so are the cursor and a
15
+ # selection made with the mouse, read before each key.
16
+ #
17
+ # Basic keys only (like a GTK entry): typing, backspace, delete, left / right,
18
+ # home / end, ctrl-a / ctrl-c / ctrl-x / ctrl-v; tab / shift-tab between the
19
+ # fields and buttons, enter submits (or presses the focused button), esc
20
+ # cancels.
21
+
22
+ # One field: a Gtk::Entry showing a Buffer
23
+ class FormField
24
+ attr_reader :entry, :buf
25
+ # Called with the new text when it changes (e.g. to filter a list)
26
+ attr_accessor :on_change
27
+
28
+ def initialize(entry)
29
+ @entry = entry
30
+ # A Buffer with a view that is never shown, not in the buffer list
31
+ @buf = Buffer.new(entry.text.to_s + "\n", nil, "form-field")
32
+ @buf.set_pos(text.size)
33
+ @sel = nil # [from, to) or nil
34
+ entry.signal_connect("changed") { pull_text if !@syncing }
35
+ sync
36
+ end
37
+
38
+ def text
39
+ @buf.to_s.chomp
40
+ end
41
+
42
+ def pos
43
+ @buf.pos
44
+ end
45
+
46
+ # [from, to) of the selected text, or nil
47
+ attr_reader :sel
48
+
49
+ def selected_text
50
+ @sel ? text[@sel[0]...@sel[1]] : nil
51
+ end
52
+
53
+ # The widget's cursor and selection (set with the mouse) into the buffer
54
+ def pull_cursor
55
+ return if @syncing
56
+ a, b = entry_selection
57
+ if a && b && a != b
58
+ @sel = [[a, b].min, [a, b].max]
59
+ else
60
+ @sel = nil
61
+ end
62
+ p = @entry.position
63
+ @buf.set_pos(p.clamp(0, text.size)) if p && p != pos
64
+ end
65
+
66
+ # Text the widget changed by itself (paste from its menu, input method)
67
+ def pull_text
68
+ t = @entry.text.to_s
69
+ return if t == text
70
+ @buf.delete_range(0, text.size - 1, register: false) if text.size > 0
71
+ @buf.insert_txt_at(t, 0) if t.size > 0
72
+ @buf.set_pos(@entry.position.to_i.clamp(0, text.size))
73
+ @sel = nil
74
+ changed
75
+ end
76
+
77
+ # The buffer into the widget
78
+ def sync
79
+ changed
80
+ @syncing = true
81
+ @entry.text = text if @entry.text.to_s != text
82
+ if @sel
83
+ @entry.select_region(@sel[0], @sel[1])
84
+ else
85
+ @entry.position = pos
86
+ end
87
+ ensure
88
+ @syncing = false
89
+ end
90
+
91
+ def insert(s)
92
+ s = s.to_s.gsub(/[\r\n]+/, " ")
93
+ return if s.empty?
94
+ delete_selection
95
+ at = pos
96
+ @buf.insert_txt_at(s, at)
97
+ @buf.set_pos(at + s.size)
98
+ end
99
+
100
+ # Deletes the selection; false if there is none
101
+ def delete_selection
102
+ return false if @sel.nil?
103
+ a, b = @sel
104
+ @sel = nil
105
+ @buf.delete_range(a, b - 1, register: false) if b > a
106
+ @buf.set_pos(a)
107
+ true
108
+ end
109
+
110
+ def backspace
111
+ return if delete_selection || pos == 0
112
+ at = pos
113
+ @buf.delete_range(at - 1, at - 1, register: false)
114
+ @buf.set_pos(at - 1)
115
+ end
116
+
117
+ def delete
118
+ return if delete_selection || pos >= text.size
119
+ @buf.delete_range(pos, pos, register: false)
120
+ end
121
+
122
+ def move_to(p)
123
+ @sel = nil
124
+ @buf.set_pos(p.clamp(0, text.size))
125
+ end
126
+
127
+ def select_all
128
+ @sel = text.empty? ? nil : [0, text.size]
129
+ @buf.set_pos(text.size)
130
+ end
131
+
132
+ # Copy / cut use the system clipboard, not the registers
133
+ def copy
134
+ t = selected_text
135
+ set_system_clipboard(t) if t && !t.empty?
136
+ end
137
+
138
+ def cut
139
+ copy
140
+ delete_selection
141
+ end
142
+
143
+ # The system clipboard's text at the cursor (over the selection). The
144
+ # clipboard is read asynchronously; the field is shown when it arrives.
145
+ def paste
146
+ vma.gui.window.display.clipboard.read_text_async do |cb, result|
147
+ t = (cb.read_text_finish(result) rescue nil)
148
+ if t && !t.empty?
149
+ insert(t)
150
+ sync
151
+ end
152
+ end
153
+ end
154
+
155
+ # Stops the buffer's autosave thread and removes its hidden view
156
+ def dispose
157
+ @buf.instance_variable_get(:@autosave_thread)&.kill
158
+ gui_close_buffer(@buf.id)
159
+ end
160
+
161
+ private
162
+
163
+ # on_change, if the text is new
164
+ def changed
165
+ return if text == @last_text
166
+ @last_text = text
167
+ @on_change&.call(text)
168
+ end
169
+
170
+ def entry_selection
171
+ r = @entry.selection_bounds
172
+ return [nil, nil] if !r.is_a?(Array)
173
+ r = r[1..] if r.size == 3 # [found, start, end]
174
+ r
175
+ rescue
176
+ [nil, nil]
177
+ end
178
+ end
179
+
180
+ # The form whose window is up: its fields and buttons, in focus order
181
+ class FormInput
182
+ class << self
183
+ # The form taking the keys, or nil
184
+ attr_accessor :current
185
+ end
186
+
187
+ attr_reader :window, :fields, :items
188
+ # Extra keys of this form: { up: proc, down: proc, delete: proc } (a
189
+ # list's selection; delete overrides deleting a char)
190
+ attr_accessor :key_handlers
191
+
192
+ # submit: called with no arguments by enter in a field; cancel: by esc
193
+ def initialize(window, submit:, cancel:)
194
+ @window = window
195
+ @submit = submit
196
+ @cancel = cancel
197
+ @fields = []
198
+ @items = [] # fields' entries and buttons, in tab order
199
+ @index = 0
200
+ @last_keyval = nil
201
+ @key_handlers = {}
202
+ install_key_handler
203
+ end
204
+
205
+ def add_field(entry)
206
+ f = FormField.new(entry)
207
+ @fields << f
208
+ @items << entry
209
+ focus_tracking(entry)
210
+ f
211
+ end
212
+
213
+ def add_button(button)
214
+ @items << button
215
+ focus_tracking(button)
216
+ end
217
+
218
+ # The focused item: a FormField's entry or a button
219
+ def focused
220
+ @items[@index]
221
+ end
222
+
223
+ def field
224
+ @fields.find { |f| f.entry.equal?(focused) }
225
+ end
226
+
227
+ def focus(i)
228
+ return if @items.empty?
229
+ @index = i % @items.size
230
+ @items[@index].grab_focus
231
+ field&.sync
232
+ end
233
+
234
+ def focus_item(widget)
235
+ i = @items.index { |w| w.equal?(widget) }
236
+ focus(i) if i
237
+ end
238
+
239
+ def next_item = focus(@index + 1)
240
+ def prev_item = focus(@index - 1)
241
+
242
+ # The form takes the keys: mode F
243
+ def activate
244
+ FormInput.current = self
245
+ @prev_stack = vma.kbd.default_mode_stack.dup
246
+ vma.kbd.set_mode(:form)
247
+ end
248
+
249
+ # Back to the mode before; the fields' buffers go away (once, also for a
250
+ # form that was never shown)
251
+ def deactivate
252
+ if FormInput.current.equal?(self)
253
+ FormInput.current = nil
254
+ if vma.kbd.get_mode == :form && @prev_stack
255
+ vma.kbd.set_mode_stack(@prev_stack)
256
+ vma.kbd.__set_mode(@prev_stack[-1])
257
+ end
258
+ end
259
+ @fields.each(&:dispose) if !@disposed
260
+ @disposed = true
261
+ end
262
+
263
+ # enter: press the focused button, or submit
264
+ def enter
265
+ w = focused
266
+ if w.is_a?(Gtk::Button)
267
+ w.signal_emit("clicked")
268
+ else
269
+ @submit.call
270
+ end
271
+ end
272
+
273
+ def cancel
274
+ @cancel.call
275
+ end
276
+
277
+ # A key of the form window, as the editor window does it
278
+ # (VSourceView#handle_key_event): released alone, "ctrl!" etc.
279
+ def key(keyval, keystr, sig)
280
+ f = field
281
+ f&.pull_cursor
282
+ k = gui_key_name(keyval, keystr)
283
+ return if k == ""
284
+ if sig == :key_release
285
+ vma.kbd.match_key_conf(k + "!", nil, :key_release) if keyval == @last_keyval
286
+ else
287
+ vma.kbd.match_key_conf(k, nil, :key_press)
288
+ end
289
+ @last_keyval = keyval
290
+ end
291
+
292
+ private
293
+
294
+ def install_key_handler
295
+ press = Gtk::EventControllerKey.new
296
+ press.set_propagation_phase(Gtk::PropagationPhase::CAPTURE)
297
+ @window.add_controller(press)
298
+ to_str = lambda { |kv| Gdk::Keyval.to_unicode(kv).chr("UTF-8") }
299
+ press.signal_connect("key-pressed") { |_c, keyval, _code, _st|
300
+ run_dialog_callback("form key") { key(keyval, to_str.(keyval), :key_press) }
301
+ true
302
+ }
303
+ press.signal_connect("key-released") { |_c, keyval, _code, _st|
304
+ run_dialog_callback("form key") { key(keyval, to_str.(keyval), :key_release) }
305
+ true
306
+ }
307
+ press.signal_connect("modifiers") { |_c, modtype| gui_set_modifiers(modtype); true }
308
+ end
309
+
310
+ # A click (or GTK moving the focus) makes the item current
311
+ def focus_tracking(widget)
312
+ fc = Gtk::EventControllerFocus.new
313
+ fc.signal_connect("enter") {
314
+ i = @items.index { |w| w.equal?(widget) }
315
+ @index = i if i
316
+ }
317
+ widget.add_controller(fc)
318
+ end
319
+ end
320
+
321
+ # The current form's field, or nil (form.* actions)
322
+ def form_field
323
+ FormInput.current&.field
324
+ end
325
+
326
+ # Mode F, the form.* actions and their keys. Called by Editor#start after the
327
+ # keymap is loaded (and by vimamsa --help), so every scheme has them.
328
+ def form_input_setup
329
+ # editor-wide: not saved in the buffer's mode stack
330
+ vma.kbd.add_mode("F", :form, scope: :editor)
331
+ f = lambda { |&blk| proc { |*a| (x = form_field) && blk.call(x, *a) } }
332
+ reg_act("form.insert.char", f.call { |x, c| x.insert(c) }, "Form: insert <char>")
333
+ reg_act("form.insert.space", f.call { |x| x.insert(" ") }, "Form: insert a space")
334
+ reg_act("form.backspace", f.call { |x| x.backspace }, "Form: delete the char before the cursor")
335
+ reg_act("form.delete", proc {
336
+ h = FormInput.current&.key_handlers&.[](:delete)
337
+ h ? h.call : form_field&.delete
338
+ }, "Form: delete the char at the cursor (in a list: the item, if it can be)")
339
+ reg_act("form.up", proc { FormInput.current&.key_handlers&.[](:up)&.call }, "Form: previous item of the list")
340
+ reg_act("form.down", proc { FormInput.current&.key_handlers&.[](:down)&.call }, "Form: next item of the list")
341
+ reg_act("form.left", f.call { |x| x.move_to(x.pos - 1) }, "Form: cursor left")
342
+ reg_act("form.right", f.call { |x| x.move_to(x.pos + 1) }, "Form: cursor right")
343
+ reg_act("form.home", f.call { |x| x.move_to(0) }, "Form: cursor to the start of the field")
344
+ reg_act("form.end", f.call { |x| x.move_to(x.text.size) }, "Form: cursor to the end of the field")
345
+ reg_act("form.select_all", f.call { |x| x.select_all }, "Form: select the whole field")
346
+ reg_act("form.copy", f.call { |x| x.copy }, "Form: copy the selection")
347
+ reg_act("form.cut", f.call { |x| x.cut }, "Form: cut the selection")
348
+ reg_act("form.paste", f.call { |x| x.paste }, "Form: paste")
349
+ reg_act("form.next", proc { FormInput.current&.next_item }, "Form: next field or button")
350
+ reg_act("form.prev", proc { FormInput.current&.prev_item }, "Form: previous field or button")
351
+ reg_act("form.enter", proc { FormInput.current&.enter }, "Form: submit, or press the focused button")
352
+ reg_act("form.cancel", proc { FormInput.current&.cancel }, "Form: cancel")
353
+ bind_form_field_keys("F")
354
+ # The field shows its buffer after every action, also for keys that don't
355
+ # come from the form window (a demo, tests)
356
+ if !$form_input_watched
357
+ $form_input_watched = true
358
+ vma.kbd.on(:action_handled) { |*_| FormInput.current&.field&.sync }
359
+ end
360
+ add_keys "form cat:edit", {
361
+ "F tab" => "form.next",
362
+ "F shift-tab" => "form.prev",
363
+ "F enter" => "form.enter",
364
+ "F esc" => "form.cancel",
365
+ "F up" => "form.up",
366
+ "F down" => "form.down",
367
+ }
368
+ end
369
+
370
+ # The basic field editing keys, for mode (shared with the command line's
371
+ # mode later: doc/demo_recording_plan.md)
372
+ def bind_form_field_keys(mode)
373
+ add_keys "form cat:edit", {
374
+ "#{mode} <char>" => "form.insert.char",
375
+ "#{mode} space" => "form.insert.space",
376
+ "#{mode} backspace" => "form.backspace",
377
+ "#{mode} delete" => "form.delete",
378
+ "#{mode} left" => "form.left",
379
+ "#{mode} right" => "form.right",
380
+ "#{mode} home" => "form.home",
381
+ "#{mode} end" => "form.end",
382
+ "#{mode} ctrl-a" => "form.select_all",
383
+ "#{mode} ctrl-c" => "form.copy",
384
+ "#{mode} ctrl-x" => "form.cut",
385
+ "#{mode} ctrl-v" => "form.paste",
386
+ }
387
+ end
388
+ end # module Vimamsa
data/lib/vimamsa/gui.rb CHANGED
@@ -276,13 +276,43 @@ class VMAgui
276
276
  end
277
277
  end
278
278
 
279
- def overlay_draw_text(text, textpos)
279
+ # Clears the overlay after ms milliseconds (e.g. to leave the chosen easy
280
+ # jump label up for a moment). A new overlay drawn meanwhile is kept.
281
+ def clear_overlay_later(ms)
282
+ da, ov = @da, @active_window[:overlay]
283
+ return if da.nil?
284
+ @da = nil
285
+ GLib::Timeout.add(ms) { ov.remove_overlay(da) rescue nil; false }
286
+ end
287
+
288
+ # Removes one widget drawn with overlay_draw_text
289
+ def overlay_remove(widget)
290
+ @da&.remove(widget)
291
+ end
292
+
293
+ # A soft glow around overlay labels (easy jump), with cnf.easy_jump.glow.
294
+ # Off by default: without a GPU (GTK's software renderer) the shadows made
295
+ # easy jump about 60% slower (a full screen, 433 labels: 0.65 s vs 0.41 s).
296
+ OVERLAY_LABEL_CSS = <<~CSS
297
+ label.overlay-label {
298
+ text-shadow: 0 0 3px rgba(255, 40, 40, 0.9);
299
+ }
300
+ CSS
301
+
302
+ # Draws text (or Pango markup) at buffer position textpos; returns the label
303
+ def overlay_draw_text(text, textpos, markup: nil)
280
304
  # debug "overlay_draw_text #{[x,y]}"
281
305
  (x, y) = @view.pos_to_coord(textpos)
282
306
  # debug "overlay_draw_text #{[x,y]}"
283
- label = Gtk::Label.new("<span background='#000000ff' foreground='#ff0000' weight='ultrabold'>#{text}</span>")
307
+ label = Gtk::Label.new(markup || "<span background='#000000ff' foreground='#ff0000' weight='ultrabold'>#{text}</span>")
284
308
  label.use_markup = true
309
+ label.add_css_class("overlay-label")
310
+ if cnf.easy_jump.glow?
311
+ @overlay_label_css ||= Gtk::CssProvider.new.tap { |c| c.load(data: OVERLAY_LABEL_CSS) }
312
+ label.style_context.add_provider(@overlay_label_css)
313
+ end
285
314
  @da.put(label, x, y)
315
+ label
286
316
  end
287
317
 
288
318
  def end_overlay_draw()
@@ -514,7 +544,7 @@ class VMAgui
514
544
  # @view.check_controllers
515
545
  end
516
546
 
517
- ctrl_fn = File.expand_path(get_dot_path("ripl_ctrl"))
547
+ ctrl_fn = File.expand_path(get_data_path("ripl_ctrl"))
518
548
  # Allows to debug in case keyboard handling is lost
519
549
  if File.exist?(ctrl_fn)
520
550
  File.delete(ctrl_fn)
@@ -551,6 +581,11 @@ class VMAgui
551
581
  # @entry_has_focus is set explicitly via notify_entry_focus by those widgets.
552
582
  next false if @entry_has_focus
553
583
  next false if @kbd_passthrough
584
+ # A playing demo types its own keys (demo_player.rb)
585
+ if DemoPlayer.blocks_input?
586
+ DemoPlayer.input_blocked
587
+ next true
588
+ end
554
589
  name = Gdk::Keyval.to_name(keyval)
555
590
  uki = Gdk::Keyval.to_unicode(keyval)
556
591
  keystr = uki.chr("UTF-8")
@@ -563,13 +598,7 @@ class VMAgui
563
598
  # eventctr: Gtk::EventControllerKey
564
599
  # modtype: Gdk::ModifierType
565
600
  debug "modifier change"
566
- vma.kbd.modifiers[:ctrl] = modtype.control_mask?
567
- vma.kbd.modifiers[:alt] = modtype.alt_mask?
568
- vma.kbd.modifiers[:hyper] = modtype.hyper_mask?
569
- vma.kbd.modifiers[:lock] = modtype.lock_mask?
570
- vma.kbd.modifiers[:meta] = modtype.meta_mask?
571
- vma.kbd.modifiers[:shift] = modtype.shift_mask?
572
- vma.kbd.modifiers[:super] = modtype.super_mask?
601
+ gui_set_modifiers(modtype) # key_names.rb
573
602
 
574
603
  #TODO:?
575
604
  # button1_mask?
@@ -581,6 +610,7 @@ class VMAgui
581
610
  press.signal_connect "key-released" do |gesture, keyval, keycode, y|
582
611
  next false if @entry_has_focus
583
612
  next false if @kbd_passthrough
613
+ next true if DemoPlayer.blocks_input?
584
614
  name = Gdk::Keyval.to_name(keyval)
585
615
  uki = Gdk::Keyval.to_unicode(keyval)
586
616
  keystr = uki.chr("UTF-8")
@@ -766,6 +796,11 @@ class VMAgui
766
796
  MODE_BADGE_CSS = { "C" => "mode-command", "I" => "mode-insert", "V" => "mode-visual",
767
797
  "B" => "mode-browse", "X" => "mode-replace" }.freeze
768
798
 
799
+ # The mode badge's text (e.g. "COMMAND") and CSS class (MODE_BADGE_CSS)
800
+ def mode_badge_info
801
+ [@last_badge_text, @badge_css_class]
802
+ end
803
+
769
804
  # Render the mode badge and pending key chord in the status area.
770
805
  # Subscribed to KeyBindingTree's :state_trail_changed event.
771
806
  def update_mode_badge(badge, badge_key, trail)
@@ -837,6 +872,12 @@ class VMAgui
837
872
  end
838
873
 
839
874
  def monitor
875
+ # kill / ctrl-c (the trap in exe/vimamsa)
876
+ if $vma_quit_requested
877
+ $vma_quit_requested = false
878
+ vma.shutdown
879
+ return false
880
+ end
840
881
  return true if @windows[1].nil?
841
882
  swa = @windows[1][:sw]
842
883
  @sw_width ||= swa.width
@@ -894,8 +935,11 @@ class VMAgui
894
935
  n_sw = Gtk::ScrolledWindow.new
895
936
  n_sw.set_policy(:automatic, :automatic)
896
937
  n_sw.add_css_class("editor-frame")
938
+ # The scrolled window is the overlay's main child, which GTK always draws
939
+ # below the overlay children (key hint, easy jump labels): a buffer switch
940
+ # replaces it there and doesn't cover them (set_current_buffer)
897
941
  n_overlay = Gtk::Overlay.new
898
- n_overlay.add_overlay(n_sw)
942
+ n_overlay.set_child(n_sw)
899
943
  # @pane = Gtk::Paned.new(:horizontal)
900
944
 
901
945
  win = { :sw => n_sw, :overlay => n_overlay, :id => win_id }
@@ -1061,13 +1105,14 @@ class VMAgui
1061
1105
  #TODO: improve
1062
1106
  swa = @active_window[:sw]
1063
1107
  ol = @active_window[:overlay]
1064
- ol.remove_overlay(swa)
1065
1108
  swa.set_child(nil)
1066
1109
  # Creating a new ScrolledWindow every time to avoid a layout bug
1067
1110
  # https://gitlab.gnome.org/GNOME/gtk/-/issues/6189
1068
1111
  swb = new_scrolled_window
1069
1112
  swb.set_child(view2)
1070
- ol.add_overlay(swb)
1113
+ # The overlay's main child: the overlay children (key hint, easy jump
1114
+ # labels) stay above it
1115
+ ol.set_child(swb)
1071
1116
  @active_window[:view] = view
1072
1117
  @active_window[:sw] = swb
1073
1118
  end
@@ -1504,10 +1549,41 @@ class VMAgui
1504
1549
  l[:maximized] ? @window.maximize : @window.set_default_size(l[:width], l[:height])
1505
1550
  apply_view_layout(l) if @view_layout_restored
1506
1551
  end
1552
+ undo_auto_maximize
1507
1553
  false
1508
1554
  }
1509
1555
  end
1510
1556
 
1557
+ # GNOME (mutter, org.gnome.mutter auto-maximize) maximizes a new window that
1558
+ # covers most of the screen, so a saved window only a little smaller than
1559
+ # the screen would come back maximized, and be saved so at quit. For a
1560
+ # while after the first map: if the layout says not maximized but the
1561
+ # window is, unmaximize it to the saved size.
1562
+ def undo_auto_maximize
1563
+ l = @startup_layout
1564
+ return if l.nil? || l[:maximized]
1565
+ tries = 0
1566
+ GLib::Timeout.add(100) {
1567
+ if @window.maximized?
1568
+ @window.unmaximize
1569
+ # Unmaximizing is asynchronous: set the size once it's done, or the
1570
+ # window manager's own unmaximized size wins
1571
+ waits = 0
1572
+ GLib::Timeout.add(50) {
1573
+ if !@window.maximized?
1574
+ @window.set_default_size(l[:width], l[:height])
1575
+ false
1576
+ else
1577
+ (waits += 1) < 60 # 3 s
1578
+ end
1579
+ }
1580
+ false
1581
+ else
1582
+ (tries += 1) < 20 # 2 s
1583
+ end
1584
+ }
1585
+ end
1586
+
1511
1587
  # Called at startup once the first buffer exists: columns and panels.
1512
1588
  def restore_view_layout
1513
1589
  return if !layout_enabled? || @startup_layout.nil?
@@ -14,10 +14,14 @@ module Vimamsa
14
14
  # :42 jump to line 42
15
15
  # :e PATH open file
16
16
  # :w :q :wq save / quit / save-and-quit
17
+ # :reg show the registers (also :registers, :di, :display)
18
+ #
19
+ # Actions run with a.<id>!, e.g. :a.buf.save! — tab completes the id after
20
+ # "a." one level at a time (namespaces, then the segments below them).
17
21
  class CommandLine
18
22
  attr_reader :history, :entry
19
23
 
20
- HISTORY_FILE = "~/.vimamsa/cmd_history.txt"
24
+ HISTORY_FILE = "cmd_history.txt" # in the data dir
21
25
  HISTORY_MAX = 100
22
26
 
23
27
  def initialize(css_provider)
@@ -57,6 +61,9 @@ class CommandLine
57
61
  when "Down"
58
62
  history_move(-1)
59
63
  true
64
+ when "Tab", "ISO_Left_Tab"
65
+ complete_action_id
66
+ true # keep focus in the entry
60
67
  else
61
68
  false
62
69
  end
@@ -108,10 +115,14 @@ class CommandLine
108
115
  when "w"
109
116
  buf.save
110
117
  when "q"
111
- exec_action(:quit)
118
+ exec_action("app.quit")
112
119
  when "wq"
113
120
  buf.save
114
- exec_action(:quit)
121
+ exec_action("app.quit")
122
+ when "reg", "registers", "di", "display"
123
+ exec_action("edit.register.list")
124
+ when "intro"
125
+ exec_action("help.intro")
115
126
  when /\Ae\s+(\S.*)\z/
116
127
  open_new_file(File.expand_path(Regexp.last_match(1).strip))
117
128
  else
@@ -119,6 +130,34 @@ class CommandLine
119
130
  end
120
131
  end
121
132
 
133
+ # Complete the action id after "a." before the cursor: the only candidate,
134
+ # or the candidates' common prefix, with the candidates shown as a message.
135
+ # Returns the candidates.
136
+ def complete_action_id
137
+ pos = @entry.position
138
+ text = @entry.text
139
+ before = text[0, pos]
140
+ m = before.match(/(?<![\w.])a\.([a-z0-9_.]*)\z/)
141
+ return [] if m.nil?
142
+ prefix = m[1]
143
+ cands = vma.actions.complete(prefix[0, (prefix.rindex(".") || -1) + 1])
144
+ cands = cands.select { |c| c.start_with?(prefix) }
145
+ return cands if cands.empty?
146
+ common = cands.reduce { |x, y|
147
+ i = 0
148
+ i += 1 while i < x.size && i < y.size && x[i] == y[i]
149
+ x[0, i]
150
+ }
151
+ # one action that is also a parent ("buf.save", "buf.save."): stop at it
152
+ common = cands[0] if cands.size == 2 && cands[1] == cands[0] + "."
153
+ if common.size > prefix.size
154
+ @entry.text = before[0, before.size - prefix.size] + common + text[pos..]
155
+ @entry.set_position(pos + common.size - prefix.size)
156
+ end
157
+ message(cands.join(" ")) if cands.size > 1
158
+ cands
159
+ end
160
+
122
161
  private
123
162
 
124
163
  # Run Ruby at top level; locals persist across invocations because
@@ -190,7 +229,7 @@ class CommandLine
190
229
  end
191
230
 
192
231
  def load_history
193
- f = File.expand_path(HISTORY_FILE)
232
+ f = get_data_path(HISTORY_FILE)
194
233
  return [] if !File.exist?(f)
195
234
  File.readlines(f, chomp: true).reject(&:empty?).last(HISTORY_MAX)
196
235
  rescue StandardError
@@ -199,7 +238,7 @@ class CommandLine
199
238
 
200
239
  def save_history
201
240
  return if ARGV.include?("--test") # don't pollute history from test runs
202
- f = File.expand_path(HISTORY_FILE)
241
+ f = get_data_path(HISTORY_FILE)
203
242
  return if !Dir.exist?(File.dirname(f))
204
243
  File.write(f, @history.join("\n") + "\n")
205
244
  rescue StandardError