vimamsa 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -89
  3. data/custom_example.rb +18 -6
  4. data/doc/TODO.md +327 -110
  5. data/doc/action_names_plan.md +442 -0
  6. data/doc/bundling_plan.md +2 -1
  7. data/doc/delta_syntax_plan.md +293 -0
  8. data/doc/demo_recording_plan.md +288 -0
  9. data/doc/design_goals.md +27 -0
  10. data/doc/intro_page_plan.md +266 -0
  11. data/doc/key_bindings_report_plan.md +45 -0
  12. data/doc/line_tree_plan.md +89 -0
  13. data/doc/missing_vim_bindings.md +34 -44
  14. data/doc/modules_settings_plan.md +1 -1
  15. data/doc/registries_plan.md +202 -0
  16. data/doc/startup_speed_plan.md +97 -0
  17. data/doc/treap_visualizer.html +585 -0
  18. data/doc/vim_compatibility_plan.md +186 -31
  19. data/doc/vimlike_vim_conflicts.md +236 -228
  20. data/doc/vm_snapshots_plan.md +4 -4
  21. data/doc/wysiwyg_plan.md +231 -0
  22. data/exe/run_tests.rb +8 -1
  23. data/exe/vimamsa +49 -6
  24. data/help/intro.txt +30 -0
  25. data/help/vim_intro.txt +31 -0
  26. data/img/demo.gif +0 -0
  27. data/img/demo.mp4 +0 -0
  28. data/lang/hyperplaintext.lang +1 -1
  29. data/lib/vimamsa/ack.rb +2 -0
  30. data/lib/vimamsa/actions.rb +381 -36
  31. data/lib/vimamsa/bookmarks.rb +8 -8
  32. data/lib/vimamsa/buffer.rb +83 -37
  33. data/lib/vimamsa/buffer_changetext.rb +58 -36
  34. data/lib/vimamsa/buffer_list.rb +2 -2
  35. data/lib/vimamsa/buffer_manager.rb +6 -6
  36. data/lib/vimamsa/cli_help.rb +75 -0
  37. data/lib/vimamsa/clipboard.rb +6 -3
  38. data/lib/vimamsa/conf.rb +9 -0
  39. data/lib/vimamsa/crash_handler.rb +2 -2
  40. data/lib/vimamsa/debug.rb +2 -2
  41. data/lib/vimamsa/demo_player.rb +458 -0
  42. data/lib/vimamsa/demo_recorder.rb +277 -0
  43. data/lib/vimamsa/diff_buffer.rb +1 -1
  44. data/lib/vimamsa/dot_repeat.rb +104 -0
  45. data/lib/vimamsa/easy_jump.rb +54 -3
  46. data/lib/vimamsa/editor.rb +89 -46
  47. data/lib/vimamsa/file_history.rb +1 -1
  48. data/lib/vimamsa/file_manager.rb +23 -23
  49. data/lib/vimamsa/form_input.rb +388 -0
  50. data/lib/vimamsa/gui.rb +83 -13
  51. data/lib/vimamsa/gui_command_line.rb +44 -5
  52. data/lib/vimamsa/gui_form_generator.rb +17 -6
  53. data/lib/vimamsa/gui_key_hint.rb +165 -0
  54. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  55. data/lib/vimamsa/gui_menu.rb +69 -50
  56. data/lib/vimamsa/gui_select_window.rb +77 -43
  57. data/lib/vimamsa/gui_settings.rb +9 -5
  58. data/lib/vimamsa/gui_sourceview.rb +15 -81
  59. data/lib/vimamsa/gui_theme.rb +11 -2
  60. data/lib/vimamsa/hook.rb +2 -0
  61. data/lib/vimamsa/intro_page.rb +368 -0
  62. data/lib/vimamsa/key_actions.rb +315 -225
  63. data/lib/vimamsa/key_binding_tree.rb +228 -61
  64. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  65. data/lib/vimamsa/key_bindings_report.rb +290 -67
  66. data/lib/vimamsa/key_bindings_vim.rb +47 -297
  67. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  68. data/lib/vimamsa/key_names.rb +80 -0
  69. data/lib/vimamsa/line_tree.rb +367 -0
  70. data/lib/vimamsa/macro.rb +20 -3
  71. data/lib/vimamsa/rbvma.rb +15 -0
  72. data/lib/vimamsa/registers.rb +125 -0
  73. data/lib/vimamsa/run_ruby.rb +64 -0
  74. data/lib/vimamsa/search_replace.rb +4 -4
  75. data/lib/vimamsa/string_util.rb +17 -3
  76. data/lib/vimamsa/tests.rb +8 -8
  77. data/lib/vimamsa/text_objects.rb +11 -54
  78. data/lib/vimamsa/text_transforms.rb +4 -0
  79. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  80. data/lib/vimamsa/user_dirs.rb +83 -0
  81. data/lib/vimamsa/version.rb +1 -1
  82. data/lib/vimamsa/vim_core.rb +355 -0
  83. data/lib/vimamsa/vim_operators.rb +365 -0
  84. data/modules/calculator/calculator.rb +5 -5
  85. data/modules/color_highlight/color_highlight.rb +3 -3
  86. data/modules/dictation/dictation.rb +32 -32
  87. data/modules/ollama/ollama.rb +5 -5
  88. data/modules/terminal/terminal.rb +5 -5
  89. data/modules/tts/tts.rb +10 -10
  90. data/run_e2e_vm.sh +3 -3
  91. data/run_tests_vm.rb +138 -0
  92. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  93. data/scripts/demo/demo_files_steps.txt +52 -0
  94. data/scripts/demo/demo_steps.txt +9 -1
  95. data/scripts/demo/notes.txt +6 -0
  96. data/scripts/demo/record_demo.rb +60 -81
  97. data/scripts/demo/report.rb +7 -0
  98. data/scripts/demo/shapes.rb +1 -0
  99. data/scripts/demo/square/shapes.rb +29 -0
  100. data/scripts/demo/square/steps.txt +185 -0
  101. data/scripts/lib/perf_startup.rb +138 -0
  102. data/scripts/lib/script_helpers.rb +53 -0
  103. data/scripts/perf_compare.rb +34 -0
  104. data/scripts/profile_startup.rb +72 -0
  105. data/tests/test_action_ids.rb +232 -0
  106. data/tests/test_auto_format.rb +2 -2
  107. data/tests/test_autocomplete.rb +1 -1
  108. data/tests/test_basic_editing.rb +18 -18
  109. data/tests/test_bookmarks.rb +6 -6
  110. data/tests/test_bracket_match.rb +3 -0
  111. data/tests/test_cli_help.rb +64 -0
  112. data/tests/test_color_highlight.rb +2 -2
  113. data/tests/test_command_line.rb +1 -1
  114. data/tests/test_context_menu_file.rb +18 -0
  115. data/tests/test_copy_paste.rb +33 -33
  116. data/tests/test_custom_two_phase.rb +1 -1
  117. data/tests/test_demo_player.rb +301 -0
  118. data/tests/test_demo_recorder.rb +202 -0
  119. data/tests/test_dictation.rb +16 -16
  120. data/tests/test_dot_repeat.rb +88 -0
  121. data/tests/test_easy_jump.rb +93 -0
  122. data/tests/test_extract_file_links.rb +3 -3
  123. data/tests/test_file_panel.rb +2 -2
  124. data/tests/test_flash.rb +1 -1
  125. data/tests/test_fold.rb +1 -1
  126. data/tests/test_form_input.rb +203 -0
  127. data/tests/test_func_panel.rb +2 -2
  128. data/tests/test_gtk_sync.rb +7 -7
  129. data/tests/test_intro_page.rb +437 -0
  130. data/tests/test_key_categories.rb +163 -0
  131. data/tests/test_keylog_panel.rb +163 -3
  132. data/tests/test_line_ends.rb +51 -0
  133. data/tests/test_line_tree.rb +86 -0
  134. data/tests/test_lsp_clangd.rb +2 -2
  135. data/tests/test_macro.rb +2 -2
  136. data/tests/test_module_interface.rb +9 -9
  137. data/tests/test_notepad_bindings.rb +5 -5
  138. data/tests/test_perf_startup.rb +28 -0
  139. data/tests/test_random_edit.rb +27 -27
  140. data/tests/test_registers.rb +122 -0
  141. data/tests/test_run_ruby.rb +77 -0
  142. data/tests/test_startup_file.rb +1 -1
  143. data/tests/test_text_objects.rb +1 -1
  144. data/tests/test_text_transforms.rb +12 -0
  145. data/tests/test_tmp_user_dir.rb +79 -0
  146. data/tests/test_tts.rb +10 -10
  147. data/tests/test_undo.rb +34 -34
  148. data/tests/test_user_dirs.rb +122 -0
  149. data/tests/test_vim_bindings.rb +107 -6
  150. data/tests/test_vim_conflicts.rb +41 -4
  151. data/tests/test_vim_operators.rb +116 -0
  152. data/tests/test_window_layout.rb +83 -0
  153. data/vimamsa.gemspec +1 -1
  154. data/vm_guest_run.sh +22 -2
  155. metadata +58 -3
  156. data/run_tests_vm.sh +0 -130
