vimamsa 0.1.26 → 0.1.27
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 +62 -16
- data/custom_example.rb +43 -13
- data/doc/TODO.md +461 -0
- data/doc/bundling_plan.md +569 -0
- data/doc/key_bindings_report_plan.md +168 -0
- data/doc/missing_vim_bindings.md +71 -0
- data/doc/modules_settings_plan.md +433 -0
- data/doc/refactor_dedup_plan.md +117 -0
- data/doc/unused_code_plan.md +120 -0
- data/doc/vim_compatibility_plan.md +296 -0
- data/doc/vimlike_vim_conflicts.md +254 -0
- data/doc/vm_snapshots_plan.md +146 -0
- data/exe/run_tests.rb +117 -3
- data/exe/vimamsa +24 -4
- data/fonts/OFL-Oxanium.txt +93 -0
- data/fonts/Oxanium[wght].ttf +0 -0
- data/icon.png +0 -0
- data/img/demo.gif +0 -0
- data/lang/hyperplaintext.lang +6 -0
- data/lib/vimamsa/ack.rb +11 -1
- data/lib/vimamsa/actions.rb +4 -1
- 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 +593 -82
- data/lib/vimamsa/buffer_changetext.rb +102 -42
- data/lib/vimamsa/buffer_cursor.rb +7 -0
- data/lib/vimamsa/buffer_list.rb +4 -0
- data/lib/vimamsa/buffer_manager.rb +4 -1
- data/lib/vimamsa/bundled_fonts.rb +32 -0
- data/lib/vimamsa/clipboard.rb +3 -0
- data/lib/vimamsa/conf.rb +59 -3
- data/lib/vimamsa/constants.rb +3 -0
- data/lib/vimamsa/crash_handler.rb +149 -0
- data/lib/vimamsa/debug.rb +4 -1
- data/lib/vimamsa/desktop_install.rb +96 -0
- data/lib/vimamsa/diff_buffer.rb +39 -10
- data/lib/vimamsa/easy_jump.rb +3 -0
- data/lib/vimamsa/editor.rb +263 -57
- data/lib/vimamsa/encrypt.rb +78 -29
- data/lib/vimamsa/file_finder.rb +4 -19
- data/lib/vimamsa/file_history.rb +3 -0
- data/lib/vimamsa/file_manager.rb +30 -15
- data/lib/vimamsa/fold.rb +226 -0
- data/lib/vimamsa/gui.rb +520 -106
- data/lib/vimamsa/gui_command_line.rb +208 -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 +59 -35
- data/lib/vimamsa/gui_func_panel.rb +67 -22
- data/lib/vimamsa/gui_image.rb +3 -0
- data/lib/vimamsa/gui_keylog_panel.rb +246 -0
- data/lib/vimamsa/gui_menu.rb +23 -11
- data/lib/vimamsa/gui_select_window.rb +19 -48
- data/lib/vimamsa/gui_settings.rb +78 -37
- data/lib/vimamsa/gui_sourceview.rb +273 -19
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +319 -90
- data/lib/vimamsa/gui_text.rb +63 -2
- data/lib/vimamsa/gui_theme.rb +606 -0
- data/lib/vimamsa/hook.rb +3 -0
- data/lib/vimamsa/hyper_plain_text.rb +3 -0
- data/lib/vimamsa/key_actions.rb +112 -13
- data/lib/vimamsa/key_binding_tree.rb +242 -215
- data/lib/vimamsa/key_bindings_notepad.rb +43 -0
- data/lib/vimamsa/key_bindings_report.rb +261 -0
- data/lib/vimamsa/key_bindings_vim.rb +354 -0
- data/lib/vimamsa/key_bindings_vimlike.rb +65 -9
- data/lib/vimamsa/langservp.rb +271 -54
- data/lib/vimamsa/macro.rb +3 -0
- data/lib/vimamsa/main.rb +14 -8
- data/lib/vimamsa/rbvma.rb +26 -1
- data/lib/vimamsa/search.rb +3 -0
- data/lib/vimamsa/search_replace.rb +11 -10
- data/lib/vimamsa/string_util.rb +120 -40
- data/lib/vimamsa/terminal.rb +3 -0
- data/lib/vimamsa/test_framework.rb +28 -2
- data/lib/vimamsa/tests.rb +3 -0
- data/lib/vimamsa/text_objects.rb +353 -0
- data/lib/vimamsa/text_transforms.rb +14 -0
- data/lib/vimamsa/util.rb +46 -7
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +0 -1
- 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/tts/tts.rb +119 -0
- data/modules/tts/tts_info.rb +3 -0
- data/run_e2e_vm.sh +28 -0
- data/run_tests_vm.sh +130 -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_steps.txt +59 -0
- data/scripts/demo/record_demo.rb +177 -0
- data/scripts/demo/shapes.rb +28 -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_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 +33 -3
- data/tests/test_bookmarks.rb +206 -0
- data/tests/test_bracket_match.rb +85 -0
- data/tests/test_bundling.rb +92 -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 +129 -0
- data/tests/test_copy_paste.rb +80 -0
- data/tests/test_crash_handler.rb +39 -0
- data/tests/test_custom_two_phase.rb +92 -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_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_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_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_jump_to_file.rb +41 -0
- data/tests/test_key_bindings.rb +208 -0
- data/tests/test_keylog_panel.rb +101 -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_notepad_bindings.rb +67 -0
- data/tests/test_popup_queue.rb +51 -0
- data/tests/test_random_edit.rb +109 -0
- data/tests/test_revert.rb +127 -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 +329 -0
- data/tests/test_tts.rb +68 -0
- data/tests/test_vim_bindings.rb +252 -0
- data/tests/test_vim_conflicts.rb +63 -0
- data/tests/test_window_layout.rb +219 -0
- data/vimamsa.gemspec +3 -1
- data/vm_guest_run.sh +109 -0
- metadata +112 -10
|
@@ -1,27 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
class FileTreePanel
|
|
2
|
-
COL_LABEL = 0
|
|
4
|
+
COL_LABEL = 0 # Pango markup
|
|
3
5
|
COL_BUF_ID = 1 # 0 = folder row (not selectable)
|
|
6
|
+
COL_CLOSE = 2 # close button markup; nil on folder rows
|
|
7
|
+
COL_MARK = 3 # mark char on mark rows; "" on the "Marks" header; nil otherwise
|
|
8
|
+
|
|
9
|
+
CLOSE_GLYPH = "×"
|
|
4
10
|
|
|
5
11
|
def initialize
|
|
6
|
-
@store = Gtk::TreeStore.new(String, Integer)
|
|
7
|
-
@tree =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
col = Gtk::TreeViewColumn.new("", renderer, text: COL_LABEL)
|
|
15
|
-
col.expand = true
|
|
16
|
-
@tree.append_column(col)
|
|
17
|
-
|
|
18
|
-
@tree.signal_connect("row-activated") do |tv, path, _col|
|
|
19
|
-
iter = @store.get_iter(path)
|
|
20
|
-
next if iter.nil?
|
|
12
|
+
@store = Gtk::TreeStore.new(String, Integer, String, String)
|
|
13
|
+
@tree, @sw = build_list_tree(@store, ellipsize: Pango::EllipsizeMode::START,
|
|
14
|
+
text_col: COL_LABEL, markup: true) do |iter|
|
|
15
|
+
mark = iter[COL_MARK]
|
|
16
|
+
if mark && !mark.empty?
|
|
17
|
+
vma.buf.jump_to_mark(mark)
|
|
18
|
+
next
|
|
19
|
+
end
|
|
21
20
|
buf_id = iter[COL_BUF_ID]
|
|
22
21
|
next if buf_id.nil? || buf_id == 0
|
|
22
|
+
next if @close_click # this click belonged to the close button
|
|
23
23
|
vma.buffers.set_current_buffer(buf_id)
|
|
24
24
|
end
|
|
25
|
+
@tree.level_indentation = 7
|
|
26
|
+
|
|
27
|
+
# Small close (x) button directly in front of each file name: a glyph cell
|
|
28
|
+
# packed first into the name column, so it follows the row indentation.
|
|
29
|
+
# Its hover/pressed tint is a Pango span background, so it covers only the
|
|
30
|
+
# button (a cell background would also fill the indentation).
|
|
31
|
+
@close_renderer = Gtk::CellRendererText.new
|
|
32
|
+
col = @tree.get_column(0)
|
|
33
|
+
col.pack_start(@close_renderer, false)
|
|
34
|
+
col.reorder(@close_renderer, 0)
|
|
35
|
+
col.add_attribute(@close_renderer, "markup", COL_CLOSE)
|
|
36
|
+
|
|
37
|
+
# Paths are ellipsized at the start (keep the file name visible); mark
|
|
38
|
+
# rows at the end, so the mark char and line number stay visible.
|
|
39
|
+
text_renderer = col.cells.find { |c| !c.equal?(@close_renderer) }
|
|
40
|
+
col.set_cell_data_func(text_renderer) do |_col, r, _model, iter|
|
|
41
|
+
r.ellipsize = iter[COL_MARK].nil? ? Pango::EllipsizeMode::START : Pango::EllipsizeMode::END
|
|
42
|
+
end
|
|
43
|
+
init_close_button_events
|
|
25
44
|
|
|
26
45
|
@context_menu = nil
|
|
27
46
|
rightclick = Gtk::GestureClick.new
|
|
@@ -38,17 +57,151 @@ class FileTreePanel
|
|
|
38
57
|
show_context_menu(x, y)
|
|
39
58
|
end
|
|
40
59
|
|
|
41
|
-
@sw = Gtk::ScrolledWindow.new
|
|
42
|
-
@sw.set_policy(:never, :automatic)
|
|
43
|
-
@sw.set_child(@tree)
|
|
44
60
|
@sw.set_size_request(180, -1)
|
|
45
61
|
@sw.vexpand = true
|
|
62
|
+
@sw.add_css_class("side-panel")
|
|
46
63
|
end
|
|
47
64
|
|
|
48
65
|
def widget
|
|
49
66
|
@sw
|
|
50
67
|
end
|
|
51
68
|
|
|
69
|
+
# { buf_id => label markup } for the file rows (tests / introspection).
|
|
70
|
+
def row_labels
|
|
71
|
+
file_rows.transform_values { |iter| iter[COL_LABEL] }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def file_rows
|
|
75
|
+
h = {}
|
|
76
|
+
@store.each do |_model, _path, iter|
|
|
77
|
+
next if iter[COL_BUF_ID] == 0
|
|
78
|
+
h[iter[COL_BUF_ID]] = iter
|
|
79
|
+
end
|
|
80
|
+
h
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Button-like feedback for the close icon: tinted on hover, darker while
|
|
84
|
+
# pressed; the file closes on release over the same button (dragging off
|
|
85
|
+
# cancels, like a real button).
|
|
86
|
+
def init_close_button_events
|
|
87
|
+
@close_hover = nil
|
|
88
|
+
@close_pressed = nil
|
|
89
|
+
|
|
90
|
+
click = Gtk::GestureClick.new
|
|
91
|
+
click.button = 1
|
|
92
|
+
# Capture phase + claim: the tree's own click handling (select/activate
|
|
93
|
+
# row) must not see presses on the close button.
|
|
94
|
+
click.propagation_phase = :capture
|
|
95
|
+
@tree.add_controller(click)
|
|
96
|
+
click.signal_connect("pressed") do |gesture, _n, x, y|
|
|
97
|
+
id = close_hit(x, y)
|
|
98
|
+
@close_click = !id.nil?
|
|
99
|
+
next unless id
|
|
100
|
+
gesture.set_state(:claimed)
|
|
101
|
+
close_press(id)
|
|
102
|
+
end
|
|
103
|
+
click.signal_connect("released") do |_g, _n, x, y|
|
|
104
|
+
close_release(close_hit(x, y))
|
|
105
|
+
end
|
|
106
|
+
click.signal_connect("stopped") { close_release(nil) if @close_pressed }
|
|
107
|
+
|
|
108
|
+
motion = Gtk::EventControllerMotion.new
|
|
109
|
+
@tree.add_controller(motion)
|
|
110
|
+
motion.signal_connect("motion") { |_c, x, y| set_close_hover(close_hit(x, y)) }
|
|
111
|
+
motion.signal_connect("leave") { set_close_hover(nil) }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# buf_id of the file row whose close button is at widget coords (x, y), else nil.
|
|
115
|
+
def close_hit(x, y)
|
|
116
|
+
bx, by = @tree.convert_widget_to_bin_window_coords(x.to_i, y.to_i)
|
|
117
|
+
path, col, = @tree.get_path_at_pos(bx, by)
|
|
118
|
+
return nil unless path && col
|
|
119
|
+
iter = @store.get_iter(path)
|
|
120
|
+
return nil unless iter && iter[COL_BUF_ID].to_i != 0
|
|
121
|
+
area = @tree.get_cell_area(path, col)
|
|
122
|
+
(bx >= area.x && bx < area.x + close_w) ? iter[COL_BUF_ID] : nil
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Width of the close button cell, px (its natural width: the glyph + padding).
|
|
126
|
+
def close_w
|
|
127
|
+
@close_renderer.markup = close_markup(nil)
|
|
128
|
+
@close_renderer.get_preferred_width(@tree)[1]
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Widget coords of the center of a file row's close button (tests).
|
|
132
|
+
def close_button_center(buf_id)
|
|
133
|
+
path = file_rows[buf_id]&.path
|
|
134
|
+
return nil unless path
|
|
135
|
+
area = @tree.get_cell_area(path, @tree.get_column(0))
|
|
136
|
+
@tree.convert_bin_window_to_widget_coords(area.x + close_w / 2, area.y + area.height / 2)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def close_press(buf_id)
|
|
140
|
+
@close_pressed = buf_id
|
|
141
|
+
update_close_bg
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Release over buf_id's close button (nil = elsewhere): closes the file only
|
|
145
|
+
# if it is the one that was pressed.
|
|
146
|
+
def close_release(buf_id)
|
|
147
|
+
pressed = @close_pressed
|
|
148
|
+
@close_pressed = nil
|
|
149
|
+
update_close_bg
|
|
150
|
+
# @close_click suppresses the row activation of this same click; clear it
|
|
151
|
+
# once the click's other handlers have run.
|
|
152
|
+
GLib::Idle.add { @close_click = false; false }
|
|
153
|
+
close_buffer_from_panel(pressed) if pressed && pressed == buf_id
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def set_close_hover(buf_id)
|
|
157
|
+
return if buf_id == @close_hover
|
|
158
|
+
@close_hover = buf_id
|
|
159
|
+
update_close_bg
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# :pressed, :hover or :normal
|
|
163
|
+
def close_state(buf_id)
|
|
164
|
+
if buf_id == @close_pressed
|
|
165
|
+
:pressed
|
|
166
|
+
elsif buf_id == @close_hover && @close_pressed.nil?
|
|
167
|
+
:hover
|
|
168
|
+
else
|
|
169
|
+
:normal
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def close_markup(buf_id)
|
|
174
|
+
case close_state(buf_id)
|
|
175
|
+
when :pressed
|
|
176
|
+
"<span background=\"#{panel_color(:file_panel_close_pressed_bg)}\" weight=\"bold\"> #{CLOSE_GLYPH} </span>"
|
|
177
|
+
when :hover
|
|
178
|
+
"<span background=\"#{panel_color(:file_panel_close_hover_bg)}\"> #{CLOSE_GLYPH} </span>"
|
|
179
|
+
else
|
|
180
|
+
"<span fgalpha=\"55%\"> #{CLOSE_GLYPH} </span>"
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def update_close_bg
|
|
185
|
+
file_rows.each do |id, iter|
|
|
186
|
+
m = close_markup(id)
|
|
187
|
+
iter[COL_CLOSE] = m if iter[COL_CLOSE] != m
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# Deferred: closing refreshes (clears) the store, which must not happen
|
|
192
|
+
# inside the tree's own row-activated emission. A non-current file is
|
|
193
|
+
# closed in the background so the current file stays in view.
|
|
194
|
+
def close_buffer_from_panel(buf_id)
|
|
195
|
+
GLib::Idle.add do
|
|
196
|
+
if vma.buf&.id == buf_id
|
|
197
|
+
vma.buffers.close_buffer(buf_id)
|
|
198
|
+
else
|
|
199
|
+
vma.buffers.close_other_buffer(buf_id)
|
|
200
|
+
end
|
|
201
|
+
false
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
52
205
|
def init_context_menu
|
|
53
206
|
act = Gio::SimpleAction.new("fp_close_buffer")
|
|
54
207
|
vma.gui.app.add_action(act)
|
|
@@ -67,8 +220,9 @@ class FileTreePanel
|
|
|
67
220
|
@context_menu.popup
|
|
68
221
|
end
|
|
69
222
|
|
|
70
|
-
|
|
71
|
-
|
|
223
|
+
# Buffers grouped by directory in the panel's display order:
|
|
224
|
+
# [[dirname, [{bname:, buf:}, ...]], ...], dirs and files sorted by name.
|
|
225
|
+
def grouped_buffers
|
|
72
226
|
bh = {}
|
|
73
227
|
vma.buffers.list.each do |b|
|
|
74
228
|
dname = b.fname ? File.dirname(b.fname) : "*"
|
|
@@ -76,19 +230,196 @@ class FileTreePanel
|
|
|
76
230
|
bh[dname] ||= []
|
|
77
231
|
bh[dname] << { bname: bname, buf: b }
|
|
78
232
|
end
|
|
233
|
+
bh.keys.sort.map { |dname| [dname, bh[dname].sort_by { |x| x[:bname] }] }
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# Switch to the file `delta` rows away (±1) from the current buffer in the
|
|
237
|
+
# panel's display order, wrapping at the ends.
|
|
238
|
+
def select_adjacent(delta)
|
|
239
|
+
ids = grouped_buffers.flat_map { |_, files| files.map { |x| x[:buf].id } }
|
|
240
|
+
return if ids.empty?
|
|
241
|
+
i = ids.index(vma.buf&.id)
|
|
242
|
+
target = i.nil? ? ids.first : ids[(i + delta) % ids.size]
|
|
243
|
+
vma.buffers.set_current_buffer(target)
|
|
244
|
+
end
|
|
79
245
|
|
|
80
|
-
|
|
246
|
+
# ── Easy jump: label file rows, switch to the file whose label is typed ──
|
|
247
|
+
# Same mechanism as EasyJump (easy_jump.rb): a whole-keyboard override
|
|
248
|
+
# captures label input; labels are rendered by prefixing the row text.
|
|
249
|
+
|
|
250
|
+
EJ_CHARS = "ASDFJKLGHQWERUIOPTYZXCVBNM".split("")
|
|
251
|
+
|
|
252
|
+
def easy_jump_active?
|
|
253
|
+
!@ej_targets.nil?
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# Single-char labels while they suffice, else all 2-char pairs — never mixed
|
|
257
|
+
# lengths, so no label is a prefix of another.
|
|
258
|
+
def ej_labels(n)
|
|
259
|
+
return EJ_CHARS.first(n) if n <= EJ_CHARS.size
|
|
260
|
+
EJ_CHARS.product(EJ_CHARS).map(&:join).first(n)
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def easy_jump_start
|
|
264
|
+
easy_jump_cancel if easy_jump_active?
|
|
265
|
+
file_rows = grouped_buffers.flat_map { |_, files| files }
|
|
266
|
+
return if file_rows.empty?
|
|
267
|
+
|
|
268
|
+
labels = ej_labels(file_rows.size)
|
|
269
|
+
@ej_targets = {}
|
|
270
|
+
file_rows.each_with_index { |bnfo, i| @ej_targets[labels[i]] = bnfo[:buf].id }
|
|
271
|
+
@ej_input = ""
|
|
272
|
+
|
|
273
|
+
# Prefix each file row's label in the store; row order matches
|
|
274
|
+
# grouped_buffers (refresh builds the store from it).
|
|
275
|
+
i = 0
|
|
276
|
+
@store.each do |_model, _path, iter|
|
|
277
|
+
next if iter[COL_BUF_ID] == 0
|
|
278
|
+
iter[COL_LABEL] = "#{ej_label_markup(labels[i])} #{iter[COL_LABEL]}"
|
|
279
|
+
i += 1
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
vma.kbd.set_keyhandling_override(self.method(:easy_jump_input_char))
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
def easy_jump_input_char(c, event_type)
|
|
286
|
+
return true if event_type != :key_press
|
|
287
|
+
# esc or any non-plain key (ctrl-x, alt-x, ...) aborts
|
|
288
|
+
if c.size != 1
|
|
289
|
+
easy_jump_cancel
|
|
290
|
+
return true
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
@ej_input << c.upcase
|
|
294
|
+
id = @ej_targets[@ej_input]
|
|
295
|
+
if id
|
|
296
|
+
target = id
|
|
297
|
+
easy_jump_cancel # remove override before switching; switch refreshes
|
|
298
|
+
vma.buffers.set_current_buffer(target)
|
|
299
|
+
elsif @ej_targets.keys.none? { |l| l.start_with?(@ej_input) }
|
|
300
|
+
easy_jump_cancel
|
|
301
|
+
end
|
|
302
|
+
return true
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def easy_jump_cancel
|
|
306
|
+
vma.kbd.remove_keyhandling_override
|
|
307
|
+
@ej_targets = nil
|
|
308
|
+
refresh # rebuild rows without label prefixes
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
def panel_color(name)
|
|
312
|
+
cnf.theme.cyberpunk_glow? ? cyber_color(name) : theme_color(name)
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# Current file: bold + brighter fg. Kept in the markup (not a cell-wide
|
|
316
|
+
# attribute) so an easy-jump label span keeps its own color on this row.
|
|
317
|
+
def current_markup(escaped)
|
|
318
|
+
"<span foreground=\"#{panel_color(:file_panel_current_fg)}\" weight=\"bold\">#{escaped}</span>"
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# Reddish bold label; a TreeView cell cannot do a CSS text-shadow, so the
|
|
322
|
+
# "glow" is a translucent background tint around the label.
|
|
323
|
+
def ej_label_markup(label)
|
|
324
|
+
"<span foreground=\"#{panel_color(:file_panel_ej_label_fg)}\" weight=\"bold\" " \
|
|
325
|
+
"background=\"#{panel_color(:file_panel_ej_label_glow)}\" bgalpha=\"30%\"> #{label} </span>"
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
# ── Marks of the current file (m <char>), shown above the files ──
|
|
329
|
+
|
|
330
|
+
MARK_TEXT_MAX = 40 # chars of the marked line shown after the line number
|
|
331
|
+
MARK_NEAR_MAX = 50 # how far to look for text when a mark is on an empty line
|
|
332
|
+
|
|
333
|
+
# { char => [lpos (0-based), text, dir] } of vma.buf's user marks, by char.
|
|
334
|
+
# text is the marked line's, or for an empty line the nearest non-empty
|
|
335
|
+
# line's, with dir :below / :above saying where it is (nil: the marked line).
|
|
336
|
+
def current_marks
|
|
337
|
+
b = vma.buf
|
|
338
|
+
return {} unless b
|
|
339
|
+
b.user_marks.to_h do |c, pos|
|
|
340
|
+
lpos = b.get_line_pos(pos)
|
|
341
|
+
[c, [lpos, *mark_text(b, lpos)]]
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# [text, dir] for the mark list; see current_marks. Ties go to the line
|
|
346
|
+
# below, which is usually what a mark before a paragraph is for.
|
|
347
|
+
def mark_text(b, lpos)
|
|
348
|
+
text = b.line(lpos).to_s.strip
|
|
349
|
+
return [text, nil] unless text.empty?
|
|
350
|
+
nlines = b.line_ends.size
|
|
351
|
+
(1..MARK_NEAR_MAX).each do |d|
|
|
352
|
+
[[lpos + d, :below], [lpos - d, :above]].each do |l, dir|
|
|
353
|
+
next if l < 0 or l >= nlines
|
|
354
|
+
t = b.line(l).to_s.strip
|
|
355
|
+
return [t, dir] unless t.empty?
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
["", nil]
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
def mark_label(c, lpos, text, dir = nil)
|
|
362
|
+
text = text[0, MARK_TEXT_MAX] + "…" if text.size > MARK_TEXT_MAX
|
|
363
|
+
arrow = { below: "↓ ", above: "↑ " }[dir].to_s
|
|
364
|
+
"<b>#{CGI.escapeHTML(c)}</b> #{lpos + 1}: #{arrow}#{CGI.escapeHTML(text)}"
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
# { char => label markup } for the mark rows (tests / introspection).
|
|
368
|
+
def mark_rows
|
|
369
|
+
h = {}
|
|
370
|
+
@store.each do |_m, _p, iter|
|
|
371
|
+
m = iter[COL_MARK]
|
|
372
|
+
h[m] = iter[COL_LABEL] if m && !m.empty?
|
|
373
|
+
end
|
|
374
|
+
h
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
# Rebuild only the marks section (first top-level row), leaving the file
|
|
378
|
+
# rows and the scroll position alone.
|
|
379
|
+
def refresh_marks
|
|
380
|
+
first = @store.iter_first
|
|
381
|
+
@store.remove(first) if first && first[COL_MARK] == ""
|
|
382
|
+
marks = current_marks
|
|
383
|
+
return if marks.empty?
|
|
384
|
+
head = @store.insert(nil, 0)
|
|
385
|
+
head[COL_LABEL] = CGI.escapeHTML("📌 Marks")
|
|
386
|
+
head[COL_BUF_ID] = 0
|
|
387
|
+
head[COL_MARK] = ""
|
|
388
|
+
marks.each do |c, (lpos, text, dir)|
|
|
389
|
+
it = @store.append(head)
|
|
390
|
+
it[COL_LABEL] = mark_label(c, lpos, text, dir)
|
|
391
|
+
it[COL_BUF_ID] = 0
|
|
392
|
+
it[COL_MARK] = c
|
|
393
|
+
end
|
|
394
|
+
@tree.expand_row(head.path, true)
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
def refresh
|
|
398
|
+
# A buffer-list change mid-pick must not leave a stale override installed
|
|
399
|
+
# or labels pointing at rows that no longer exist.
|
|
400
|
+
if easy_jump_active?
|
|
401
|
+
vma.kbd.remove_keyhandling_override
|
|
402
|
+
@ej_targets = nil
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
@store.clear
|
|
406
|
+
grouped_buffers.each do |dname, files|
|
|
81
407
|
dir_iter = @store.append(nil)
|
|
82
|
-
dir_iter[COL_LABEL] = "📂 #{tilde_path(dname)}"
|
|
408
|
+
dir_iter[COL_LABEL] = CGI.escapeHTML("📂 #{tilde_path(dname)}")
|
|
83
409
|
dir_iter[COL_BUF_ID] = 0
|
|
84
|
-
|
|
410
|
+
files.each do |bnfo|
|
|
85
411
|
active_mark = bnfo[:buf].is_active? ? "● " : " "
|
|
412
|
+
current = bnfo[:buf].equal?(vma.buf) # Buffer < String: == compares text
|
|
86
413
|
file_iter = @store.append(dir_iter)
|
|
87
|
-
|
|
414
|
+
label = CGI.escapeHTML("#{active_mark}#{bnfo[:bname]}")
|
|
415
|
+
file_iter[COL_LABEL] = current ? current_markup(label) : label
|
|
88
416
|
file_iter[COL_BUF_ID] = bnfo[:buf].id
|
|
417
|
+
file_iter[COL_CLOSE] = close_markup(bnfo[:buf].id)
|
|
89
418
|
end
|
|
90
419
|
end
|
|
91
420
|
|
|
92
421
|
@tree.expand_all
|
|
422
|
+
refresh_marks
|
|
93
423
|
end
|
|
94
424
|
end
|
|
425
|
+
end # module Vimamsa
|
|
@@ -1,20 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
# PopupFormGenerator.new().run
|
|
2
4
|
class PopupFormGenerator
|
|
5
|
+
# Modal popups are serialized: only one is visible at a time. Presenting two
|
|
6
|
+
# transient modal windows together (e.g. the session-restore dialog and a
|
|
7
|
+
# startup file's autosave dialog at startup) makes them grab input from each
|
|
8
|
+
# other and get stuck, so queue any popup requested while another is active
|
|
9
|
+
# and show it once the active one closes.
|
|
10
|
+
@@popup_active = nil
|
|
11
|
+
@@popup_queue = []
|
|
12
|
+
|
|
13
|
+
# Present the next queued popup, if any. Called when the active popup closes.
|
|
14
|
+
def self.advance_popup_queue
|
|
15
|
+
@@popup_active = nil
|
|
16
|
+
nxt = @@popup_queue.shift
|
|
17
|
+
nxt&.present_now
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Test/utility hook: forget any queued/active popups.
|
|
21
|
+
def self.reset_popup_queue
|
|
22
|
+
@@popup_active = nil
|
|
23
|
+
@@popup_queue = []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.popup_active? = !@@popup_active.nil?
|
|
27
|
+
def self.popup_queue_size = @@popup_queue.size
|
|
28
|
+
|
|
3
29
|
def submit()
|
|
4
30
|
for id, entry in @vals
|
|
5
31
|
@ret[id] = entry.text
|
|
6
32
|
end
|
|
7
33
|
if !@callback.nil?
|
|
8
|
-
@callback.call(@ret)
|
|
34
|
+
run_dialog_callback("form submit") { @callback.call(@ret) }
|
|
9
35
|
end
|
|
36
|
+
close
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Close this popup and present the next queued one, if any. All close paths
|
|
40
|
+
# (submit, cancel, escape, window close) route through here. GTK4 has no
|
|
41
|
+
# widget "destroy" signal to hook, so the queue is advanced explicitly.
|
|
42
|
+
def close
|
|
10
43
|
@window.destroy
|
|
44
|
+
PopupFormGenerator.advance_popup_queue if @@popup_active.equal?(self)
|
|
11
45
|
end
|
|
12
46
|
|
|
13
47
|
def initialize(params = nil)
|
|
14
48
|
@ret = {}
|
|
15
|
-
@window =
|
|
16
|
-
# @window.screen = main_window.screen
|
|
17
|
-
# @window.title = title
|
|
49
|
+
@window = make_modal_window()
|
|
18
50
|
# params = {}
|
|
19
51
|
# params["inputs"] = {}
|
|
20
52
|
# params["inputs"]["search"] = { :label => "Search", :type => :entry }
|
|
@@ -22,17 +54,16 @@ class PopupFormGenerator
|
|
|
22
54
|
# params["inputs"]["btn1"] = { :label => "Replace all", :type => :button }
|
|
23
55
|
# params[:callback] = proc { |x| puts "====="; puts x.inspect; puts "=====" }
|
|
24
56
|
|
|
25
|
-
|
|
26
57
|
@callback = params[:callback]
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@window.
|
|
58
|
+
# Window manager close (title-bar X): advance the queue too, then let GTK
|
|
59
|
+
# destroy the window (return false). Programmatic closes go through #close.
|
|
60
|
+
@window.signal_connect("close-request") do
|
|
61
|
+
PopupFormGenerator.advance_popup_queue if @@popup_active.equal?(self)
|
|
62
|
+
false
|
|
63
|
+
end
|
|
30
64
|
|
|
31
65
|
frame = Gtk::Frame.new()
|
|
32
|
-
frame.
|
|
33
|
-
frame.margin_top = 8
|
|
34
|
-
frame.margin_end = 8
|
|
35
|
-
frame.margin_start = 8
|
|
66
|
+
frame.margin = 8
|
|
36
67
|
|
|
37
68
|
@window.set_child(frame)
|
|
38
69
|
|
|
@@ -41,10 +72,7 @@ class PopupFormGenerator
|
|
|
41
72
|
# @callback = params["callback"]
|
|
42
73
|
|
|
43
74
|
vbox = Gtk::Box.new(:vertical, 8)
|
|
44
|
-
vbox.
|
|
45
|
-
vbox.margin_top = 8
|
|
46
|
-
vbox.margin_end = 8
|
|
47
|
-
vbox.margin_start = 8
|
|
75
|
+
vbox.margin = 8
|
|
48
76
|
|
|
49
77
|
frame.set_child(vbox)
|
|
50
78
|
|
|
@@ -79,20 +107,7 @@ class PopupFormGenerator
|
|
|
79
107
|
hbox.append(entry)
|
|
80
108
|
@vals[id] = entry
|
|
81
109
|
|
|
82
|
-
|
|
83
|
-
press.set_propagation_phase(Gtk::PropagationPhase::CAPTURE)
|
|
84
|
-
entry.add_controller(press)
|
|
85
|
-
press.signal_connect "key-pressed" do |gesture, keyval, keycode, y|
|
|
86
|
-
if keyval == Gdk::Keyval::KEY_Return
|
|
87
|
-
submit
|
|
88
|
-
true
|
|
89
|
-
elsif keyval == Gdk::Keyval::KEY_Escape
|
|
90
|
-
@window.destroy
|
|
91
|
-
true
|
|
92
|
-
else
|
|
93
|
-
false
|
|
94
|
-
end
|
|
95
|
-
end
|
|
110
|
+
on_submit_escape(entry, submit: method(:submit), escape: method(:close))
|
|
96
111
|
end
|
|
97
112
|
end # each
|
|
98
113
|
|
|
@@ -100,7 +115,7 @@ class PopupFormGenerator
|
|
|
100
115
|
|
|
101
116
|
cancel_button = Gtk::Button.new(:label => "Cancel")
|
|
102
117
|
cancel_button.signal_connect "clicked" do
|
|
103
|
-
|
|
118
|
+
close
|
|
104
119
|
end
|
|
105
120
|
hbox.append(cancel_button)
|
|
106
121
|
@cancel_button = cancel_button
|
|
@@ -108,11 +123,19 @@ class PopupFormGenerator
|
|
|
108
123
|
end
|
|
109
124
|
|
|
110
125
|
def run
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
# If another popup is already showing, queue this one; it is presented when
|
|
127
|
+
# the active popup closes (see advance_popup_queue).
|
|
128
|
+
if @@popup_active && !@@popup_active.instance_variable_get(:@window).destroyed?
|
|
129
|
+
@@popup_queue << self
|
|
130
|
+
return @window
|
|
115
131
|
end
|
|
132
|
+
present_now
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Actually show the window now and mark it as the active popup.
|
|
136
|
+
def present_now
|
|
137
|
+
@@popup_active = self
|
|
138
|
+
@window.present
|
|
116
139
|
if !@default_button.nil?
|
|
117
140
|
@default_button.grab_focus
|
|
118
141
|
end
|
|
@@ -120,3 +143,4 @@ class PopupFormGenerator
|
|
|
120
143
|
@window
|
|
121
144
|
end
|
|
122
145
|
end
|
|
146
|
+
end # module Vimamsa
|
|
@@ -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
|