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.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +17 -10
- data/Dockerfile +2 -2
- data/README.md +162 -90
- data/custom_example.rb +33 -15
- data/doc/TODO.md +334 -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/test_commands.md +232 -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/docker_cmd.sh +1 -1
- data/exe/run_tests.rb +85 -3
- 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 +84 -38
- 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 +494 -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 +136 -65
- 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 +89 -13
- data/lib/vimamsa/gui_command_line.rb +44 -5
- data/lib/vimamsa/gui_form_generator.rb +17 -6
- data/lib/vimamsa/gui_func_panel.rb +1 -1
- 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 +28 -81
- data/lib/vimamsa/gui_theme.rb +11 -2
- data/lib/vimamsa/hook.rb +2 -0
- data/lib/vimamsa/intro_page.rb +367 -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 +43 -297
- data/lib/vimamsa/key_bindings_vim_core.rb +356 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +62 -7
- 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_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 +163 -0
- data/scripts/appimage/AppRun +7 -0
- data/scripts/appimage/build_in_container.sh +11 -1
- data/scripts/appimage/smoke_test.sh +1 -1
- 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 +355 -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_lsp_root.rb +43 -0
- 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 +131 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +45 -4
- 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 +75 -28
- metadata +60 -4
- data/run_tests.rb +0 -89
- data/run_tests_vm.sh +0 -130
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
module Vimamsa
|
|
2
|
+
# Records a demo like a macro (Help ▸ Demos ▸ Record demo, help.demo.record),
|
|
3
|
+
# into the demo step format that DemoPlayer plays (doc/demo_recording_plan.md,
|
|
4
|
+
# part 2). The keys are taken where every key comes in (the :key_input event
|
|
5
|
+
# of KeyBindingTree#match_key_conf, where DemoPlayer also feeds them), so
|
|
6
|
+
# whatever goes through the key bindings is recorded, typing in forms too.
|
|
7
|
+
#
|
|
8
|
+
# Recorded per key: the time, the key name, the mode before it, the action
|
|
9
|
+
# it ran (if any) and the cursor's line before it. At the end the keys become
|
|
10
|
+
# steps (DemoRecorder.steps): delay, wait, keys, type, and target +
|
|
11
|
+
# @JUMP_LABEL@ for easy jump labels (they depend on the window size). The
|
|
12
|
+
# demo is saved in <user dir>/demos/<name>/ with a copy of the file as it was
|
|
13
|
+
# at the start, and played from Help ▸ Demos (DemoPlayer.demos).
|
|
14
|
+
class DemoRecorder
|
|
15
|
+
# One recorded key
|
|
16
|
+
# read: read by something else than the key bindings (easy jump's label
|
|
17
|
+
# keys, while its key override is on)
|
|
18
|
+
Key = Struct.new(:t, :key, :mode, :action, :line, :col, :read, keyword_init: true)
|
|
19
|
+
|
|
20
|
+
MODIFIERS = %w[ctrl alt shift]
|
|
21
|
+
MAX_WAIT = 3.0 # a longer pause is cut to this
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
# The recorder recording now, or nil
|
|
25
|
+
attr_accessor :current
|
|
26
|
+
# The demo saved last (a DemoPlayer.demos key)
|
|
27
|
+
attr_accessor :last_saved
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.toggle
|
|
31
|
+
if @current
|
|
32
|
+
@current.stop
|
|
33
|
+
else
|
|
34
|
+
@current = new
|
|
35
|
+
@current.start
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.recording? = !@current.nil?
|
|
40
|
+
|
|
41
|
+
attr_reader :keys, :buf, :start_text
|
|
42
|
+
|
|
43
|
+
def initialize
|
|
44
|
+
@keys = []
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def start
|
|
48
|
+
@buf = vma.buf
|
|
49
|
+
# Where a demo starts playing: Command mode, the cursor at the top
|
|
50
|
+
vma.kbd.set_mode(:command)
|
|
51
|
+
@buf.set_pos(0)
|
|
52
|
+
@start_text = @buf.to_s.dup
|
|
53
|
+
@start_fname = @buf.fname
|
|
54
|
+
@t0 = now
|
|
55
|
+
@recording = true
|
|
56
|
+
DemoRecorder.watch
|
|
57
|
+
vma.gui.set_status_indicator(:demo_record, "● REC demo", css_class: "status-recording") rescue nil
|
|
58
|
+
message("Recording a demo from the top of the file. Help ▸ Demos ▸ Record demo again stops it.")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Stops; asks for a name and saves (save: false only stops, for tests)
|
|
62
|
+
def stop(save: true)
|
|
63
|
+
@recording = false
|
|
64
|
+
DemoRecorder.current = nil
|
|
65
|
+
vma.gui.set_status_indicator(:demo_record, nil) rescue nil
|
|
66
|
+
drop_stop_keys
|
|
67
|
+
@end_line = @buf.lpos
|
|
68
|
+
@end_col = @buf.cpos
|
|
69
|
+
if @keys.empty?
|
|
70
|
+
message("Demo recording stopped: no keys recorded")
|
|
71
|
+
return
|
|
72
|
+
end
|
|
73
|
+
ask_name_and_save if save
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def recording? = @recording
|
|
77
|
+
|
|
78
|
+
# A key from :key_input
|
|
79
|
+
def key_input(c, event_type)
|
|
80
|
+
return if !@recording
|
|
81
|
+
if event_type == :key_release
|
|
82
|
+
# ctrl (alt, shift) alone: pressed and released with nothing between,
|
|
83
|
+
# which is what "ctrl!" means and what DemoPlayer#press("ctrl") plays
|
|
84
|
+
if @pending_mod && c == "#{@pending_mod.key}!"
|
|
85
|
+
@keys << @pending_mod
|
|
86
|
+
end
|
|
87
|
+
@pending_mod = nil
|
|
88
|
+
return
|
|
89
|
+
end
|
|
90
|
+
k = Key.new(t: now - @t0, key: c, mode: vma.kbd.get_mode, line: vma.buf.lpos, col: vma.buf.cpos,
|
|
91
|
+
read: vma.kbd.keyhandling_override?)
|
|
92
|
+
if MODIFIERS.include?(c)
|
|
93
|
+
@pending_mod = k
|
|
94
|
+
else
|
|
95
|
+
@pending_mod = nil
|
|
96
|
+
@keys << k
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# The action the last key ran (:key_action)
|
|
101
|
+
def key_action(action)
|
|
102
|
+
return if !@recording || @keys.empty?
|
|
103
|
+
@keys.last.action = action.to_s
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# The steps file text (see DemoRecorder.steps)
|
|
107
|
+
def steps_text(title: nil, file: nil)
|
|
108
|
+
DemoRecorder.steps(@keys, end_line: @end_line || @buf.lpos, end_col: @end_col || @buf.cpos, title: title, file: file)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Saves into <user dir>/demos/<slug>/: steps.txt and the start file
|
|
112
|
+
def save(name)
|
|
113
|
+
slug = DemoRecorder.slug(name)
|
|
114
|
+
dir = File.join(DemoPlayer.user_demos_dir, slug)
|
|
115
|
+
FileUtils.mkdir_p(dir)
|
|
116
|
+
file = @start_fname ? File.basename(@start_fname) : "demo.txt"
|
|
117
|
+
File.write(File.join(dir, file), @start_text)
|
|
118
|
+
File.write(File.join(dir, "steps.txt"), steps_text(title: name, file: file))
|
|
119
|
+
DemoRecorder.last_saved = DemoPlayer.user_demo_key(slug)
|
|
120
|
+
message("Demo saved: #{dir} (Help ▸ Demos ▸ Play the last recorded demo)")
|
|
121
|
+
dir
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# "My demo!" -> "my_demo"
|
|
125
|
+
def self.slug(name)
|
|
126
|
+
s = name.to_s.downcase.gsub(/[^a-z0-9]+/, "_").gsub(/\A_+|_+\z/, "")
|
|
127
|
+
s.empty? ? "demo" : s
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Subscribes once to the key events
|
|
131
|
+
def self.watch
|
|
132
|
+
return if @watched
|
|
133
|
+
@watched = true
|
|
134
|
+
vma.kbd.on(:key_input) { |c, ev| @current&.key_input(c, ev) }
|
|
135
|
+
vma.kbd.on(:key_action) { |_trail, action| @current&.key_action(action) }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Steps from recorded keys (Key list, times in seconds from the start).
|
|
139
|
+
# end_line, end_col: the cursor's place when recording stopped (for an
|
|
140
|
+
# easy jump at the end).
|
|
141
|
+
def self.steps(keys, end_line: 0, end_col: 0, title: nil, file: nil)
|
|
142
|
+
out = []
|
|
143
|
+
out << "# Recorded with Help ▸ Demos ▸ Record demo (#{Time.now.strftime("%Y-%m-%d")})."
|
|
144
|
+
out << "# Edit freely; the format is in scripts/demo/demo_steps.txt."
|
|
145
|
+
out << "title #{title}" if title
|
|
146
|
+
out << "file #{file}" if file
|
|
147
|
+
gaps = keys.each_cons(2).map { |a, b| b.t - a.t }.select { |g| g > 0 && g < 2.0 }
|
|
148
|
+
delay = gaps.empty? ? 0.4 : (median(gaps) * 20).round / 20.0
|
|
149
|
+
delay = delay.clamp(0.2, 0.8)
|
|
150
|
+
out << "delay #{fmt(delay)}"
|
|
151
|
+
out << "wait 1"
|
|
152
|
+
|
|
153
|
+
groups = group(keys, end_line, end_col)
|
|
154
|
+
prev_t = nil
|
|
155
|
+
groups.each { |g|
|
|
156
|
+
if prev_t
|
|
157
|
+
gap = g[:t] - prev_t
|
|
158
|
+
w = [gap - delay, MAX_WAIT].min
|
|
159
|
+
out << "wait #{fmt((w * 10).round / 10.0)}" if gap > 2 * delay && w >= 0.1
|
|
160
|
+
end
|
|
161
|
+
out.concat(g[:lines])
|
|
162
|
+
prev_t = g[:t_end]
|
|
163
|
+
}
|
|
164
|
+
out.join("\n") + "\n"
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Keys in groups that become step lines: a run typed in Insert (or form)
|
|
168
|
+
# mode is a type line; an easy jump label is target + @JUMP_LABEL@; other
|
|
169
|
+
# keys go in keys lines, a new one after a pause
|
|
170
|
+
def self.group(keys, end_line, end_col = 0)
|
|
171
|
+
groups = []
|
|
172
|
+
i = 0
|
|
173
|
+
while i < keys.size
|
|
174
|
+
k = keys[i]
|
|
175
|
+
if typed_char(k)
|
|
176
|
+
j = i
|
|
177
|
+
text = +""
|
|
178
|
+
while j < keys.size && typed_char(keys[j]) && (j == i || keys[j].t - keys[j - 1].t < 2.0)
|
|
179
|
+
text << typed_char(keys[j])
|
|
180
|
+
j += 1
|
|
181
|
+
end
|
|
182
|
+
lines = []
|
|
183
|
+
# leading spaces would be lost after "type "
|
|
184
|
+
lead = text[/\A */].size
|
|
185
|
+
lines << "keys #{(["space"] * lead).join(" ")}" if lead > 0
|
|
186
|
+
lines << "type #{text[lead..]}" if text.size > lead
|
|
187
|
+
groups << { t: k.t, t_end: keys[j - 1].t, lines: lines }
|
|
188
|
+
i = j
|
|
189
|
+
elsif k.action.to_s.match?(/jump\.easy/)
|
|
190
|
+
# The label keys after it: read by easy jump itself (not just any
|
|
191
|
+
# key without an action: the d of d d has none either)
|
|
192
|
+
j = i + 1
|
|
193
|
+
j += 1 while j < keys.size && keys[j].read
|
|
194
|
+
# Where the cursor landed: the place before the next key
|
|
195
|
+
line, col = j < keys.size ? [keys[j].line, keys[j].col] : [end_line, end_col]
|
|
196
|
+
groups << { t: k.t, t_end: k.t, lines: ["# #{desc(k)}", "keys #{k.key}"] } # s
|
|
197
|
+
groups << { t: keys[i + 1]&.t || k.t, t_end: keys[j - 1].t,
|
|
198
|
+
lines: ["target line #{line + 1} col #{col.to_i + 1}", "keys @JUMP_LABEL@"] } if j > i + 1
|
|
199
|
+
i = j
|
|
200
|
+
else
|
|
201
|
+
j = i
|
|
202
|
+
run = []
|
|
203
|
+
while j < keys.size && !typed_char(keys[j]) && !keys[j].action.to_s.match?(/jump\.easy/) &&
|
|
204
|
+
(j == i || keys[j].t - keys[j - 1].t < 1.0)
|
|
205
|
+
run << keys[j]
|
|
206
|
+
j += 1
|
|
207
|
+
end
|
|
208
|
+
lines = []
|
|
209
|
+
d = run.map { |x| desc(x) }.compact.uniq
|
|
210
|
+
lines << "# #{d.join(", ")}" if d.any?
|
|
211
|
+
# "#" can only be last on a line (" # " starts a comment)
|
|
212
|
+
line = []
|
|
213
|
+
run.each { |x|
|
|
214
|
+
line << x.key
|
|
215
|
+
if x.key == "#"
|
|
216
|
+
lines << "keys #{line.join(" ")}"
|
|
217
|
+
line = []
|
|
218
|
+
end
|
|
219
|
+
}
|
|
220
|
+
lines << "keys #{line.join(" ")}" if line.any?
|
|
221
|
+
groups << { t: k.t, t_end: run.last.t, lines: lines }
|
|
222
|
+
i = j
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
groups
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# The character a key typed in Insert or form mode, or nil
|
|
229
|
+
def self.typed_char(k)
|
|
230
|
+
return nil if ![:insert, :form].include?(k.mode)
|
|
231
|
+
return nil if !k.action.to_s.match?(/insert\.(char|space)|insert_txt/)
|
|
232
|
+
return " " if k.key == "space"
|
|
233
|
+
k.key.size == 1 ? k.key : nil
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# The description of the action a key ran
|
|
237
|
+
def self.desc(k)
|
|
238
|
+
return nil if k.action.nil?
|
|
239
|
+
id = k.action[/\Aa\.([a-z][a-z0-9_.]*)!/, 1] || k.action
|
|
240
|
+
d = vma.actions[id]&.method_name.to_s
|
|
241
|
+
d.empty? || d == id ? id : d.sub("<char>", k.key)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def self.median(a)
|
|
245
|
+
s = a.sort
|
|
246
|
+
s.size.odd? ? s[s.size / 2] : (s[s.size / 2 - 1] + s[s.size / 2]) / 2.0
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def self.fmt(x)
|
|
250
|
+
x.to_s.sub(/\.0\z/, "")
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
private
|
|
254
|
+
|
|
255
|
+
def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
256
|
+
|
|
257
|
+
# The keys of the stop command itself (when it has a key binding): from the
|
|
258
|
+
# last key that ran another action
|
|
259
|
+
def drop_stop_keys
|
|
260
|
+
i = @keys.rindex { |k| k.action.to_s.include?("help.demo.record") }
|
|
261
|
+
return if i.nil?
|
|
262
|
+
j = i
|
|
263
|
+
j -= 1 while j > 0 && @keys[j - 1].action.nil?
|
|
264
|
+
@keys.slice!(j..)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# A form for the demo's name (typed in form mode, so this works with keys)
|
|
268
|
+
def ask_name_and_save
|
|
269
|
+
params = { "title" => "Save the recorded demo", "inputs" => {} }
|
|
270
|
+
base = @start_fname ? File.basename(@start_fname, ".*") : "demo"
|
|
271
|
+
params["inputs"]["name"] = { label: "Name", type: :entry, initial_text: "#{base} demo" }
|
|
272
|
+
params["inputs"]["save_btn"] = { label: "Save", type: :button }
|
|
273
|
+
params[:callback] = proc { |x| save(x["name"]) if !x["name"].to_s.strip.empty? }
|
|
274
|
+
PopupFormGenerator.new(params).run
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
end # module Vimamsa
|
data/lib/vimamsa/diff_buffer.rb
CHANGED
|
@@ -85,7 +85,7 @@ def diff_buffer_init()
|
|
|
85
85
|
return if @diff_buffer_init_done
|
|
86
86
|
@diff_buffer_init_done = true
|
|
87
87
|
vma.kbd.add_minor_mode("diffview", :diffview, :command)
|
|
88
|
-
bindkey "diffview enter",
|
|
88
|
+
bindkey "diffview enter", "diffview.source"
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
def diff_buffer()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
module Vimamsa
|
|
2
|
+
# Vim "." (doc/vim_compatibility_plan.md, step 4): repeat the last change.
|
|
3
|
+
#
|
|
4
|
+
# A change is a command run from Command mode that modified the buffer (d w,
|
|
5
|
+
# x, p, > >, g U U, ...) or that started Insert or Replace mode (i, a, o, c w,
|
|
6
|
+
# R, ...). For the latter, everything done until Insert mode was left belongs
|
|
7
|
+
# to the change too: the typed text, backspaces, the key that left. The
|
|
8
|
+
# command is kept as the key tree ran it (a string such as
|
|
9
|
+
# a.op.motion!({op: :change, motion: :word_next}), or an action id), with its
|
|
10
|
+
# count and register, so "." runs exactly the same thing again:
|
|
11
|
+
# c w foo esc then . changes the next word to foo
|
|
12
|
+
# 3 . repeats with count 3 instead (for an operator: d w, 3 .
|
|
13
|
+
# deletes 3 words; for i/a/o: inserts the text 3 times)
|
|
14
|
+
# The repeat is one undo step.
|
|
15
|
+
#
|
|
16
|
+
# Not recorded: commands run from Visual mode (vim repeats those on the same
|
|
17
|
+
# amount of text, not done here), undo/redo, macros, and commands that act on
|
|
18
|
+
# files, buffers or the view rather than the text.
|
|
19
|
+
class DotRepeat
|
|
20
|
+
# The last change: { action:, count:, reg:, typed: [...], changed: }
|
|
21
|
+
attr_reader :last
|
|
22
|
+
|
|
23
|
+
NOT_CHANGES = /\A(a\.)?(undo|macro|buf|file|app|debug|help|panel|view|lsp|grep|ack|search|mode\.cmdline)\b/
|
|
24
|
+
TYPING_MODES = [:insert, :replace]
|
|
25
|
+
|
|
26
|
+
def initialize
|
|
27
|
+
@last = nil
|
|
28
|
+
@cmd = nil
|
|
29
|
+
@insert = nil
|
|
30
|
+
@replaying = false
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def replaying?
|
|
34
|
+
@replaying
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# KeyBindingTree :key_action: a command is about to run
|
|
38
|
+
def before(action)
|
|
39
|
+
return if @replaying
|
|
40
|
+
if @insert
|
|
41
|
+
@insert[:typed] << action
|
|
42
|
+
return
|
|
43
|
+
end
|
|
44
|
+
@cmd = { action: action, count: vma.kbd.next_command_count, reg: vma.registers.pending,
|
|
45
|
+
buf: vma.buf, version: vma.buf&.edit_version, mode: vma.kbd.get_mode }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# KeyBindingTree :action_handled: the command finished
|
|
49
|
+
def after(action)
|
|
50
|
+
return if @replaying
|
|
51
|
+
mode = vma.kbd.get_mode
|
|
52
|
+
if @insert
|
|
53
|
+
if !TYPING_MODES.include?(mode)
|
|
54
|
+
@last = @insert
|
|
55
|
+
@insert = nil
|
|
56
|
+
end
|
|
57
|
+
return
|
|
58
|
+
end
|
|
59
|
+
c = @cmd
|
|
60
|
+
@cmd = nil
|
|
61
|
+
return if c.nil? || !c[:action].equal?(action) || c[:mode] != :command
|
|
62
|
+
return if action.class != String || action.match?(NOT_CHANGES)
|
|
63
|
+
changed = vma.buf.equal?(c[:buf]) && vma.buf.edit_version != c[:version]
|
|
64
|
+
if TYPING_MODES.include?(mode)
|
|
65
|
+
@insert = c.merge(typed: [], changed: changed)
|
|
66
|
+
elsif changed
|
|
67
|
+
@last = c.merge(typed: [], changed: true)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# ".": run the last change again. count: the count typed before ".", which
|
|
72
|
+
# replaces the change's own.
|
|
73
|
+
def repeat(count = nil)
|
|
74
|
+
l = @last
|
|
75
|
+
return false if l.nil?
|
|
76
|
+
b = vma.buf
|
|
77
|
+
kbd = vma.kbd
|
|
78
|
+
@replaying = true
|
|
79
|
+
b.new_undo_group
|
|
80
|
+
b.instance_variable_set(:@macro_group_active, true)
|
|
81
|
+
begin
|
|
82
|
+
vma.registers.select(l[:reg]) if l[:reg]
|
|
83
|
+
typed = l[:typed]
|
|
84
|
+
leave = typed.empty? ? [] : [typed.last]
|
|
85
|
+
body = typed[0...-1] || []
|
|
86
|
+
# An insert command (i, a, o: the text didn't change before typing):
|
|
87
|
+
# the count repeats the typed text. Otherwise it goes to the command.
|
|
88
|
+
insert_cmd = !l[:changed] && typed.any?
|
|
89
|
+
kbd.next_command_count = insert_cmd ? l[:count] : (count || l[:count])
|
|
90
|
+
kbd.handle_key_bindigs_action(l[:action], nil)
|
|
91
|
+
times = insert_cmd ? (count || 1) : 1
|
|
92
|
+
times.times { body.each { |a| exec_action(a) } }
|
|
93
|
+
leave.each { |a| exec_action(a) }
|
|
94
|
+
ensure
|
|
95
|
+
b.instance_variable_set(:@macro_group_active, false)
|
|
96
|
+
b.new_undo_group
|
|
97
|
+
@replaying = false
|
|
98
|
+
# The nested run reset this; "." handles its count itself
|
|
99
|
+
kbd.method_handles_repeat = true
|
|
100
|
+
end
|
|
101
|
+
true
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end # module Vimamsa
|
data/lib/vimamsa/easy_jump.rb
CHANGED
|
@@ -58,7 +58,9 @@ class EasyJump
|
|
|
58
58
|
# vma.paint_stack = []
|
|
59
59
|
debug "EASY JUMP: easy_jump_input_char [#{c}]"
|
|
60
60
|
@easy_jump_input << c.upcase
|
|
61
|
+
state = :typing
|
|
61
62
|
if @jump_sequence.include?(@easy_jump_input)
|
|
63
|
+
state = :jumped
|
|
62
64
|
jshash = Hash[@jump_sequence.map.with_index.to_a]
|
|
63
65
|
nthword = jshash[@easy_jump_input]
|
|
64
66
|
newpos = @easy_jump_wsmarks[nthword]
|
|
@@ -68,25 +70,74 @@ class EasyJump
|
|
|
68
70
|
end
|
|
69
71
|
vma.kbd.remove_keyhandling_override
|
|
70
72
|
@jump_sequence = []
|
|
71
|
-
|
|
73
|
+
show_chosen(nthword)
|
|
72
74
|
end
|
|
73
|
-
if @easy_jump_input.size
|
|
75
|
+
show_typed if state == :typing && @easy_jump_input.size <= 2
|
|
76
|
+
if state == :typing && @easy_jump_input.size > 2
|
|
77
|
+
state = :nomatch
|
|
74
78
|
# @kbd.set_mode(:command)
|
|
75
79
|
vma.kbd.remove_keyhandling_override
|
|
76
80
|
@jump_sequence = []
|
|
77
81
|
vma.gui.clear_overlay
|
|
78
82
|
end
|
|
83
|
+
# The keys of the label go to this override, not to the key bindings:
|
|
84
|
+
# the key log gets them from here
|
|
85
|
+
vma.gui.keylog_panel&.log_jump_label(@easy_jump_input, state, state == :jumped ? buf.lpos + 1 : nil)
|
|
79
86
|
return true
|
|
80
87
|
end
|
|
81
88
|
|
|
89
|
+
LABEL_FG = "#ff0000"
|
|
90
|
+
TYPED_FG = "#ffff66" # the keys of a label typed so far
|
|
91
|
+
CHOSEN_SECS = 0.15 # the chosen label stays this long after the others go
|
|
92
|
+
|
|
82
93
|
def easy_jump_draw()
|
|
83
94
|
vma.gui.start_overlay_draw
|
|
95
|
+
@labels = []
|
|
84
96
|
for i in 0..(@easy_jump_wsmarks.size - 1)
|
|
85
|
-
vma.gui.overlay_draw_text(@jump_sequence[i], @easy_jump_wsmarks[i])
|
|
97
|
+
@labels << vma.gui.overlay_draw_text(@jump_sequence[i], @easy_jump_wsmarks[i], markup: label_markup(@jump_sequence[i], 0))
|
|
86
98
|
end
|
|
87
99
|
vma.gui.end_overlay_draw
|
|
88
100
|
end
|
|
89
101
|
|
|
102
|
+
# Markup of label seq whose first n keys are typed: those bright and
|
|
103
|
+
# bold, the rest red; dim: a label that no longer matches
|
|
104
|
+
def label_markup(seq, n, dim: false)
|
|
105
|
+
seq = seq.to_s
|
|
106
|
+
typed = CGI.escapeHTML(seq[0, n].to_s)
|
|
107
|
+
rest = CGI.escapeHTML(seq[n..].to_s)
|
|
108
|
+
alpha = dim ? " alpha='35%'" : ""
|
|
109
|
+
s = "<span background='#000000ff' weight='ultrabold'#{alpha}>"
|
|
110
|
+
s << "<span foreground='#{TYPED_FG}' weight='heavy'>#{typed}</span>" if !typed.empty?
|
|
111
|
+
s << "<span foreground='#{LABEL_FG}'>#{rest}</span>" if !rest.empty?
|
|
112
|
+
s << "</span>"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# After a key of a label: the matching labels show the typed part, the
|
|
116
|
+
# others are dimmed
|
|
117
|
+
def show_typed
|
|
118
|
+
return if @labels.nil?
|
|
119
|
+
inp = @easy_jump_input
|
|
120
|
+
@labels.each_with_index { |l, i|
|
|
121
|
+
seq = @jump_sequence[i].to_s
|
|
122
|
+
l.markup = seq.start_with?(inp) ? label_markup(seq, inp.size) : label_markup(seq, 0, dim: true)
|
|
123
|
+
}
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# The chosen label alone, all bright, for CHOSEN_SECS
|
|
127
|
+
def show_chosen(i)
|
|
128
|
+
label = @labels && i && @labels[i]
|
|
129
|
+
if label.nil?
|
|
130
|
+
vma.gui.clear_overlay
|
|
131
|
+
return
|
|
132
|
+
end
|
|
133
|
+
@labels.each { |l| vma.gui.overlay_remove(l) if !l.equal?(label) }
|
|
134
|
+
label.markup = label_markup(@easy_jump_input, @easy_jump_input.size)
|
|
135
|
+
vma.gui.clear_overlay_later((CHOSEN_SECS * 1000).round)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Test-visible: the label widgets, in the order of the marks
|
|
139
|
+
attr_reader :labels
|
|
140
|
+
|
|
90
141
|
def make_jump_sequence(num_items)
|
|
91
142
|
left_hand = "asdfvgbqwertzxc123".upcase.split("")
|
|
92
143
|
right_hand = "jklhnnmyuiop890".upcase.split("")
|