vimamsa 0.1.27 → 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.
- checksums.yaml +4 -4
- data/README.md +139 -89
- data/custom_example.rb +18 -6
- data/doc/TODO.md +327 -110
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +2 -1
- data/doc/delta_syntax_plan.md +293 -0
- data/doc/demo_recording_plan.md +288 -0
- data/doc/design_goals.md +27 -0
- data/doc/intro_page_plan.md +266 -0
- data/doc/key_bindings_report_plan.md +45 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +34 -44
- data/doc/modules_settings_plan.md +1 -1
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/vim_compatibility_plan.md +186 -31
- data/doc/vimlike_vim_conflicts.md +236 -228
- data/doc/vm_snapshots_plan.md +4 -4
- data/doc/wysiwyg_plan.md +231 -0
- data/exe/run_tests.rb +8 -1
- data/exe/vimamsa +49 -6
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +1 -1
- data/lib/vimamsa/ack.rb +2 -0
- data/lib/vimamsa/actions.rb +381 -36
- data/lib/vimamsa/bookmarks.rb +8 -8
- data/lib/vimamsa/buffer.rb +83 -37
- data/lib/vimamsa/buffer_changetext.rb +58 -36
- data/lib/vimamsa/buffer_list.rb +2 -2
- data/lib/vimamsa/buffer_manager.rb +6 -6
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +6 -3
- data/lib/vimamsa/conf.rb +9 -0
- data/lib/vimamsa/crash_handler.rb +2 -2
- data/lib/vimamsa/debug.rb +2 -2
- data/lib/vimamsa/demo_player.rb +458 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/diff_buffer.rb +1 -1
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +54 -3
- data/lib/vimamsa/editor.rb +89 -46
- data/lib/vimamsa/file_history.rb +1 -1
- data/lib/vimamsa/file_manager.rb +23 -23
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +83 -13
- data/lib/vimamsa/gui_command_line.rb +44 -5
- data/lib/vimamsa/gui_form_generator.rb +17 -6
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +164 -2
- data/lib/vimamsa/gui_menu.rb +69 -50
- data/lib/vimamsa/gui_select_window.rb +77 -43
- data/lib/vimamsa/gui_settings.rb +9 -5
- data/lib/vimamsa/gui_sourceview.rb +15 -81
- data/lib/vimamsa/gui_theme.rb +11 -2
- data/lib/vimamsa/hook.rb +2 -0
- data/lib/vimamsa/intro_page.rb +368 -0
- data/lib/vimamsa/key_actions.rb +315 -225
- data/lib/vimamsa/key_binding_tree.rb +228 -61
- data/lib/vimamsa/key_bindings_notepad.rb +18 -16
- data/lib/vimamsa/key_bindings_report.rb +290 -67
- data/lib/vimamsa/key_bindings_vim.rb +47 -297
- data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +20 -3
- data/lib/vimamsa/rbvma.rb +15 -0
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search_replace.rb +4 -4
- data/lib/vimamsa/string_util.rb +17 -3
- data/lib/vimamsa/tests.rb +8 -8
- data/lib/vimamsa/text_objects.rb +11 -54
- data/lib/vimamsa/text_transforms.rb +4 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_core.rb +355 -0
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +3 -3
- data/modules/dictation/dictation.rb +32 -32
- data/modules/ollama/ollama.rb +5 -5
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +10 -10
- data/run_e2e_vm.sh +3 -3
- data/run_tests_vm.rb +138 -0
- data/scripts/demo/demo_easyjump_steps.txt +60 -0
- data/scripts/demo/demo_files_steps.txt +52 -0
- data/scripts/demo/demo_steps.txt +9 -1
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +60 -81
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +1 -0
- data/scripts/demo/square/shapes.rb +29 -0
- data/scripts/demo/square/steps.txt +185 -0
- data/scripts/lib/perf_startup.rb +138 -0
- data/scripts/lib/script_helpers.rb +53 -0
- data/scripts/perf_compare.rb +34 -0
- data/scripts/profile_startup.rb +72 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +2 -2
- data/tests/test_autocomplete.rb +1 -1
- data/tests/test_basic_editing.rb +18 -18
- data/tests/test_bookmarks.rb +6 -6
- data/tests/test_bracket_match.rb +3 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +2 -2
- data/tests/test_command_line.rb +1 -1
- data/tests/test_context_menu_file.rb +18 -0
- data/tests/test_copy_paste.rb +33 -33
- data/tests/test_custom_two_phase.rb +1 -1
- data/tests/test_demo_player.rb +301 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dictation.rb +16 -16
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +3 -3
- data/tests/test_file_panel.rb +2 -2
- data/tests/test_flash.rb +1 -1
- data/tests/test_fold.rb +1 -1
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +2 -2
- data/tests/test_gtk_sync.rb +7 -7
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +163 -3
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +2 -2
- data/tests/test_macro.rb +2 -2
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +5 -5
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_random_edit.rb +27 -27
- data/tests/test_registers.rb +122 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +1 -1
- data/tests/test_text_objects.rb +1 -1
- data/tests/test_text_transforms.rb +12 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +10 -10
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +107 -6
- data/tests/test_vim_conflicts.rb +41 -4
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +83 -0
- data/vimamsa.gemspec +1 -1
- data/vm_guest_run.sh +22 -2
- metadata +58 -3
- 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
|
-
|
|
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(
|
|
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)
|
|
@@ -563,13 +593,7 @@ class VMAgui
|
|
|
563
593
|
# eventctr: Gtk::EventControllerKey
|
|
564
594
|
# modtype: Gdk::ModifierType
|
|
565
595
|
debug "modifier change"
|
|
566
|
-
|
|
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?
|
|
596
|
+
gui_set_modifiers(modtype) # key_names.rb
|
|
573
597
|
|
|
574
598
|
#TODO:?
|
|
575
599
|
# button1_mask?
|
|
@@ -766,6 +790,11 @@ class VMAgui
|
|
|
766
790
|
MODE_BADGE_CSS = { "C" => "mode-command", "I" => "mode-insert", "V" => "mode-visual",
|
|
767
791
|
"B" => "mode-browse", "X" => "mode-replace" }.freeze
|
|
768
792
|
|
|
793
|
+
# The mode badge's text (e.g. "COMMAND") and CSS class (MODE_BADGE_CSS)
|
|
794
|
+
def mode_badge_info
|
|
795
|
+
[@last_badge_text, @badge_css_class]
|
|
796
|
+
end
|
|
797
|
+
|
|
769
798
|
# Render the mode badge and pending key chord in the status area.
|
|
770
799
|
# Subscribed to KeyBindingTree's :state_trail_changed event.
|
|
771
800
|
def update_mode_badge(badge, badge_key, trail)
|
|
@@ -837,6 +866,12 @@ class VMAgui
|
|
|
837
866
|
end
|
|
838
867
|
|
|
839
868
|
def monitor
|
|
869
|
+
# kill / ctrl-c (the trap in exe/vimamsa)
|
|
870
|
+
if $vma_quit_requested
|
|
871
|
+
$vma_quit_requested = false
|
|
872
|
+
vma.shutdown
|
|
873
|
+
return false
|
|
874
|
+
end
|
|
840
875
|
return true if @windows[1].nil?
|
|
841
876
|
swa = @windows[1][:sw]
|
|
842
877
|
@sw_width ||= swa.width
|
|
@@ -894,8 +929,11 @@ class VMAgui
|
|
|
894
929
|
n_sw = Gtk::ScrolledWindow.new
|
|
895
930
|
n_sw.set_policy(:automatic, :automatic)
|
|
896
931
|
n_sw.add_css_class("editor-frame")
|
|
932
|
+
# The scrolled window is the overlay's main child, which GTK always draws
|
|
933
|
+
# below the overlay children (key hint, easy jump labels): a buffer switch
|
|
934
|
+
# replaces it there and doesn't cover them (set_current_buffer)
|
|
897
935
|
n_overlay = Gtk::Overlay.new
|
|
898
|
-
n_overlay.
|
|
936
|
+
n_overlay.set_child(n_sw)
|
|
899
937
|
# @pane = Gtk::Paned.new(:horizontal)
|
|
900
938
|
|
|
901
939
|
win = { :sw => n_sw, :overlay => n_overlay, :id => win_id }
|
|
@@ -1061,13 +1099,14 @@ class VMAgui
|
|
|
1061
1099
|
#TODO: improve
|
|
1062
1100
|
swa = @active_window[:sw]
|
|
1063
1101
|
ol = @active_window[:overlay]
|
|
1064
|
-
ol.remove_overlay(swa)
|
|
1065
1102
|
swa.set_child(nil)
|
|
1066
1103
|
# Creating a new ScrolledWindow every time to avoid a layout bug
|
|
1067
1104
|
# https://gitlab.gnome.org/GNOME/gtk/-/issues/6189
|
|
1068
1105
|
swb = new_scrolled_window
|
|
1069
1106
|
swb.set_child(view2)
|
|
1070
|
-
|
|
1107
|
+
# The overlay's main child: the overlay children (key hint, easy jump
|
|
1108
|
+
# labels) stay above it
|
|
1109
|
+
ol.set_child(swb)
|
|
1071
1110
|
@active_window[:view] = view
|
|
1072
1111
|
@active_window[:sw] = swb
|
|
1073
1112
|
end
|
|
@@ -1504,10 +1543,41 @@ class VMAgui
|
|
|
1504
1543
|
l[:maximized] ? @window.maximize : @window.set_default_size(l[:width], l[:height])
|
|
1505
1544
|
apply_view_layout(l) if @view_layout_restored
|
|
1506
1545
|
end
|
|
1546
|
+
undo_auto_maximize
|
|
1507
1547
|
false
|
|
1508
1548
|
}
|
|
1509
1549
|
end
|
|
1510
1550
|
|
|
1551
|
+
# GNOME (mutter, org.gnome.mutter auto-maximize) maximizes a new window that
|
|
1552
|
+
# covers most of the screen, so a saved window only a little smaller than
|
|
1553
|
+
# the screen would come back maximized, and be saved so at quit. For a
|
|
1554
|
+
# while after the first map: if the layout says not maximized but the
|
|
1555
|
+
# window is, unmaximize it to the saved size.
|
|
1556
|
+
def undo_auto_maximize
|
|
1557
|
+
l = @startup_layout
|
|
1558
|
+
return if l.nil? || l[:maximized]
|
|
1559
|
+
tries = 0
|
|
1560
|
+
GLib::Timeout.add(100) {
|
|
1561
|
+
if @window.maximized?
|
|
1562
|
+
@window.unmaximize
|
|
1563
|
+
# Unmaximizing is asynchronous: set the size once it's done, or the
|
|
1564
|
+
# window manager's own unmaximized size wins
|
|
1565
|
+
waits = 0
|
|
1566
|
+
GLib::Timeout.add(50) {
|
|
1567
|
+
if !@window.maximized?
|
|
1568
|
+
@window.set_default_size(l[:width], l[:height])
|
|
1569
|
+
false
|
|
1570
|
+
else
|
|
1571
|
+
(waits += 1) < 60 # 3 s
|
|
1572
|
+
end
|
|
1573
|
+
}
|
|
1574
|
+
false
|
|
1575
|
+
else
|
|
1576
|
+
(tries += 1) < 20 # 2 s
|
|
1577
|
+
end
|
|
1578
|
+
}
|
|
1579
|
+
end
|
|
1580
|
+
|
|
1511
1581
|
# Called at startup once the first buffer exists: columns and panels.
|
|
1512
1582
|
def restore_view_layout
|
|
1513
1583
|
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 = "
|
|
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(
|
|
118
|
+
exec_action("app.quit")
|
|
112
119
|
when "wq"
|
|
113
120
|
buf.save
|
|
114
|
-
exec_action(
|
|
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 =
|
|
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 =
|
|
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
|