@@ -26,10 +26,15 @@ class PopupFormGenerator
26
26
  def self.popup_active? = !@@popup_active.nil?
27
27
  def self.popup_queue_size = @@popup_queue.size
28
28
 
29
+ # The form's keys go through the key bindings, in form mode (form_input.rb)
30
+ attr_reader :form
31
+
29
32
  def submit()
30
- for id, entry in @vals
31
- @ret[id] = entry.text
33
+ for id, field in @vals
34
+ @ret[id] = field.text
32
35
  end
36
+ # Back to the editor's mode before the callback, which may change it
37
+ @form.deactivate
33
38
  if !@callback.nil?
34
39
  run_dialog_callback("form submit") { @callback.call(@ret) }
35
40
  end
@@ -40,6 +45,7 @@ class PopupFormGenerator
40
45
  # (submit, cancel, escape, window close) route through here. GTK4 has no
41
46
  # widget "destroy" signal to hook, so the queue is advanced explicitly.
42
47
  def close
48
+ @form.deactivate
43
49
  @window.destroy
44
50
  PopupFormGenerator.advance_popup_queue if @@popup_active.equal?(self)
45
51
  end
@@ -55,9 +61,11 @@ class PopupFormGenerator
55
61
  # params[:callback] = proc { |x| puts "====="; puts x.inspect; puts "=====" }
