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.
- checksums.yaml +4 -4
- data/.github/workflows/appimage.yml +93 -0
- data/.gitignore +4 -1
- data/Dockerfile +7 -4
- data/README.md +195 -99
- data/custom_example.rb +59 -17
- data/doc/TODO.md +678 -0
- data/doc/action_names_plan.md +442 -0
- data/doc/bundling_plan.md +570 -0
- 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 +213 -0
- data/doc/line_tree_plan.md +89 -0
- data/doc/missing_vim_bindings.md +61 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/registries_plan.md +202 -0
- data/doc/startup_speed_plan.md +97 -0
- data/doc/treap_visualizer.html +585 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +451 -0
- data/doc/vimlike_vim_conflicts.md +262 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/doc/wysiwyg_plan.md +231 -0
- data/exe/run_tests.rb +124 -3
- data/exe/vimamsa +68 -5
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/help/intro.txt +30 -0
- data/help/vim_intro.txt +31 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/img/demo.mp4 +0 -0
- data/lang/hyperplaintext.lang +7 -1
- data/lib/vimamsa/ack.rb +13 -1
- data/lib/vimamsa/actions.rb +385 -37
- data/lib/vimamsa/appimage_env.rb +35 -0
- data/lib/vimamsa/audio.rb +2 -5
- data/lib/vimamsa/bookmarks.rb +302 -0
- data/lib/vimamsa/buffer.rb +675 -118
- data/lib/vimamsa/buffer_changetext.rb +150 -68
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +6 -2
- data/lib/vimamsa/buffer_manager.rb +10 -7
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/cli_help.rb +75 -0
- data/lib/vimamsa/clipboard.rb +9 -3
- data/lib/vimamsa/conf.rb +68 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +6 -3
- data/lib/vimamsa/demo_player.rb +458 -0
- data/lib/vimamsa/demo_recorder.rb +277 -0
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +40 -11
- data/lib/vimamsa/dot_repeat.rb +104 -0
- data/lib/vimamsa/easy_jump.rb +57 -3
- data/lib/vimamsa/editor.rb +327 -78
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +4 -1
- data/lib/vimamsa/file_manager.rb +46 -31
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/form_input.rb +388 -0
- data/lib/vimamsa/gui.rb +603 -119
- data/lib/vimamsa/gui_command_line.rb +247 -0
- data/lib/vimamsa/gui_dialog.rb +94 -42
- data/lib/vimamsa/gui_file_panel.rb +356 -25
- data/lib/vimamsa/gui_form_generator.rb +75 -40
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_key_hint.rb +165 -0
- data/lib/vimamsa/gui_keylog_panel.rb +408 -0
- data/lib/vimamsa/gui_menu.rb +84 -53
- data/lib/vimamsa/gui_select_window.rb +80 -75
- data/lib/vimamsa/gui_settings.rb +86 -41
- data/lib/vimamsa/gui_sourceview.rb +280 -92
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +615 -0
- data/lib/vimamsa/hook.rb +5 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/intro_page.rb +368 -0
- data/lib/vimamsa/key_actions.rb +382 -193
- data/lib/vimamsa/key_binding_tree.rb +467 -273
- data/lib/vimamsa/key_bindings_notepad.rb +45 -0
- data/lib/vimamsa/key_bindings_report.rb +484 -0
- data/lib/vimamsa/key_bindings_vim.rb +104 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +353 -289
- data/lib/vimamsa/key_names.rb +80 -0
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/line_tree.rb +367 -0
- data/lib/vimamsa/macro.rb +23 -3
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +41 -1
- data/lib/vimamsa/registers.rb +125 -0
- data/lib/vimamsa/run_ruby.rb +64 -0
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +15 -14
- data/lib/vimamsa/string_util.rb +134 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +11 -8
- data/lib/vimamsa/text_objects.rb +310 -0
- data/lib/vimamsa/text_transforms.rb +18 -0
- data/lib/vimamsa/tmp_user_dir.rb +39 -0
- data/lib/vimamsa/user_dirs.rb +83 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa/vim_core.rb +355 -0
- data/lib/vimamsa/vim_operators.rb +365 -0
- data/lib/vimamsa.rb +0 -1
- data/modules/calculator/calculator.rb +5 -5
- data/modules/color_highlight/color_highlight.rb +118 -0
- data/modules/color_highlight/color_highlight_info.rb +3 -0
- data/modules/dictation/dictation.rb +1054 -0
- data/modules/dictation/dictation_info.rb +3 -0
- data/modules/dictation/whisper_worker.py +273 -0
- data/modules/ollama/ollama.rb +107 -0
- data/modules/ollama/ollama_info.rb +3 -0
- data/modules/terminal/terminal.rb +5 -5
- data/modules/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.rb +138 -0
- data/scripts/appimage/AppRun +54 -0
- data/scripts/appimage/Dockerfile +18 -0
- data/scripts/appimage/build.sh +19 -0
- data/scripts/appimage/build_in_container.sh +192 -0
- data/scripts/appimage/smoke_test.sh +27 -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 +67 -0
- data/scripts/demo/notes.txt +6 -0
- data/scripts/demo/record_demo.rb +156 -0
- data/scripts/demo/report.rb +7 -0
- data/scripts/demo/shapes.rb +29 -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/styles/134272-molokai.xml +3 -0
- data/styles/molokai_cyber.xml +48 -0
- data/styles/molokai_edit.xml +1 -0
- data/tests/support/virtual_keyboard.rb +254 -0
- data/tests/support/virtual_mic.rb +67 -0
- data/tests/test_ack.rb +22 -0
- data/tests/test_action_ids.rb +232 -0
- data/tests/test_auto_format.rb +122 -0
- data/tests/test_autocomplete.rb +211 -0
- data/tests/test_autosave.rb +145 -0
- data/tests/test_basic_editing.rb +46 -16
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +88 -0
- data/tests/test_bundling.rb +92 -0
- data/tests/test_cli_help.rb +64 -0
- data/tests/test_color_highlight.rb +92 -0
- data/tests/test_command_line.rb +79 -0
- data/tests/test_command_line_file.rb +27 -0
- data/tests/test_context_menu_file.rb +147 -0
- data/tests/test_copy_paste.rb +106 -26
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -0
- data/tests/test_demo_player.rb +301 -0
- data/tests/test_demo_recorder.rb +202 -0
- data/tests/test_dialog_callback_errors.rb +44 -0
- data/tests/test_dictation.rb +294 -0
- data/tests/test_diff_buffer_name.rb +51 -0
- data/tests/test_dot_repeat.rb +88 -0
- data/tests/test_double_click.rb +41 -0
- data/tests/test_drag_selection.rb +125 -0
- data/tests/test_e2e_cmdline.rb +116 -0
- data/tests/test_e2e_dictation.rb +98 -0
- data/tests/test_e2e_replace_char.rb +58 -0
- data/tests/test_easy_jump.rb +93 -0
- data/tests/test_extract_file_links.rb +55 -0
- data/tests/test_file_format.rb +217 -0
- data/tests/test_file_manager.rb +72 -0
- data/tests/test_file_panel.rb +269 -0
- data/tests/test_flash.rb +78 -0
- data/tests/test_fold.rb +111 -0
- data/tests/test_font_refresh.rb +56 -0
- data/tests/test_form_input.rb +203 -0
- data/tests/test_func_panel.rb +68 -0
- data/tests/test_grep_apply.rb +46 -0
- data/tests/test_gtk_sync.rb +126 -0
- data/tests/test_hpt_highlight_visible.rb +75 -0
- data/tests/test_hpt_link_highlight.rb +82 -0
- data/tests/test_intro_page.rb +437 -0
- data/tests/test_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_key_categories.rb +163 -0
- data/tests/test_keylog_panel.rb +261 -0
- data/tests/test_line_ends.rb +51 -0
- data/tests/test_line_tree.rb +86 -0
- data/tests/test_lsp_clangd.rb +281 -0
- data/tests/test_lsp_jump.rb +87 -0
- data/tests/test_lsp_position_encoding.rb +49 -0
- data/tests/test_lsp_symbols.rb +68 -0
- data/tests/test_macro.rb +137 -0
- data/tests/test_markdown_highlight.rb +57 -0
- data/tests/test_mode_badge.rb +41 -0
- data/tests/test_module_interface.rb +9 -9
- data/tests/test_notepad_bindings.rb +67 -0
- data/tests/test_perf_startup.rb +28 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_registers.rb +122 -0
- data/tests/test_revert.rb +127 -0
- data/tests/test_run_ruby.rb +77 -0
- data/tests/test_startup_file.rb +58 -0
- data/tests/test_status_area.rb +50 -0
- data/tests/test_text_objects.rb +163 -0
- data/tests/test_text_transforms.rb +341 -0
- data/tests/test_tmp_user_dir.rb +79 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_undo.rb +34 -34
- data/tests/test_user_dirs.rb +122 -0
- data/tests/test_vim_bindings.rb +353 -0
- data/tests/test_vim_conflicts.rb +100 -0
- data/tests/test_vim_operators.rb +116 -0
- data/tests/test_window_layout.rb +302 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +129 -0
- metadata +167 -10
|
@@ -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
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
|
|
3
|
+
module Vimamsa
|
|
4
|
+
|
|
5
|
+
# Application id used both for the GTK application (see gui.rb) and as the
|
|
6
|
+
# StartupWMClass / desktop-file basename so desktop environments can match the
|
|
7
|
+
# running window to its launcher entry and icon.
|
|
8
|
+
VMA_APP_ID = "net.samiddhi.vimamsa"
|
|
9
|
+
|
|
10
|
+
# Install a desktop launcher entry + application icon into the user's data dir
|
|
11
|
+
# (~/.local/share). Runs on every startup but only writes when the installed
|
|
12
|
+
# copy is missing or differs from the bundled source, so a new logo / changed
|
|
13
|
+
# .desktop shipped by a gem upgrade is picked up automatically, while the common
|
|
14
|
+
# unchanged case does nothing (and never spawns the cache-refresh processes).
|
|
15
|
+
# Best-effort — any failure is logged and swallowed so it can never block startup.
|
|
16
|
+
def install_desktop_integration
|
|
17
|
+
icon_src = ppath("icon.png")
|
|
18
|
+
unless File.exist?(icon_src)
|
|
19
|
+
debug "Desktop install: icon source not found at #{icon_src}"
|
|
20
|
+
return
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
data_home = ENV["XDG_DATA_HOME"]
|
|
24
|
+
data_home = File.expand_path("~/.local/share") if data_home.nil? || data_home.empty?
|
|
25
|
+
|
|
26
|
+
icon_dir = File.join(data_home, "icons", "hicolor", "256x256", "apps")
|
|
27
|
+
icon_dst = File.join(icon_dir, "vimamsa.png")
|
|
28
|
+
apps_dir = File.join(data_home, "applications")
|
|
29
|
+
desktop_dst = File.join(apps_dir, "#{VMA_APP_ID}.desktop")
|
|
30
|
+
|
|
31
|
+
installed_something = false
|
|
32
|
+
|
|
33
|
+
# Re-copy the icon whenever the bundled source differs (e.g. a new logo after
|
|
34
|
+
# a gem upgrade). FileUtils.identical? compares contents, not just mtime.
|
|
35
|
+
if !File.exist?(icon_dst) || !FileUtils.identical?(icon_src, icon_dst)
|
|
36
|
+
FileUtils.mkdir_p(icon_dir)
|
|
37
|
+
FileUtils.cp(icon_src, icon_dst)
|
|
38
|
+
installed_something = true
|
|
39
|
+
debug "Desktop install: copied icon to #{icon_dst}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# The .desktop file is app-generated metadata; rewrite it when our generated
|
|
43
|
+
# content changes (new fields / version). This is not a user-customization file.
|
|
44
|
+
desktop_txt = desktop_entry_contents
|
|
45
|
+
if !File.exist?(desktop_dst) || File.read(desktop_dst) != desktop_txt
|
|
46
|
+
FileUtils.mkdir_p(apps_dir)
|
|
47
|
+
File.write(desktop_dst, desktop_txt)
|
|
48
|
+
installed_something = true
|
|
49
|
+
debug "Desktop install: wrote #{desktop_dst}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
refresh_desktop_caches(File.join(data_home, "icons", "hicolor"), apps_dir) if installed_something
|
|
53
|
+
rescue => e
|
|
54
|
+
# Never let desktop integration break startup.
|
|
55
|
+
debug "Desktop install failed: #{e.class}: #{e.message}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Exec= value for the launcher. From an AppImage ($APPIMAGE is the file's path,
|
|
59
|
+
# set by the AppImage runtime) the launcher runs that file, so it works without
|
|
60
|
+
# a vimamsa on PATH; if the file is moved, the next start rewrites the entry.
|
|
61
|
+
# Otherwise the gem's binstub.
|
|
62
|
+
def desktop_exec_command
|
|
63
|
+
appimage = ENV["APPIMAGE"]
|
|
64
|
+
return "vimamsa %F" if appimage.nil? || appimage.empty?
|
|
65
|
+
# Desktop Entry spec: inside quotes, backslash-escape " ` $ \; then the
|
|
66
|
+
# string-value escaping doubles every backslash again; % is written %%.
|
|
67
|
+
quoted = appimage.gsub(/["`$\\]/) { |c| "\\#{c}" }.gsub("\\") { "\\\\" }.gsub("%", "%%")
|
|
68
|
+
%{"#{quoted}" %F}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def desktop_entry_contents
|
|
72
|
+
<<~DESKTOP
|
|
73
|
+
[Desktop Entry]
|
|
74
|
+
Type=Application
|
|
75
|
+
Name=Vimamsa
|
|
76
|
+
Comment=Vi/Vim-inspired GUI text editor
|
|
77
|
+
Exec=#{desktop_exec_command}
|
|
78
|
+
Icon=vimamsa
|
|
79
|
+
Terminal=false
|
|
80
|
+
Categories=Utility;TextEditor;
|
|
81
|
+
StartupWMClass=#{VMA_APP_ID}
|
|
82
|
+
DESKTOP
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def refresh_desktop_caches(icon_theme_dir, apps_dir)
|
|
86
|
+
if which("gtk-update-icon-cache")
|
|
87
|
+
system("gtk-update-icon-cache", "-q", "-t", "-f", icon_theme_dir,
|
|
88
|
+
out: File::NULL, err: File::NULL)
|
|
89
|
+
end
|
|
90
|
+
if which("update-desktop-database")
|
|
91
|
+
system("update-desktop-database", apps_dir,
|
|
92
|
+
out: File::NULL, err: File::NULL)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end # module Vimamsa
|
data/lib/vimamsa/diff_buffer.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
# Map a "line number in a unified diff output" to the corresponding
|
|
2
4
|
# line in the new/changed file (the + side), together with the file it belongs to.
|
|
3
5
|
#
|
|
@@ -83,7 +85,7 @@ def diff_buffer_init()
|
|
|
83
85
|
return if @diff_buffer_init_done
|
|
84
86
|
@diff_buffer_init_done = true
|
|
85
87
|
vma.kbd.add_minor_mode("diffview", :diffview, :command)
|
|
86
|
-
bindkey "diffview enter",
|
|
88
|
+
bindkey "diffview enter", "diffview.source"
|
|
87
89
|
end
|
|
88
90
|
|
|
89
91
|
def diff_buffer()
|
|
@@ -93,9 +95,18 @@ def diff_buffer()
|
|
|
93
95
|
infile = Tempfile.new("in")
|
|
94
96
|
infile.write(vma.buf.to_s)
|
|
95
97
|
infile.flush
|
|
96
|
-
|
|
98
|
+
# Compare like with like: the buffer is UTF-8 + \n, the file may be in
|
|
99
|
+
# another encoding / CRLF (see read_file_with_format), so diff against the
|
|
100
|
+
# file as it would be loaded. Both sides are labeled with the real path.
|
|
101
|
+
origfile = Tempfile.new("orig")
|
|
102
|
+
origfile.write(read_file("", orig_path))
|
|
103
|
+
origfile.flush
|
|
104
|
+
label = Shellwords.escape(orig_path)
|
|
105
|
+
bufstr = text_to_utf8(run_cmd("diff -uw --label #{label} --label #{label} " \
|
|
106
|
+
"#{Shellwords.escape(origfile.path)} #{Shellwords.escape(infile.path)}"))
|
|
97
107
|
infile.close; infile.unlink
|
|
98
|
-
|
|
108
|
+
origfile.close; origfile.unlink
|
|
109
|
+
create_new_buffer(bufstr, "diff-unsaved-#{File.basename(orig_path.to_s)}")
|
|
99
110
|
gui_set_file_lang(vma.buf.id, "diff")
|
|
100
111
|
vma.kbd.set_mode(:diffview)
|
|
101
112
|
end
|
|
@@ -126,7 +137,7 @@ end
|
|
|
126
137
|
# Prefers new_path (the post-change file); falls back to old_path
|
|
127
138
|
# when new_path is /dev/null or a temp file that no longer exists.
|
|
128
139
|
def resolve_diff_path(new_path, old_path)
|
|
129
|
-
git_root = `git rev-parse --show-toplevel 2>/dev/null`.strip
|
|
140
|
+
git_root = vma.buf.git_root || `git rev-parse --show-toplevel 2>/dev/null`.strip
|
|
130
141
|
|
|
131
142
|
expand = lambda do |path|
|
|
132
143
|
return nil if path.nil? || path == "/dev/null"
|
|
@@ -144,24 +155,32 @@ def resolve_diff_path(new_path, old_path)
|
|
|
144
155
|
expand.call(old_path)
|
|
145
156
|
end
|
|
146
157
|
|
|
158
|
+
# Git worktree root containing the current buffer's file (or CWD when the buffer
|
|
159
|
+
# has no file), or nil if it is not inside a git repository.
|
|
160
|
+
def buffer_git_root
|
|
161
|
+
dir = vma.buf.fname ? File.dirname(vma.buf.fname) : Dir.pwd
|
|
162
|
+
root = `git -C #{Shellwords.escape(dir)} rev-parse --show-toplevel 2>/dev/null`.strip
|
|
163
|
+
root.empty? ? nil : root
|
|
164
|
+
end
|
|
165
|
+
|
|
147
166
|
def git_diff_w()
|
|
148
167
|
return if !if_cmd_exists("git")
|
|
149
168
|
diff_buffer_init
|
|
150
169
|
|
|
151
|
-
|
|
152
|
-
git_root
|
|
153
|
-
if git_root.empty?
|
|
170
|
+
git_root = buffer_git_root
|
|
171
|
+
if git_root.nil?
|
|
154
172
|
message("Not a git repository")
|
|
155
173
|
return
|
|
156
174
|
end
|
|
157
175
|
|
|
158
|
-
bufstr = run_cmd("git -C #{Shellwords.escape(git_root)} diff -w")
|
|
176
|
+
bufstr = text_to_utf8(run_cmd("git -C #{Shellwords.escape(git_root)} diff -w"))
|
|
159
177
|
if bufstr.strip.empty?
|
|
160
178
|
message("git diff -w: no changes")
|
|
161
179
|
return
|
|
162
180
|
end
|
|
163
181
|
|
|
164
|
-
|
|
182
|
+
create_new_buffer(bufstr, "gitdiff-#{File.basename(git_root)}")
|
|
183
|
+
vma.buf.git_root = git_root
|
|
165
184
|
gui_set_file_lang(vma.buf.id, "diff")
|
|
166
185
|
vma.kbd.set_mode(:diffview)
|
|
167
186
|
end
|
|
@@ -174,12 +193,22 @@ def git_diff_buffer()
|
|
|
174
193
|
message("Buffer has no file")
|
|
175
194
|
return
|
|
176
195
|
end
|
|
177
|
-
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
git_root = buffer_git_root
|
|
199
|
+
if git_root.nil?
|
|
200
|
+
message("Not a git repository")
|
|
201
|
+
return
|
|
202
|
+
end
|
|
203
|
+
bufstr = text_to_utf8(run_cmd("git -C #{Shellwords.escape(git_root)} diff -w -- #{Shellwords.escape(fname)}"))
|
|
178
204
|
if bufstr.strip.empty?
|
|
179
205
|
message("git diff: no changes")
|
|
180
206
|
return
|
|
181
207
|
end
|
|
182
|
-
|
|
208
|
+
create_new_buffer(bufstr, "gitdiff-#{File.basename(fname)}")
|
|
209
|
+
vma.buf.git_root = git_root
|
|
183
210
|
gui_set_file_lang(vma.buf.id, "diff")
|
|
184
211
|
vma.kbd.set_mode(:diffview)
|
|
185
212
|
end
|
|
213
|
+
|
|
214
|
+
end # module Vimamsa
|
|
@@ -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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
# Similar feature as Vim EasyMotion https://github.com/easymotion/vim-easymotion
|
|
2
4
|
class EasyJump
|
|
3
5
|
# def self.initialize()
|
|
@@ -56,7 +58,9 @@ class EasyJump
|
|
|
56
58
|
# vma.paint_stack = []
|
|
57
59
|
debug "EASY JUMP: easy_jump_input_char [#{c}]"
|
|
58
60
|
@easy_jump_input << c.upcase
|
|
61
|
+
state = :typing
|
|
59
62
|
if @jump_sequence.include?(@easy_jump_input)
|
|
63
|
+
state = :jumped
|
|
60
64
|
jshash = Hash[@jump_sequence.map.with_index.to_a]
|
|
61
65
|
nthword = jshash[@easy_jump_input]
|
|
62
66
|
newpos = @easy_jump_wsmarks[nthword]
|
|
@@ -66,25 +70,74 @@ class EasyJump
|
|
|
66
70
|
end
|
|
67
71
|
vma.kbd.remove_keyhandling_override
|
|
68
72
|
@jump_sequence = []
|
|
69
|
-
|
|
73
|
+
show_chosen(nthword)
|
|
70
74
|
end
|
|
71
|
-
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
|
|
72
78
|
# @kbd.set_mode(:command)
|
|
73
79
|
vma.kbd.remove_keyhandling_override
|
|
74
80
|
@jump_sequence = []
|
|
75
81
|
vma.gui.clear_overlay
|
|
76
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)
|
|
77
86
|
return true
|
|
78
87
|
end
|
|
79
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
|
+
|
|
80
93
|
def easy_jump_draw()
|
|
81
94
|
vma.gui.start_overlay_draw
|
|
95
|
+
@labels = []
|
|
82
96
|
for i in 0..(@easy_jump_wsmarks.size - 1)
|
|
83
|
-
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))
|
|
84
98
|
end
|
|
85
99
|
vma.gui.end_overlay_draw
|
|
86
100
|
end
|
|
87
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
|
+
|
|
88
141
|
def make_jump_sequence(num_items)
|
|
89
142
|
left_hand = "asdfvgbqwertzxc123".upcase.split("")
|
|
90
143
|
right_hand = "jklhnnmyuiop890".upcase.split("")
|
|
@@ -162,3 +215,4 @@ class EasyJump
|
|
|
162
215
|
return sequence
|
|
163
216
|
end
|
|
164
217
|
end
|
|
218
|
+
end # module Vimamsa
|