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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
# Left-side panel that displays LSP-provided functions/methods for the current buffer,
|
|
2
4
|
# grouped by the class or module they belong to.
|
|
3
5
|
class FuncPanel
|
|
@@ -9,32 +11,14 @@ class FuncPanel
|
|
|
9
11
|
# under their parent class. Two columns: the display string and the line number.
|
|
10
12
|
@store = Gtk::TreeStore.new(String, Integer)
|
|
11
13
|
|
|
12
|
-
# @tree
|
|
13
|
-
#
|
|
14
|
-
|
|
15
|
-
@tree
|
|
16
|
-
@tree.activate_on_single_click = true
|
|
17
|
-
|
|
18
|
-
# Single text column; ellipsize at end so long names don't overflow the panel width.
|
|
19
|
-
renderer = Gtk::CellRendererText.new
|
|
20
|
-
renderer.ellipsize = Pango::EllipsizeMode::END
|
|
21
|
-
col = Gtk::TreeViewColumn.new("", renderer, text: COL_NAME)
|
|
22
|
-
col.expand = true
|
|
23
|
-
@tree.append_column(col)
|
|
24
|
-
|
|
25
|
-
# Jump to the function's line when a row is clicked.
|
|
26
|
-
# Class header rows have COL_LINE = 0 and are skipped (no jump).
|
|
27
|
-
@tree.signal_connect("row-activated") do |_tv, path, _col|
|
|
28
|
-
iter = @store.get_iter(path)
|
|
29
|
-
next if iter.nil?
|
|
14
|
+
# @tree renders @store; it holds expand/collapse state and row selection.
|
|
15
|
+
# Clicking a row jumps to the function's line; class header rows have
|
|
16
|
+
# COL_LINE = 0 and are skipped (no jump).
|
|
17
|
+
@tree, sw = build_list_tree(@store, text_col: COL_NAME) do |iter|
|
|
30
18
|
line = iter[COL_LINE]
|
|
31
19
|
next if line <= 0
|
|
32
20
|
vma.buf.jump_to_line(line)
|
|
33
21
|
end
|
|
34
|
-
|
|
35
|
-
sw = Gtk::ScrolledWindow.new
|
|
36
|
-
sw.set_policy(:never, :automatic)
|
|
37
|
-
sw.set_child(@tree)
|
|
38
22
|
sw.vexpand = true
|
|
39
23
|
|
|
40
24
|
header = Gtk::Label.new("<span weight='ultrabold'>Functions</span> (click to jump)")
|
|
@@ -48,6 +32,7 @@ class FuncPanel
|
|
|
48
32
|
# @box is the outermost widget: header label on top, scrollable tree below.
|
|
49
33
|
@box = Gtk::Box.new(:vertical, 0)
|
|
50
34
|
@box.set_size_request(160, -1)
|
|
35
|
+
@box.add_css_class("side-panel")
|
|
51
36
|
@box.append(header)
|
|
52
37
|
@box.append(sw)
|
|
53
38
|
end
|
|
@@ -66,6 +51,23 @@ class FuncPanel
|
|
|
66
51
|
set_placeholder("(no file)")
|
|
67
52
|
return
|
|
68
53
|
end
|
|
54
|
+
if hyperplaintext_buffer?(buf)
|
|
55
|
+
entries = hyperplaintext_outline_entries(buf)
|
|
56
|
+
@store.clear
|
|
57
|
+
if entries.empty?
|
|
58
|
+
set_placeholder("(no headings)")
|
|
59
|
+
else
|
|
60
|
+
populate_hyperplaintext(entries)
|
|
61
|
+
end
|
|
62
|
+
return
|
|
63
|
+
end
|
|
64
|
+
# LangSrv is only defined when LSP is enabled (require guarded in
|
|
65
|
+
# Editor#start). Without this check, opening the panel with LSP off
|
|
66
|
+
# raises NameError inside the GTK callback and glib2 kills the whole app.
|
|
67
|
+
unless cnf.lsp.enabled? && defined?(LangSrv)
|
|
68
|
+
set_placeholder("(no LSP)")
|
|
69
|
+
return
|
|
70
|
+
end
|
|
69
71
|
lsp = LangSrv.get(buf.lang)
|
|
70
72
|
unless lsp
|
|
71
73
|
set_placeholder("(no LSP)")
|
|
@@ -117,6 +119,48 @@ class FuncPanel
|
|
|
117
119
|
@tree.expand_all # show all classes expanded by default
|
|
118
120
|
end
|
|
119
121
|
|
|
122
|
+
def populate_hyperplaintext(entries)
|
|
123
|
+
parents = {}
|
|
124
|
+
entries.each do |entry|
|
|
125
|
+
parent = nil
|
|
126
|
+
if entry[:level] > 0
|
|
127
|
+
parent = parents[entry[:level] - 1]
|
|
128
|
+
end
|
|
129
|
+
row = @store.append(parent)
|
|
130
|
+
row[COL_NAME] = entry[:name]
|
|
131
|
+
row[COL_LINE] = entry[:line]
|
|
132
|
+
parents[entry[:level]] = row
|
|
133
|
+
parents.delete_if { |level, _iter| level > entry[:level] }
|
|
134
|
+
end
|
|
135
|
+
@tree.expand_all
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def hyperplaintext_buffer?(buf)
|
|
139
|
+
buf.lang == "hyperplaintext" || buf.fname&.end_with?(".txt")
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def hyperplaintext_outline_entries(buf)
|
|
143
|
+
entries = []
|
|
144
|
+
buf.to_s.each_line.with_index(1) do |line, line_no|
|
|
145
|
+
stripped = line.strip
|
|
146
|
+
next if stripped.empty?
|
|
147
|
+
|
|
148
|
+
if (m = stripped.match(/\A❙\s*(.*?)\s*❙\z/))
|
|
149
|
+
title = m[1].strip
|
|
150
|
+
entries << { name: title, line: line_no, level: 0 } unless title.empty?
|
|
151
|
+
next
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
if (m = stripped.match(/\A(◼+)\s+(.*)\z/))
|
|
155
|
+
name = m[2].strip
|
|
156
|
+
next if name.empty?
|
|
157
|
+
level = [m[1].length, 6].min
|
|
158
|
+
entries << { name: name, line: line_no, level: level }
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
entries
|
|
162
|
+
end
|
|
163
|
+
|
|
120
164
|
# Replace the entire store contents with a single non-clickable status message.
|
|
121
165
|
def set_placeholder(text)
|
|
122
166
|
@store.clear
|
|
@@ -125,3 +169,4 @@ class FuncPanel
|
|
|
125
169
|
iter[COL_LINE] = 0
|
|
126
170
|
end
|
|
127
171
|
end
|
|
172
|
+
end # module Vimamsa
|
data/lib/vimamsa/gui_image.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
# Following this example:
|
|
2
4
|
# https://gabmus.org/posts/create_an_auto-resizing_image_widget_with_gtk3_and_python/
|
|
3
5
|
class ResizableImage < Gtk::DrawingArea
|
|
@@ -45,3 +47,4 @@ class ResizableImage < Gtk::DrawingArea
|
|
|
45
47
|
cr.paint
|
|
46
48
|
end
|
|
47
49
|
end
|
|
50
|
+
end # module Vimamsa
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
module Vimamsa
|
|
2
|
+
# A see-through bubble next to the cursor with the key just pressed and the
|
|
3
|
+
# action it ran, so a demo (or a new user) can follow the keys without
|
|
4
|
+
# looking at the key log panel. Shown while the key log panel is shown, fed
|
|
5
|
+
# by it (KeyLogPanel#push), and fades out after a moment. It goes slightly
|
|
6
|
+
# below the cursor's row (cnf.key_hint.y_offset px; above it if there is
|
|
7
|
+
# no room), starting at the cursor's column but right of the text of the
|
|
8
|
+
# rows it covers, with a dashed border to set it apart from the text. It
|
|
9
|
+
# starts with the current mode as a copy of the mode badge (same CSS
|
|
10
|
+
# classes, so it follows the theme, cyberpunk included). It is drawn over
|
|
11
|
+
# the editor, above easy jump's labels, and takes no mouse input.
|
|
12
|
+
class KeyHint
|
|
13
|
+
SHOW_SECS = 2.0 # fully shown
|
|
14
|
+
FADE_SECS = 0.8 # then fading out
|
|
15
|
+
OPACITY = 1.0
|
|
16
|
+
GAP = 14 # px between the end of the line and the bubble
|
|
17
|
+
MIN_GAP = 12 # the gap used when GAP doesn't leave room for the bubble
|
|
18
|
+
Y_OFFSET = 20 # px below the cursor's row (cnf.key_hint.y_offset)
|
|
19
|
+
|
|
20
|
+
# Test-visible: the mode and markup shown; the bubble (a Gtk::Box), its
|
|
21
|
+
# mode badge label and its key/action label
|
|
22
|
+
attr_reader :markup, :widget, :mode_label, :label
|
|
23
|
+
|
|
24
|
+
def initialize
|
|
25
|
+
@mode_label = Gtk::Label.new
|
|
26
|
+
@mode_label.add_css_class("mode-badge")
|
|
27
|
+
@mode_label.valign = :center
|
|
28
|
+
@mode_cls = nil
|
|
29
|
+
@label = Gtk::Label.new
|
|
30
|
+
@label.use_markup = true
|
|
31
|
+
@label.wrap = false
|
|
32
|
+
@widget = Gtk::Box.new(:horizontal, 6)
|
|
33
|
+
@widget.append(@mode_label)
|
|
34
|
+
@widget.append(@label)
|
|
35
|
+
@widget.halign = :start
|
|
36
|
+
@widget.valign = :start
|
|
37
|
+
@widget.can_target = false
|
|
38
|
+
@widget.add_css_class("key-hint")
|
|
39
|
+
css = Gtk::CssProvider.new
|
|
40
|
+
css.load(data: <<~CSS)
|
|
41
|
+
.key-hint {
|
|
42
|
+
background-color: rgba(20, 26, 34, 1.0);
|
|
43
|
+
color: #ffffff;
|
|
44
|
+
border: 1px dashed rgba(255, 255, 255, 1.0);
|
|
45
|
+
border-radius: 8px;
|
|
46
|
+
padding: 0px 8px;
|
|
47
|
+
font-size: 1.3em;
|
|
48
|
+
}
|
|
49
|
+
CSS
|
|
50
|
+
@widget.style_context.add_provider(css)
|
|
51
|
+
@widget.visible = false
|
|
52
|
+
@parent = nil
|
|
53
|
+
@timer = nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def visible?
|
|
57
|
+
@widget.visible?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# body: Pango markup of the key and action; the mode tag goes before it
|
|
61
|
+
def show(body)
|
|
62
|
+
attach
|
|
63
|
+
return if @parent.nil?
|
|
64
|
+
@body = body
|
|
65
|
+
render
|
|
66
|
+
@widget.opacity = OPACITY
|
|
67
|
+
@widget.visible = true
|
|
68
|
+
remove_timer
|
|
69
|
+
# Placed once the action has run, so it follows the cursor's new place
|
|
70
|
+
GLib::Idle.add { place; false }
|
|
71
|
+
@shown_at = Time.now
|
|
72
|
+
@timer = GLib::Timeout.add(40) { fade }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def hide
|
|
76
|
+
remove_timer
|
|
77
|
+
@widget.visible = false
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
# The mode is read when shown and again when placed, after the action
|
|
83
|
+
# has run (v shows VISUAL)
|
|
84
|
+
def render
|
|
85
|
+
text, cls = vma.gui.mode_badge_info
|
|
86
|
+
@mode_label.text = text.to_s
|
|
87
|
+
@mode_label.visible = !text.to_s.empty?
|
|
88
|
+
if cls != @mode_cls
|
|
89
|
+
@mode_label.remove_css_class(@mode_cls) if @mode_cls
|
|
90
|
+
@mode_label.add_css_class(cls) if cls
|
|
91
|
+
@mode_cls = cls
|
|
92
|
+
end
|
|
93
|
+
@label.markup = @body.to_s
|
|
94
|
+
@markup = "#{text} #{@body}"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Into the active window's overlay, as its topmost child (easy jump adds
|
|
98
|
+
# its labels to the same overlay later)
|
|
99
|
+
def attach
|
|
100
|
+
ov = vma.gui.active_window && vma.gui.active_window[:overlay]
|
|
101
|
+
return if ov.nil?
|
|
102
|
+
return if ov.equal?(@parent) && ov.last_child.equal?(@widget)
|
|
103
|
+
@parent&.remove_overlay(@widget)
|
|
104
|
+
ov.add_overlay(@widget)
|
|
105
|
+
@parent = ov
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Right of the end of the cursor's line; if the line is too long, below it
|
|
109
|
+
# (above it near the bottom of the view)
|
|
110
|
+
def place
|
|
111
|
+
v = vma.gui.view
|
|
112
|
+
return if v.nil? || @parent.nil? || !@widget.visible?
|
|
113
|
+
render
|
|
114
|
+
b = vma.buf
|
|
115
|
+
x, y = v.pos_to_coord(b.pos)
|
|
116
|
+
line_h = v.get_iter_location(v.buffer.get_iter_at(offset: b.pos)).height rescue 20
|
|
117
|
+
# The size it will have with the new text (the allocated one is the
|
|
118
|
+
# previous text's); measure counts the margins, which place it
|
|
119
|
+
w = [@widget.measure(:horizontal, -1)[1] - @widget.margin_start - @widget.margin_end, 80].max
|
|
120
|
+
h = [@widget.measure(:vertical, -1)[1] - @widget.margin_top - @widget.margin_bottom, 24].max
|
|
121
|
+
# Slightly below the cursor's row, or above it if there is no room
|
|
122
|
+
off = cnf.key_hint.y_offset! || Y_OFFSET
|
|
123
|
+
nrows = ((h + off) / line_h.to_f).ceil
|
|
124
|
+
top = y + line_h + off
|
|
125
|
+
rows = (b.lpos + 1..b.lpos + nrows)
|
|
126
|
+
if top + h > @parent.height && y - h - off >= 0
|
|
127
|
+
top = y - h - off
|
|
128
|
+
rows = ([b.lpos - nrows, 0].max..b.lpos - 1)
|
|
129
|
+
end
|
|
130
|
+
# From the cursor's column, but right of the text of the rows it covers
|
|
131
|
+
xe = rows.map { |l| row_end_x(v, b, l) }.compact.max
|
|
132
|
+
gap = xe && [GAP, MIN_GAP].find { |g| xe + g + w <= @parent.width }
|
|
133
|
+
left = xe.nil? ? x : (gap ? [x, xe + gap].max : x)
|
|
134
|
+
left = left.clamp(0, [@parent.width - w, 0].max)
|
|
135
|
+
@widget.margin_start = [left, 0].max
|
|
136
|
+
@widget.margin_top = [top, 0].max
|
|
137
|
+
rescue => e
|
|
138
|
+
debug "KeyHint#place: #{e.message}"
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# The x where the text of line l (0-based) ends, or nil past the last line
|
|
142
|
+
def row_end_x(v, b, l)
|
|
143
|
+
return nil if l < 0 || l > b.line_ends.size
|
|
144
|
+
eol = l < b.line_ends.size ? b.line_ends[l] : b.size
|
|
145
|
+
v.pos_to_coord(eol)[0]
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def fade
|
|
149
|
+
t = Time.now - @shown_at
|
|
150
|
+
return true if t < SHOW_SECS
|
|
151
|
+
if t >= SHOW_SECS + FADE_SECS
|
|
152
|
+
@widget.visible = false
|
|
153
|
+
@timer = nil
|
|
154
|
+
return false
|
|
155
|
+
end
|
|
156
|
+
@widget.opacity = OPACITY * (1 - (t - SHOW_SECS) / FADE_SECS)
|
|
157
|
+
true
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def remove_timer
|
|
161
|
+
GLib::Source.remove(@timer) rescue nil if @timer
|
|
162
|
+
@timer = nil
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end # module Vimamsa
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
3
|
+
# Right-side panel that live-logs pressed key chords and the actions they
|
|
4
|
+
# trigger. Meant for demos and for new users learning the key bindings.
|
|
5
|
+
# Fed by direct calls from KeyBindingTree (log_action / log_pending /
|
|
6
|
+
# log_nomatch); all of them are no-ops unless the panel is shown (@active).
|
|
7
|
+
class KeyLogPanel
|
|
8
|
+
MAX_ENTRIES = 200
|
|
9
|
+
|
|
10
|
+
# Test-visible model: array of hashes, one per row (newest last;
|
|
11
|
+
# displayed newest first). kind: :action | :pending | :insert | :nomatch | :mode
|
|
12
|
+
attr_reader :entries
|
|
13
|
+
|
|
14
|
+
# The highlighted Gtk::ListBoxRow of the newest entry
|
|
15
|
+
attr_reader :newest_row
|
|
16
|
+
|
|
17
|
+
# Demo controls (Help ▸ Play demo), shown while a demo plays
|
|
18
|
+
attr_reader :demo_bar, :demo_pause_btn, :demo_speed_lbl, :close_btn, :demo_list
|
|
19
|
+
|
|
20
|
+
# The bubble next to the cursor with the newest entry (gui_key_hint.rb)
|
|
21
|
+
attr_reader :hint
|
|
22
|
+
|
|
23
|
+
# Insert-mode typing arrives as eval-string actions like buf.insert_txt('h');
|
|
24
|
+
# matched here so consecutive chars can be coalesced into one "typed:" row.
|
|
25
|
+
INSERT_TXT_RE = /\Abuf\.insert_txt\((.+)\)\z/
|
|
26
|
+
|
|
27
|
+
# A named action bound to a <char> key, as the key tree runs it:
|
|
28
|
+
# a.edit.insert.char!('h') (KeyBindingTree#match_key_conf)
|
|
29
|
+
CHAR_ACTION_RE = /\Aa\.([a-z][a-z0-9_.]*)!\((.+)\)\z/
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
@entries = []
|
|
33
|
+
@rows = [] # Gtk::ListBoxRow per entry, parallel to @entries
|
|
34
|
+
# (newest last, like @entries; displayed newest first)
|
|
35
|
+
@active = false
|
|
36
|
+
@last_mode = nil # last seen mode badge, e.g. "[COMMAND]"
|
|
37
|
+
@newest_row = nil
|
|
38
|
+
@hint = KeyHint.new
|
|
39
|
+
|
|
40
|
+
@list = Gtk::ListBox.new
|
|
41
|
+
@list.selection_mode = :none
|
|
42
|
+
|
|
43
|
+
# Highlight for the newest row (color from gui_theme.rb, cnf-backed)
|
|
44
|
+
@row_css = Gtk::CssProvider.new
|
|
45
|
+
@row_css.load(data: keylog_row_css)
|
|
46
|
+
|
|
47
|
+
@sw = Gtk::ScrolledWindow.new
|
|
48
|
+
@sw.set_policy(:never, :automatic)
|
|
49
|
+
@sw.set_child(@list)
|
|
50
|
+
@sw.vexpand = true
|
|
51
|
+
|
|
52
|
+
title = Gtk::Label.new("<span weight='ultrabold' size='large'>Key log</span>")
|
|
53
|
+
title.use_markup = true
|
|
54
|
+
title.xalign = 0.0
|
|
55
|
+
title.hexpand = true
|
|
56
|
+
|
|
57
|
+
clear_btn = Gtk::Button.new(label: "Clear")
|
|
58
|
+
clear_btn.signal_connect("clicked") { clear }
|
|
59
|
+
|
|
60
|
+
# Closes the panel (and stops a demo, whose controls are here)
|
|
61
|
+
@close_btn = Gtk::Button.new(label: "✕")
|
|
62
|
+
@close_btn.tooltip_text = "Close the key log"
|
|
63
|
+
@close_btn.focus_on_click = false
|
|
64
|
+
@close_btn.signal_connect("clicked") { close }
|
|
65
|
+
|
|
66
|
+
header = Gtk::Box.new(:horizontal, 6)
|
|
67
|
+
header.margin_start = 8
|
|
68
|
+
header.margin_end = 6
|
|
69
|
+
header.margin_top = 6
|
|
70
|
+
header.margin_bottom = 4
|
|
71
|
+
header.append(title)
|
|
72
|
+
header.append(clear_btn)
|
|
73
|
+
header.append(@close_btn)
|
|
74
|
+
|
|
75
|
+
# @box is the outermost widget: header on top, scrollable log below.
|
|
76
|
+
@box = Gtk::Box.new(:vertical, 0)
|
|
77
|
+
@box.set_size_request(320, -1)
|
|
78
|
+
@box.add_css_class("side-panel")
|
|
79
|
+
@box.append(header)
|
|
80
|
+
@box.append(demo_bar_init)
|
|
81
|
+
@box.append(@sw)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# The ✕ button: hides the panel, stopping a demo that plays
|
|
85
|
+
def close
|
|
86
|
+
DemoPlayer.current.stop("Demo stopped") if DemoPlayer.current&.running?
|
|
87
|
+
vma.gui.hide_keylog_panel
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Pause / continue, slower and faster for DemoPlayer. The buttons
|
|
91
|
+
# don't take the focus, so the editor keeps getting the keys.
|
|
92
|
+
def demo_bar_init
|
|
93
|
+
btn = lambda { |label, tip, &blk|
|
|
94
|
+
b = Gtk::Button.new(label: label)
|
|
95
|
+
b.focus_on_click = false
|
|
96
|
+
b.tooltip_text = tip
|
|
97
|
+
b.signal_connect("clicked") { blk.call }
|
|
98
|
+
b
|
|
99
|
+
}
|
|
100
|
+
@demo_pause_btn = btn.call("Pause", "Pause or continue the demo") { call_action("help.demo.pause") }
|
|
101
|
+
slower = btn.call("−", "Slower") { call_action("help.demo.slower") }
|
|
102
|
+
faster = btn.call("+", "Faster") { call_action("help.demo.faster") }
|
|
103
|
+
@demo_speed_lbl = Gtk::Label.new("1×")
|
|
104
|
+
@demo_speed_lbl.width_chars = 5
|
|
105
|
+
|
|
106
|
+
# The demos (DemoPlayer.demos, recorded ones too); choosing one switches
|
|
107
|
+
# to it
|
|
108
|
+
@demo_names = DemoPlayer::DEMOS.keys
|
|
109
|
+
@demo_list = Gtk::DropDown.new(Gtk::StringList.new(DemoPlayer::DEMOS.values.map { |d| d[:title] }), nil)
|
|
110
|
+
@demo_list.tooltip_text = "Switch to another demo"
|
|
111
|
+
@demo_list.focusable = false
|
|
112
|
+
@demo_list.hexpand = true
|
|
113
|
+
@demo_list.signal_connect("notify::selected") {
|
|
114
|
+
name = @demo_names[@demo_list.selected]
|
|
115
|
+
cur = DemoPlayer.current
|
|
116
|
+
if !@demo_list_updating && name && cur&.running? && cur.name != name
|
|
117
|
+
GLib::Idle.add { DemoPlayer.toggle(name); false }
|
|
118
|
+
end
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
title = Gtk::Label.new("Demo")
|
|
122
|
+
title.xalign = 0.0
|
|
123
|
+
|
|
124
|
+
# Two rows (the demo list, then the buttons), so the panel keeps its width
|
|
125
|
+
list_row = Gtk::Box.new(:horizontal, 6)
|
|
126
|
+
[title, @demo_list].each { |w| list_row.append(w) }
|
|
127
|
+
spacer = Gtk::Label.new("")
|
|
128
|
+
spacer.hexpand = true
|
|
129
|
+
btn_row = Gtk::Box.new(:horizontal, 4)
|
|
130
|
+
[spacer, @demo_pause_btn, slower, @demo_speed_lbl, faster].each { |w| btn_row.append(w) }
|
|
131
|
+
|
|
132
|
+
@demo_bar = Gtk::Box.new(:vertical, 4)
|
|
133
|
+
@demo_bar.margin_start = 8
|
|
134
|
+
@demo_bar.margin_end = 6
|
|
135
|
+
@demo_bar.margin_bottom = 4
|
|
136
|
+
[list_row, btn_row].each { |w| @demo_bar.append(w) }
|
|
137
|
+
@demo_bar.visible = false
|
|
138
|
+
@demo_bar
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def show_demo_controls(paused:, rate:, demo: nil)
|
|
142
|
+
@demo_pause_btn.label = paused ? "Continue" : "Pause"
|
|
143
|
+
@demo_speed_lbl.label = rate
|
|
144
|
+
refresh_demo_list
|
|
145
|
+
i = @demo_names.index(demo)
|
|
146
|
+
if i && @demo_list.selected != i
|
|
147
|
+
@demo_list_updating = true
|
|
148
|
+
@demo_list.selected = i
|
|
149
|
+
@demo_list_updating = false
|
|
150
|
+
end
|
|
151
|
+
@demo_bar.visible = true
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# The demo list again if demos were recorded since
|
|
155
|
+
def refresh_demo_list
|
|
156
|
+
demos = DemoPlayer.demos
|
|
157
|
+
return if demos.keys == @demo_names
|
|
158
|
+
@demo_list_updating = true
|
|
159
|
+
@demo_names = demos.keys
|
|
160
|
+
@demo_list.model = Gtk::StringList.new(demos.values.map { |d| d[:title] })
|
|
161
|
+
@demo_list_updating = false
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def hide_demo_controls
|
|
165
|
+
@demo_bar.visible = false
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Returns the outermost widget to embed in the paned layout.
|
|
169
|
+
def widget
|
|
170
|
+
@box
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def active?
|
|
174
|
+
@active
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# First row currently displayed (should be the newest); used by tests.
|
|
178
|
+
def top_row
|
|
179
|
+
@list.first_child
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def set_active(v)
|
|
183
|
+
@active = v
|
|
184
|
+
@hint.hide if !v
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Re-read the newest-row highlight color from cnf and reload it live.
|
|
188
|
+
def refresh_css
|
|
189
|
+
@row_css.load(data: keylog_row_css)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def clear
|
|
193
|
+
@entries.clear
|
|
194
|
+
@rows.each { |r| @list.remove(r) }
|
|
195
|
+
@rows.clear
|
|
196
|
+
@last_mode = nil
|
|
197
|
+
@newest_row = nil
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# ── logging API, called from key_binding_tree.rb ──────────────────────────
|
|
201
|
+
|
|
202
|
+
# A key chord completed and an action is about to execute.
|
|
203
|
+
# trail_str is e.g. "[COMMAND] g g"; action is a Symbol, Proc or eval string.
|
|
204
|
+
def log_action(trail_str, action)
|
|
205
|
+
return unless @active
|
|
206
|
+
if action.class == String && (m = INSERT_TXT_RE.match(action))
|
|
207
|
+
log_insert_char(unquote(m[1]))
|
|
208
|
+
return
|
|
209
|
+
end
|
|
210
|
+
if action.class == String && (m = CHAR_ACTION_RE.match(action))
|
|
211
|
+
if m[1] == "edit.insert.char" || m[1] == "form.insert.char" # form_input.rb
|
|
212
|
+
log_insert_char(unquote(m[2]))
|
|
213
|
+
return
|
|
214
|
+
end
|
|
215
|
+
id, char = m[1], unquote(m[2])
|
|
216
|
+
end
|
|
217
|
+
mode_divider(trail_str)
|
|
218
|
+
drop_pending
|
|
219
|
+
desc = vma.actions[id || action]&.method_name.to_s
|
|
220
|
+
desc = desc.gsub("<char>", char) if char
|
|
221
|
+
name = action.class == Proc ? "(proc)" : action.to_s
|
|
222
|
+
desc = "" if desc == name
|
|
223
|
+
push(kind: :action, chord: fmt_chord(trail_str), action: action, desc: desc)
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# A multi-key sequence is in progress (matched a state that has children).
|
|
227
|
+
def log_pending(trail_str)
|
|
228
|
+
return unless @active
|
|
229
|
+
mode_divider(trail_str)
|
|
230
|
+
e = { kind: :pending, chord: fmt_chord(trail_str) }
|
|
231
|
+
if @entries.last && @entries.last[:kind] == :pending
|
|
232
|
+
@entries[-1] = e
|
|
233
|
+
update_last_row(e)
|
|
234
|
+
else
|
|
235
|
+
push(e)
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# A key of an easy jump label (easy_jump.rb, which reads them itself).
|
|
240
|
+
# label: the keys so far; state: :typing, :jumped (to 1-based line) or
|
|
241
|
+
# :nomatch. One row per label, updated as it is typed.
|
|
242
|
+
def log_jump_label(label, state, line = nil)
|
|
243
|
+
return unless @active
|
|
244
|
+
drop_pending
|
|
245
|
+
e = { kind: :jump, text: label.downcase, state: state, line: line }
|
|
246
|
+
last = @entries.last
|
|
247
|
+
if last && last[:kind] == :jump && last[:state] == :typing
|
|
248
|
+
@entries[-1] = e
|
|
249
|
+
update_last_row(e)
|
|
250
|
+
else
|
|
251
|
+
push(e)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# A key press that matched nothing in the binding tree.
|
|
256
|
+
def log_nomatch(c, trail_str)
|
|
257
|
+
return unless @active
|
|
258
|
+
drop_pending
|
|
259
|
+
chord = [trail_str, c].reject { |s| s.to_s.empty? }.join(" ")
|
|
260
|
+
push(kind: :nomatch, chord: fmt_chord(chord))
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
private
|
|
264
|
+
|
|
265
|
+
def log_insert_char(ch)
|
|
266
|
+
if @entries.last && @entries.last[:kind] == :insert
|
|
267
|
+
@entries.last[:text] << ch
|
|
268
|
+
update_last_row(@entries.last)
|
|
269
|
+
else
|
|
270
|
+
push(kind: :insert, text: ch.dup)
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# A pending row is superseded by the entry that completes or aborts it.
|
|
275
|
+
def drop_pending
|
|
276
|
+
return unless @entries.last && @entries.last[:kind] == :pending
|
|
277
|
+
@entries.pop
|
|
278
|
+
@list.remove(@rows.pop)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Insert a dim divider row whenever the mode badge changes between entries.
|
|
282
|
+
def mode_divider(trail_str)
|
|
283
|
+
mode = trail_str.to_s[/\A\[[^\]]+\]/]
|
|
284
|
+
return if mode.nil?
|
|
285
|
+
push(kind: :mode, text: mode) if @last_mode && mode != @last_mode
|
|
286
|
+
@last_mode = mode
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def push(e)
|
|
290
|
+
@entries << e
|
|
291
|
+
lbl = Gtk::Label.new
|
|
292
|
+
lbl.use_markup = true
|
|
293
|
+
lbl.xalign = 0.0
|
|
294
|
+
lbl.wrap = true
|
|
295
|
+
# Break inside long words too: an action like
|
|
296
|
+
# buf.jump(END_OF_LINE);buf.insert_txt("\n");... has no spaces, and its
|
|
297
|
+
# width would otherwise become the panel's minimum width
|
|
298
|
+
lbl.wrap_mode = :word_char
|
|
299
|
+
lbl.margin_start = 8
|
|
300
|
+
lbl.margin_end = 8
|
|
301
|
+
lbl.margin_top = 3
|
|
302
|
+
lbl.margin_bottom = 3
|
|
303
|
+
lbl.markup = markup_for(e)
|
|
304
|
+
row = Gtk::ListBoxRow.new
|
|
305
|
+
row.set_child(lbl)
|
|
306
|
+
row.style_context.add_provider(@row_css)
|
|
307
|
+
@list.prepend(row) # newest entry shown at top
|
|
308
|
+
@rows << row
|
|
309
|
+
highlight(row)
|
|
310
|
+
show_hint(e)
|
|
311
|
+
if @entries.size > MAX_ENTRIES
|
|
312
|
+
@entries.shift
|
|
313
|
+
@list.remove(@rows.shift) # oldest row sits at the bottom
|
|
314
|
+
end
|
|
315
|
+
scroll_to_top
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def update_last_row(e)
|
|
319
|
+
@rows.last.child.markup = markup_for(e)
|
|
320
|
+
show_hint(e)
|
|
321
|
+
scroll_to_top
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# The entry in the bubble next to the cursor, shorter: no mode badge (the
|
|
325
|
+
# mode divider rows aren't shown there)
|
|
326
|
+
def show_hint(e)
|
|
327
|
+
return if e[:kind] == :mode
|
|
328
|
+
chord = esc(e[:chord].to_s.sub(/\A\[[^\]]*\]\s*/, ""))
|
|
329
|
+
m = case e[:kind]
|
|
330
|
+
when :action
|
|
331
|
+
name = e[:action].class == Proc ? "(proc)" : e[:action].to_s
|
|
332
|
+
what = e[:desc].to_s.empty? ? name : e[:desc]
|
|
333
|
+
what = what[0, 45] + "…" if what.size > 46
|
|
334
|
+
"<b>#{chord}</b> <span alpha='80%'>#{esc(what)}</span>"
|
|
335
|
+
when :pending then "<b>#{chord}</b> …"
|
|
336
|
+
when :insert
|
|
337
|
+
t = e[:text]
|
|
338
|
+
t = "…" + t[-30..] if t.size > 31
|
|
339
|
+
"<span alpha='80%'>typed</span> <b>#{esc(t)}</b>"
|
|
340
|
+
when :nomatch then "<b>#{chord}</b> <span alpha='80%'>(no binding)</span>"
|
|
341
|
+
when :jump then "<span alpha='80%'>label</span> <b>#{esc(e[:text])}</b><span alpha='80%'>#{jump_result(e)}</span>"
|
|
342
|
+
end
|
|
343
|
+
@hint.show(m)
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
# Mark row as the newest entry, unmarking the previous one.
|
|
347
|
+
def highlight(row)
|
|
348
|
+
@newest_row&.remove_css_class("keylog-newest")
|
|
349
|
+
row.add_css_class("keylog-newest")
|
|
350
|
+
@newest_row = row
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
def markup_for(e)
|
|
354
|
+
case e[:kind]
|
|
355
|
+
when :action
|
|
356
|
+
name = e[:action].class == Proc ? "(proc)" : e[:action].to_s
|
|
357
|
+
s = "<span size='large' weight='bold'>#{esc(e[:chord])}</span>\n"
|
|
358
|
+
s << "<span foreground='#8fbef0' size='large'>#{esc(e[:desc])}</span>" unless e[:desc].empty?
|
|
359
|
+
s << "\n<span>#{esc(name)}</span>"
|
|
360
|
+
s
|
|
361
|
+
when :pending
|
|
362
|
+
"<span size='large' weight='bold' alpha='55%'>#{esc(e[:chord])} …</span>"
|
|
363
|
+
when :insert
|
|
364
|
+
"<span size='large'>typed: <b>#{esc(e[:text])}</b></span>"
|
|
365
|
+
when :mode
|
|
366
|
+
"<span size='small' alpha='50%'>— #{esc(e[:text])} —</span>"
|
|
367
|
+
when :nomatch
|
|
368
|
+
"<span size='large' alpha='45%'>#{esc(e[:chord])} (no binding)</span>"
|
|
369
|
+
when :jump
|
|
370
|
+
"<span size='large'>label: <b>#{esc(e[:text])}</b>#{jump_result(e)}</span>"
|
|
371
|
+
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
def jump_result(e)
|
|
376
|
+
case e[:state]
|
|
377
|
+
when :typing then " …"
|
|
378
|
+
when :jumped then " → line #{e[:line]}"
|
|
379
|
+
else " (no such label)"
|
|
380
|
+
end
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
# Render key-release notation "ctrl!" as "ctrl↑"
|
|
384
|
+
def fmt_chord(s)
|
|
385
|
+
s.to_s.gsub(/(\S+?)!/) { "#{$1}↑" }
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
def esc(s)
|
|
389
|
+
CGI.escapeHTML(s.to_s)
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
# Extract the character from the quoted arg of buf.insert_txt('x'),
|
|
393
|
+
# undoing the escaping done in match_key_conf.
|
|
394
|
+
def unquote(s)
|
|
395
|
+
s = s.to_s
|
|
396
|
+
s = s[1..-2] if s.size >= 2 && (s[0] == "'" || s[0] == '"') && s[-1] == s[0]
|
|
397
|
+
s.gsub("\\\\'", "'").gsub("\\\\\\\\", "\\\\")
|
|
398
|
+
end
|
|
399
|
+
|
|
400
|
+
def scroll_to_top
|
|
401
|
+
GLib::Idle.add do
|
|
402
|
+
adj = @sw.vadjustment
|
|
403
|
+
adj.value = adj.lower
|
|
404
|
+
false
|
|
405
|
+
end
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
end # module Vimamsa
|