56
62
 
57
63
  @callback = params[:callback]
64
+ @form = FormInput.new(@window, submit: method(:submit), cancel: method(:close))
58
65
  # Window manager close (title-bar X): advance the queue too, then let GTK
59
66
  # destroy the window (return false). Programmatic closes go through #close.
60
67
  @window.signal_connect("close-request") do
68
+ @form.deactivate
61
69
  PopupFormGenerator.advance_popup_queue if @@popup_active.equal?(self)
62
70
  false
63
71
  end
@@ -97,6 +105,7 @@ class PopupFormGenerator
97
105
  @ret[id] = "submit"
98
106
  submit
99
107
  end
108
+ @form.add_button(button)
100
109
  elsif elem[:type] == :entry
101
110
  label = Gtk::Label.new(elem[:label])
102
111
  entry = Gtk::Entry.new
@@ -105,9 +114,7 @@ class PopupFormGenerator
105
114
  end
106
115
  hbox.append(label)
107
116
  hbox.append(entry)
108
- @vals[id] = entry
109
-
110
- on_submit_escape(entry, submit: method(:submit), escape: method(:close))
117
+ @vals[id] = @form.add_field(entry)
111
118
  end
112
119
  end # each
113
120
 
@@ -118,6 +125,7 @@ class PopupFormGenerator
118
125
  close
119
126
  end
120
127
  hbox.append(cancel_button)
128
+ @form.add_button(cancel_button)
121
129
  @cancel_button = cancel_button
122
130
  return
123
131
  end
@@ -136,8 +144,11 @@ class PopupFormGenerator
136
144
  def present_now
137
145
  @@popup_active = self
138
146
  @window.present
147
+ @form.activate
139
148
  if !@default_button.nil?
140
- @default_button.grab_focus
149
+ @form.focus_item(@default_button)
150
+ else
151
+ @form.focus(0)
141
152
  end
142
153
  @window.set_focus_visible(true)
143
154
  @window
@@ -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
@@ -14,10 +14,20 @@ class KeyLogPanel
14
14
  # The highlighted Gtk::ListBoxRow of the newest entry
15
15
  attr_reader :newest_row
16
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
+
17
23
  # Insert-mode typing arrives as eval-string actions like buf.insert_txt('h');
18
24
  # matched here so consecutive chars can be coalesced into one "typed:" row.
19
25
  INSERT_TXT_RE = /\Abuf\.insert_txt\((.+)\)\z/
20
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
+
21
31
  def initialize
22
32
  @entries = []
23
33
  @rows = [] # Gtk::ListBoxRow per entry, parallel to @entries
@@ -25,6 +35,7 @@ class KeyLogPanel
25
35
  @active = false
26
36
  @last_mode = nil # last seen mode badge, e.g. "[COMMAND]"
27
37
  @newest_row = nil
38
+ @hint = KeyHint.new
28
39
 
29
40
  @list = Gtk::ListBox.new
30
41
  @list.selection_mode = :none
@@ -46,6 +57,12 @@ class KeyLogPanel
46
57
  clear_btn = Gtk::Button.new(label: "Clear")
47
58
  clear_btn.signal_connect("clicked") { clear }
48
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
+
49
66
  header = Gtk::Box.new(:horizontal, 6)
50
67
  header.margin_start = 8
51
68
  header.margin_end = 6
@@ -53,15 +70,101 @@ class KeyLogPanel
53
70
  header.margin_bottom = 4
54
71
  header.append(title)
55
72
  header.append(clear_btn)
73
+ header.append(@close_btn)
56
74
 
57
75
  # @box is the outermost widget: header on top, scrollable log below.
58
76
  @box = Gtk::Box.new(:vertical, 0)
59
77
  @box.set_size_request(320, -1)
60
78
  @box.add_css_class("side-panel")
61
79
  @box.append(header)
80
+ @box.append(demo_bar_init)
62
81
  @box.append(@sw)
63
82
  end
64
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
+
65
168
  # Returns the outermost widget to embed in the paned layout.
66
169
  def widget
67
170
  @box
@@ -78,6 +181,7 @@ class KeyLogPanel
78
181
 
79
182
  def set_active(v)
80
183
  @active = v
184
+ @hint.hide if !v
81
185
  end
82
186
 
83
187
  # Re-read the newest-row highlight color from cnf and reload it live.
@@ -103,9 +207,17 @@ class KeyLogPanel
103
207
  log_insert_char(unquote(m[1]))
104
208
  return
105
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
106
217
  mode_divider(trail_str)
107
218
  drop_pending
108
- desc = vma.actions[action]&.method_name.to_s
219
+ desc = vma.actions[id || action]&.method_name.to_s
220
+ desc = desc.gsub("<char>", char) if char
109
221
  name = action.class == Proc ? "(proc)" : action.to_s
110
222
  desc = "" if desc == name
111
223
  push(kind: :action, chord: fmt_chord(trail_str), action: action, desc: desc)
@@ -124,6 +236,22 @@ class KeyLogPanel
124
236
  end
125
237
  end
126
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
+
127
255
  # A key press that matched nothing in the binding tree.
128
256
  def log_nomatch(c, trail_str)
129
257
  return unless @active
@@ -179,6 +307,7 @@ class KeyLogPanel
179
307
  @list.prepend(row) # newest entry shown at top
180
308
  @rows << row
181
309
  highlight(row)
310
+ show_hint(e)
182
311
  if @entries.size > MAX_ENTRIES
183
312
  @entries.shift
184
313
  @list.remove(@rows.shift) # oldest row sits at the bottom
@@ -188,9 +317,32 @@ class KeyLogPanel
188
317
 
189
318
  def update_last_row(e)
190
319
  @rows.last.child.markup = markup_for(e)
320
+ show_hint(e)
191
321
  scroll_to_top
192
322
  end
193
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
+
194
346
  # Mark row as the newest entry, unmarking the previous one.
195
347
  def highlight(row)
196
348
  @newest_row&.remove_css_class("keylog-newest")
@@ -203,7 +355,7 @@ class KeyLogPanel
203
355
  when :action
204
356
  name = e[:action].class == Proc ? "(proc)" : e[:action].to_s
205
357
  s = "<span size='large' weight='bold'>#{esc(e[:chord])}</span>\n"
206
- s << "<span foreground='#4a90d9' size='large' alpha='60%'>#{esc(e[:desc])}</span>" unless e[:desc].empty?
358
+ s << "<span foreground='#8fbef0' size='large'>#{esc(e[:desc])}</span>" unless e[:desc].empty?
207
359
  s << "\n<span>#{esc(name)}</span>"
208
360
  s
209
361
  when :pending
@@ -214,7 +366,17 @@ class KeyLogPanel
214
366
  "<span size='small' alpha='50%'>— #{esc(e[:text])} —</span>"
215
367
  when :nomatch
216
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
217
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)"
218
380
  end
219
381
  end
220
382
 
@@ -22,71 +22,78 @@ module Vimamsa
22
22
 
23
23
  def add_menu_items()
24
24
  add_to_menu "File.Example", { :label => "<span foreground='#888888'>Action, [mode] key binding</span>", :action => nil }
25
- add_to_menu "File.Save", { :label => "Save", :action => :buf_save }
26
- add_to_menu "File.Save as", { :label => "Save As...", :action => :buf_save_as }
27
- add_to_menu "File.Open", { :label => "Open", :action => :open_file_dialog }
25
+ add_to_menu "File.Save", { :label => "Save", :action => "buf.save" }
26
+ add_to_menu "File.Save as", { :label => "Save As...", :action => "buf.save.as" }
27
+ add_to_menu "File.Open", { :label => "Open", :action => "file.open" }
28
28
 
29
- add_to_menu "File.New", { :label => "New file", :action => :buf_new }
30
- add_to_menu "File.Revert", { :label => "Reload file from disk", :action => :buf_revert }
31
- add_to_menu "File.List", { :label => "List open files", :action => :start_buf_manager }
32
- add_to_menu "File.Close", { :label => "Close file", :action => :close_current_buffer }
29
+ add_to_menu "File.New", { :label => "New file", :action => "buf.new" }
30
+ add_to_menu "File.Revert", { :label => "Reload file from disk", :action => "buf.revert" }
31
+ add_to_menu "File.List", { :label => "List open files", :action => "buf.manager" }
32
+ add_to_menu "File.Close", { :label => "Close file", :action => "buf.close" }
33
33
 
34
- add_to_menu "File.Restart", { :label => "Restart (reload config and files)", :action => :restart_editor }
35
- add_to_menu "File.Quit", { :label => "Quit", :action => :quit }
34
+ add_to_menu "File.Restart", { :label => "Restart (reload config and files)", :action => "app.restart" }
35
+ add_to_menu "File.Quit", { :label => "Quit", :action => "app.quit" }
36
36
 
37
- add_to_menu "Edit.Undo", { :label => "Undo edit", :action => :edit_undo }
38
- add_to_menu "Edit.Redo", { :label => "Redo edit", :action => :edit_redo }
39
- add_to_menu "Edit.SearchReplace", { :label => "Search and replace", :action => :gui_search_replace }
40
- add_to_menu "Edit.Find", { :label => "Find", :action => :find_in_buffer }
41
- add_to_menu "Edit.ToggleAutocomplete", { :label => "Toggle autocomplete", :action => :toggle_autocomplete }
37
+ add_to_menu "Edit.Undo", { :label => "Undo edit", :action => "undo.last" }
38
+ add_to_menu "Edit.Redo", { :label => "Redo edit", :action => "undo.redo" }
39
+ add_to_menu "Edit.SearchReplace", { :label => "Search and replace", :action => "search.replace" }
40
+ add_to_menu "Edit.Find", { :label => "Find", :action => "search.buf" }
41
+ add_to_menu "Edit.ToggleAutocomplete", { :label => "Toggle autocomplete", :action => "edit.complete.toggle" }
42
42
 
43
43
  # add_to_menu "Edit.StartCompletion", { :label => "StartCompletion", :action => :start_autocomplete }
44
44
  # add_to_menu "Edit.ShowCompletion", { :label => "ShowCompletion", :action => :show_autocomplete }
45
45
 
46
- add_to_menu "Settings.Preferences", { :label => "Preferences...", :action => :show_settings }
47
- add_to_menu "Settings.Customize", { :action => :edit_customrb }
48
- add_to_menu "Settings.ReloadCustom", { :action => :reload_customrb }
46
+ add_to_menu "Settings.Preferences", { :label => "Preferences...", :action => "app.settings" }
47
+ add_to_menu "Settings.Customize", { :action => "app.customrb.edit" }
48
+ add_to_menu "Settings.ReloadCustom", { :action => "app.customrb.reload" }
49
49
 
50
- add_to_menu "Actions.SearchForActions", { :label => "Search for Actions", :action => :search_actions }
50
+ add_to_menu "Actions.SearchForActions", { :label => "Search for Actions", :action => "search.actions" }
51
51
 
52
- add_to_menu "Actions.Grep", { :label => "Grep lines", :action => :invoke_grep_search }
52
+ add_to_menu "Actions.Grep", { :label => "Grep lines", :action => "grep.buf" }
53
53
 
54
- add_to_menu "Actions.FileHistoryFinder", { :label => "Search files in history", :action => :gui_file_history_finder }
54
+ add_to_menu "Actions.FileHistoryFinder", { :label => "Search files in history", :action => "file.history" }
55
55
 
56
- add_to_menu "Actions.experimental.Diff", { :label => "Show Diff of\nunsaved changes", :action => :diff_buffer }
57
- add_to_menu "Actions.experimental.GitDiff", { :label => "Show git diff", :action => :git_diff_buffer }
58
- add_to_menu "Actions.experimental.GitDiffW", { :label => "Show git diff -w (repo)", :action => :git_diff_w }
56
+ add_to_menu "Actions.experimental.Diff", { :label => "Show Diff of\nunsaved changes", :action => "buf.diff" }
57
+ add_to_menu "Actions.experimental.GitDiff", { :label => "Show git diff", :action => "buf.diff.git" }
58
+ add_to_menu "Actions.experimental.GitDiffW", { :label => "Show git diff -w (repo)", :action => "file.diff.repo" }
59
59
 
60
- add_to_menu "Actions.experimental.PrintBufferAccessList", { :label => "Print buffers by access time", :action => :print_buffer_access_list }
61
- add_to_menu "Actions.experimental.EnableDebug", { :label => "Enable debug", :action => :enable_debug }
62
- add_to_menu "Actions.experimental.DisableDebug", { :label => "Disable debug", :action => :disable_debug }
63
- add_to_menu "Actions.experimental.ShowImages", { :label => "Show images ⟦img:path⟧", :action => :show_images }
60
+ add_to_menu "Actions.experimental.PrintBufferAccessList", { :label => "Print buffers by access time", :action => "debug.buf.access" }
61
+ add_to_menu "Actions.experimental.EnableDebug", { :label => "Enable debug", :action => "debug.on" }
62
+ add_to_menu "Actions.experimental.DisableDebug", { :label => "Disable debug", :action => "debug.off" }
63
+ add_to_menu "Actions.experimental.ShowImages", { :label => "Show images ⟦img:path⟧", :action => "style.images" }
64
64
 
65
- add_to_menu "Actions.experimental.ShowImages", { :action => :experimental_eval }
65
+ add_to_menu "Actions.experimental.ShowImages", { :action => "debug.eval.sel" }
66
66
 
67
67
 
68
- add_to_menu "Actions.debug.dumpkbd", { :label => "Dump kbd state", :action => :kbd_dump_state }
69
- add_to_menu "Actions.debug.ToggleKbdPassthrough", { :label => "Toggle kbd event passthrough", :action => :toggle_kbd_passthrough }
70
-
71
- add_to_menu "View.BufferManager", { :label => "Show open files", :action => :start_buf_manager }
72
- add_to_menu "View.Bookmarks", { :label => "Show bookmarks", :action => :bookmark_list }
73
- add_to_menu "Edit.AddBookmark", { :label => "Add bookmark", :action => :bookmark_add }
74
- add_to_menu "View.SelectLanguage", { :label => "Set buffer language...", :action => :select_buffer_language }
75
- add_to_menu "View.TwoColumn", { :label => "Toggle two column mode", :action => :toggle_two_column }
76
- add_to_menu "View.FilePanel", { :label => "Toggle file panel", :action => :toggle_file_panel }
77
- add_to_menu "View.FuncPanel", { :label => "Toggle function panel (LSP)", :action => :toggle_func_panel }
78
- add_to_menu "View.KeyLog", { :label => "Toggle key log panel", :action => :toggle_keylog_panel }
79
- add_to_menu "View.MsgHistory", { :label => "Message history", :action => :show_message_history }
80
-
81
- add_to_menu "Actions.EncryptFile", { :label => "Encrypt file", :action => :encrypt_file }
82
- add_to_menu "Actions.LspRestart", { :label => "Restart LSP server", :action => :lsp_restart }
83
- add_to_menu "Help.KeyBindings", { :label => "Show key bindings", :action => :show_key_bindings }
84
- add_to_menu "Help.VimConflicts", { :label => "Vim keys that differ in vimlike", :action => :show_vim_binding_conflicts }
85
- add_to_menu "Help.InstallDemo", { :action => :install_demo_files }
86
-
87
- #TODO: :auto_indent_buffer
88
-
89
- # add_to_menu "Actions.Ack", { :label => "source code search (Ack)", :action => :ack_search }
68
+ add_to_menu "Actions.debug.dumpkbd", { :label => "Dump kbd state", :action => "debug.kbd" }
69
+ add_to_menu "Actions.debug.ToggleKbdPassthrough", { :label => "Toggle kbd event passthrough", :action => "mode.passthrough.toggle" }
70
+
71
+ add_to_menu "View.BufferManager", { :label => "Show open files", :action => "buf.manager" }
72
+ add_to_menu "View.Bookmarks", { :label => "Show bookmarks", :action => "mark.list" }
73
+ add_to_menu "Edit.AddBookmark", { :label => "Add bookmark", :action => "mark.add" }
74
+ add_to_menu "View.SelectLanguage", { :label => "Set buffer language...", :action => "buf.language" }
75
+ add_to_menu "View.TwoColumn", { :label => "Toggle two column mode", :action => "view.columns.toggle" }
76
+ add_to_menu "View.FilePanel", { :label => "Toggle file panel", :action => "panel.files.toggle" }
77
+ add_to_menu "View.FuncPanel", { :label => "Toggle function panel (LSP)", :action => "panel.funcs.toggle" }
78
+ add_to_menu "View.KeyLog", { :label => "Toggle key log panel", :action => "panel.keylog.toggle" }
79
+ add_to_menu "View.MsgHistory", { :label => "Message history", :action => "help.messages" }
80
+
81
+ add_to_menu "Actions.EncryptFile", { :label => "Encrypt file", :action => "buf.encrypt" }
82
+ add_to_menu "Actions.LspRestart", { :label => "Restart LSP server", :action => "lsp.restart" }
83
+ add_to_menu "Help.Intro", { :label => "Introduction", :action => "help.intro" }
84
+ add_to_menu "Help.KeyBindings", { :label => "Show key bindings", :action => "help.keys" }
85
+ add_to_menu "Help.VimIntro", { :label => "Vimamsa for Vim users", :action => "help.vim_intro" }
86
+ add_to_menu "Help.VimConflicts", { :label => "Vim keys that differ in vimlike", :action => "help.vim_conflicts" }
87
+ DemoPlayer.demos.each { |name, d|
88
+ add_to_menu "Help.Demos.#{name}", { :label => d[:title], :action => d[:action] }
89
+ }
90
+ add_to_menu "Help.Demos.Record", { :label => "Record demo (again: stop)", :action => "help.demo.record" }
91
+ add_to_menu "Help.Demos.PlayRecorded", { :label => "Play the last recorded demo", :action => "help.demo.recorded.last" }
92
+ add_to_menu "Help.InstallDemo", { :action => "app.demo" }
93
+
94
+ #TODO: "edit.indent.buf"
95
+
96
+ # add_to_menu "Actions.Ack", { :label => "source code search (Ack)", :action => "ack.search" }
90
97
 
91
98
  end
92
99
 
@@ -118,6 +125,18 @@ module Vimamsa
118
125
  return ""
119
126
  end
120
127
 
128
+ # "Help ▸ Show key bindings" for the menu item that runs action, or nil
129
+ def path_for(action, nfo = @nfo, path = [])
130
+ nfo.each_value { |x|
131
+ p = path + [x[:label].to_s]
132
+ return p.join(" ▸ ") if x[:action].to_s == action.to_s
133
+ if x[:items].is_a?(Hash) && (r = path_for(action, x[:items], p))
134
+ return r
135
+ end
136
+ }
137
+ nil
138
+ end
139
+
121
140
  # Add a menu item under the top-level "Modules" menu.
122
141
  # Creates the Modules menu the first time it is called.
123
142
  def add_module_action(action, label)