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,143 +1,372 @@
|
|
|
1
|
-
# require "trie"
|
|
2
|
-
require "rambling-trie"
|
|
3
1
|
|
|
2
|
+
module Vimamsa
|
|
3
|
+
|
|
4
|
+
# Word-based completion candidates collected from open buffers.
|
|
5
|
+
# Words are stored per buffer (buffer id => {word => count}) so that a
|
|
6
|
+
# re-scan on save replaces that buffer's words and stale words drop out.
|
|
4
7
|
class Autocomplete
|
|
5
|
-
@@
|
|
8
|
+
@@buf_words = {} # buffer id => { word => count }
|
|
9
|
+
@@scan_version = {} # buffer id => edit_version at last scan
|
|
10
|
+
|
|
11
|
+
MAX_WORD_LENGTH = 100
|
|
12
|
+
MAX_SCAN_SIZE = 500_000 # don't rescan larger buffers on the fly
|
|
6
13
|
|
|
7
14
|
def self.init
|
|
8
15
|
vma.hook.register(:file_saved, self.method("update_index"))
|
|
9
16
|
end
|
|
10
17
|
|
|
11
18
|
def self.update_index(bu)
|
|
12
|
-
debug "
|
|
13
|
-
|
|
19
|
+
debug "Autocomplete.update_index", 2
|
|
20
|
+
scan_buffer(bu)
|
|
14
21
|
end
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
# Called from Buffer#set_content with the initial word list
|
|
24
|
+
def self.add_words(words, buf_id = nil)
|
|
25
|
+
counts = Hash.new(0)
|
|
26
|
+
for w in words
|
|
27
|
+
counts[w] += 1 if w.size < MAX_WORD_LENGTH
|
|
21
28
|
end
|
|
22
|
-
@@
|
|
29
|
+
@@buf_words[buf_id || :global] = counts
|
|
23
30
|
end
|
|
24
31
|
|
|
25
|
-
def self.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
def self.scan_buffer(bu)
|
|
33
|
+
counts = Hash.new(0)
|
|
34
|
+
bu.scan(/\b\w+\b/) { |w| counts[w] += 1 if w.size < MAX_WORD_LENGTH }
|
|
35
|
+
@@buf_words[bu.id] = counts
|
|
36
|
+
@@scan_version[bu.id] = bu.edit_version
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Re-scan the buffer being edited if it has changed since the last scan,
|
|
40
|
+
# so the popup also offers words typed since the last save.
|
|
41
|
+
def self.refresh_current(bu)
|
|
42
|
+
return if bu.nil? or bu.size >= MAX_SCAN_SIZE
|
|
43
|
+
return if @@scan_version[bu.id] == bu.edit_version
|
|
44
|
+
scan_buffer(bu)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.remove_buffer(buf_id)
|
|
48
|
+
@@buf_words.delete(buf_id)
|
|
49
|
+
@@scan_version.delete(buf_id)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Match quality tiers: case-sensitive prefix > case-insensitive prefix >
|
|
53
|
+
# substring > in-order subsequence. nil = no match.
|
|
54
|
+
def self.match_tier(word, prefix, prefix_down)
|
|
55
|
+
return 3 if word.start_with?(prefix)
|
|
56
|
+
wd = word.downcase
|
|
57
|
+
return 2 if wd.start_with?(prefix_down)
|
|
58
|
+
return 1 if wd.include?(prefix_down)
|
|
59
|
+
return 0 if subsequence?(prefix_down, wd)
|
|
60
|
+
return nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.subsequence?(needle, haystack)
|
|
64
|
+
i = -1
|
|
65
|
+
needle.each_char do |ch|
|
|
66
|
+
i = haystack.index(ch, i + 1)
|
|
67
|
+
return false if i.nil?
|
|
30
68
|
end
|
|
69
|
+
return true
|
|
31
70
|
end
|
|
32
71
|
|
|
33
|
-
|
|
34
|
-
|
|
72
|
+
# Ranked completion candidates for prefix, best match first.
|
|
73
|
+
def self.matching_words(prefix, max: nil)
|
|
74
|
+
return [] if prefix.nil? or prefix.empty?
|
|
75
|
+
max ||= cnf.autocomplete.max_items! || 50
|
|
76
|
+
pd = prefix.downcase
|
|
77
|
+
freq = Hash.new(0)
|
|
78
|
+
@@buf_words.each_value { |h| h.each { |w, c| freq[w] += c } }
|
|
79
|
+
scored = []
|
|
80
|
+
freq.each do |w, c|
|
|
81
|
+
next if w == prefix
|
|
82
|
+
tier = match_tier(w, prefix, pd)
|
|
83
|
+
next if tier.nil?
|
|
84
|
+
scored << [-tier, -[c, 99].min, w.size, w]
|
|
85
|
+
end
|
|
86
|
+
scored.sort!
|
|
87
|
+
return scored[0...max].map { |x| x[3] }
|
|
35
88
|
end
|
|
36
89
|
|
|
37
|
-
|
|
38
|
-
|
|
90
|
+
# Filter LSP completion items ({text:, ...}) against the currently typed
|
|
91
|
+
# prefix, keeping the server's order within each match tier.
|
|
92
|
+
def self.filter_lsp_items(items, prefix)
|
|
93
|
+
return [] if items.nil? or items.empty?
|
|
94
|
+
return items.dup if prefix.nil? or prefix.empty?
|
|
95
|
+
pd = prefix.downcase
|
|
96
|
+
scored = []
|
|
97
|
+
items.each_with_index do |it, i|
|
|
98
|
+
tier = match_tier(it[:text], prefix, pd)
|
|
99
|
+
next if tier.nil?
|
|
100
|
+
scored << [[-tier, i], it]
|
|
101
|
+
end
|
|
102
|
+
scored.sort_by! { |x| x[0] }
|
|
103
|
+
return scored.map { |x| x[1] }
|
|
39
104
|
end
|
|
40
105
|
end
|
|
41
106
|
|
|
42
107
|
class VSourceView < GtkSource::View
|
|
108
|
+
AUTOCP_ROW_HEIGHT = 26
|
|
109
|
+
|
|
110
|
+
def autocp_init
|
|
111
|
+
@autocp_active = false
|
|
112
|
+
@autocp_items = []
|
|
113
|
+
@autocp_selected = 0
|
|
114
|
+
@autocp_prefix = nil
|
|
115
|
+
@autocp_word_start = nil
|
|
116
|
+
@autocp_cursor_pos = nil
|
|
117
|
+
@autocp_gen = 0
|
|
118
|
+
@autocp_lsp_items = []
|
|
119
|
+
@autocp_idle_pending = false
|
|
120
|
+
@autocp_manual = false
|
|
121
|
+
@acwin = nil
|
|
122
|
+
@ac_list = nil
|
|
123
|
+
@ac_sw = nil
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Texts of the current candidate list (used by tests)
|
|
127
|
+
def autocp_texts
|
|
128
|
+
@autocp_items.map { |x| x[:text] }
|
|
129
|
+
end
|
|
130
|
+
|
|
43
131
|
def hide_completions
|
|
44
|
-
if @acwin
|
|
45
|
-
@acwin.hide
|
|
46
|
-
end
|
|
132
|
+
@acwin.popdown if @acwin and @acwin.visible?
|
|
47
133
|
@autocp_active = false
|
|
134
|
+
@autocp_manual = false
|
|
135
|
+
@autocp_items = []
|
|
136
|
+
@autocp_lsp_items = []
|
|
137
|
+
@autocp_prefix = nil
|
|
138
|
+
@autocp_word_start = nil
|
|
139
|
+
@autocp_cursor_pos = nil
|
|
140
|
+
@autocp_gen += 1 # invalidate pending LSP callbacks
|
|
48
141
|
end
|
|
49
142
|
|
|
50
143
|
def autocp_select
|
|
51
144
|
return if !@autocp_active
|
|
52
|
-
|
|
53
|
-
|
|
145
|
+
item = @autocp_items[@autocp_selected]
|
|
146
|
+
hide_completions
|
|
147
|
+
# dup: word-hash keys are frozen, insert_txt_at calls force_encoding
|
|
148
|
+
bufo.complete_current_word(item[:text].dup) if item
|
|
149
|
+
grab_focus
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def autocp_select_next
|
|
153
|
+
return if !@autocp_active
|
|
154
|
+
autocp_set_selected(@autocp_selected + 1) if @autocp_selected < @autocp_items.size - 1
|
|
54
155
|
end
|
|
55
156
|
|
|
56
157
|
def autocp_select_previous
|
|
57
|
-
return if
|
|
58
|
-
|
|
59
|
-
autocp_unhilight(@autocp_selected)
|
|
60
|
-
@autocp_selected -= 1
|
|
61
|
-
autocp_hilight(@autocp_selected)
|
|
158
|
+
return if !@autocp_active
|
|
159
|
+
autocp_set_selected(@autocp_selected - 1) if @autocp_selected > 0
|
|
62
160
|
end
|
|
63
161
|
|
|
64
|
-
def
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
162
|
+
def autocp_manual_trigger
|
|
163
|
+
return unless cnf.autocomplete.enabled?
|
|
164
|
+
@autocp_manual = true
|
|
165
|
+
autocp_refresh(request_lsp: true)
|
|
68
166
|
end
|
|
69
167
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
168
|
+
# Called from Buffer#insert_txt while in insert mode (covers both the key
|
|
169
|
+
# binding path and the Wayland IM insert-text path).
|
|
170
|
+
def autocp_on_insert(c)
|
|
171
|
+
return unless cnf.autocomplete.enabled?
|
|
172
|
+
if c.nil? or c.empty? or c[-1] !~ /\w/
|
|
173
|
+
hide_completions if @autocp_active
|
|
174
|
+
return
|
|
175
|
+
end
|
|
176
|
+
if @autocp_active or cnf.autocomplete.auto_trigger? != false
|
|
177
|
+
autocp_schedule_refresh
|
|
178
|
+
end
|
|
74
179
|
end
|
|
75
180
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
autocp_unhilight(@autocp_selected)
|
|
80
|
-
@autocp_selected += 1
|
|
81
|
-
autocp_hilight(@autocp_selected)
|
|
181
|
+
# Called from Buffer#delete while in insert mode (backspace etc.)
|
|
182
|
+
def autocp_on_delete
|
|
183
|
+
autocp_schedule_refresh if @autocp_active
|
|
82
184
|
end
|
|
83
185
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
186
|
+
# Called from Buffer#set_pos: dismiss if the cursor moved anywhere we
|
|
187
|
+
# don't expect (mouse click, arrows, jumps). One backspace between
|
|
188
|
+
# refreshes is tolerated; delete() calls set_pos before autocp_on_delete.
|
|
189
|
+
def autocp_check_pos(new_pos)
|
|
190
|
+
return if !@autocp_active or @autocp_cursor_pos.nil?
|
|
191
|
+
if new_pos != @autocp_cursor_pos and new_pos != @autocp_cursor_pos - 1
|
|
192
|
+
hide_completions
|
|
193
|
+
end
|
|
88
194
|
end
|
|
89
195
|
|
|
90
|
-
|
|
196
|
+
# Coalesce refreshes into one idle callback per batch of edits. Running as
|
|
197
|
+
# idle also guarantees handle_deltas has synced the GTK buffer before we
|
|
198
|
+
# compute popup coordinates.
|
|
199
|
+
def autocp_schedule_refresh
|
|
200
|
+
return if @autocp_idle_pending
|
|
201
|
+
@autocp_idle_pending = true
|
|
202
|
+
GLib::Idle.add do
|
|
203
|
+
@autocp_idle_pending = false
|
|
204
|
+
autocp_refresh
|
|
205
|
+
false
|
|
206
|
+
end
|
|
91
207
|
end
|
|
92
208
|
|
|
93
|
-
def
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
209
|
+
def autocp_refresh(request_lsp: false)
|
|
210
|
+
bu = @bufo
|
|
211
|
+
return if bu.nil?
|
|
212
|
+
p = bu.pos - 1
|
|
213
|
+
if !bu.is_legal_pos(p) or bu[p] !~ /\w/
|
|
214
|
+
hide_completions if @autocp_active
|
|
215
|
+
return
|
|
216
|
+
end
|
|
217
|
+
(prefix, range) = bu.get_word_in_pos(p, boundary: :word)
|
|
218
|
+
min_chars = cnf.autocomplete.min_chars! || 2
|
|
219
|
+
if prefix.nil? or prefix !~ /\A\w+\z/ or (!@autocp_manual and prefix.size < min_chars)
|
|
220
|
+
hide_completions if @autocp_active
|
|
221
|
+
return
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
if range.begin != @autocp_word_start
|
|
225
|
+
# Word start changed: LSP results for the old word are stale
|
|
226
|
+
@autocp_lsp_items = []
|
|
227
|
+
@autocp_gen += 1
|
|
228
|
+
request_lsp = true if @autocp_active or cnf.autocomplete.auto_trigger? != false
|
|
229
|
+
end
|
|
230
|
+
@autocp_word_start = range.begin
|
|
231
|
+
@autocp_prefix = prefix
|
|
232
|
+
@autocp_cursor_pos = bu.pos
|
|
233
|
+
|
|
234
|
+
autocp_request_lsp if request_lsp
|
|
235
|
+
Autocomplete.refresh_current(bu)
|
|
236
|
+
autocp_render
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Merge LSP items (server order within match tiers) with buffer words,
|
|
240
|
+
# dedupe by completion text, and show the popup.
|
|
241
|
+
def autocp_render
|
|
242
|
+
prefix = @autocp_prefix
|
|
243
|
+
return if prefix.nil?
|
|
244
|
+
max = cnf.autocomplete.max_items! || 50
|
|
245
|
+
items = []
|
|
246
|
+
seen = {}
|
|
247
|
+
Autocomplete.filter_lsp_items(@autocp_lsp_items, prefix).each do |it|
|
|
248
|
+
next if seen[it[:text]] or it[:text] == prefix
|
|
249
|
+
seen[it[:text]] = true
|
|
250
|
+
items << it
|
|
251
|
+
end
|
|
252
|
+
Autocomplete.matching_words(prefix, max: max).each do |w|
|
|
253
|
+
next if seen[w]
|
|
254
|
+
seen[w] = true
|
|
255
|
+
items << { text: w, kind: nil, detail: nil, source: :buffer }
|
|
256
|
+
end
|
|
257
|
+
items = items[0...max]
|
|
258
|
+
if items.empty?
|
|
259
|
+
hide_completions if @autocp_active
|
|
260
|
+
return
|
|
261
|
+
end
|
|
100
262
|
@autocp_active = true
|
|
101
|
-
@
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
263
|
+
@autocp_items = items
|
|
264
|
+
autocp_update_list(items)
|
|
265
|
+
(x, y) = pos_to_coord(@autocp_word_start)
|
|
266
|
+
@acwin.set_pointing_to(Gdk::Rectangle.new(x, y + 8, 10, 10))
|
|
267
|
+
@acwin.popup if !@acwin.visible?
|
|
268
|
+
autocp_set_selected(0)
|
|
269
|
+
grab_focus
|
|
270
|
+
end
|
|
106
271
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
272
|
+
# Request completions from the LSP server (async; the callback is
|
|
273
|
+
# marshaled to the GTK thread by LangSrv). Debounced per word start.
|
|
274
|
+
def autocp_request_lsp
|
|
275
|
+
return if cnf.autocomplete.lsp.enabled? == false
|
|
276
|
+
bu = @bufo
|
|
277
|
+
lsp = bu.lsp
|
|
278
|
+
return if lsp.nil? or !lsp.completion_supported or bu.fname.nil?
|
|
279
|
+
gen = @autocp_gen
|
|
280
|
+
debounce = ((cnf.autocomplete.lsp.debounce! || 0.15) * 1000).to_i
|
|
281
|
+
debounce = 1 if @autocp_manual
|
|
282
|
+
GLib::Timeout.add(debounce) do
|
|
283
|
+
if gen == @autocp_gen
|
|
284
|
+
lsp.request_completion(bu.fname, bu.lpos, bu.cpos) do |items|
|
|
285
|
+
# Discard if the word or popup state changed while waiting
|
|
286
|
+
if gen == @autocp_gen and !items.empty?
|
|
287
|
+
@autocp_lsp_items = items
|
|
288
|
+
autocp_render
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
false
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
private
|
|
297
|
+
|
|
298
|
+
def autocp_ensure_win
|
|
299
|
+
return @acwin if @acwin
|
|
300
|
+
win = Gtk::Popover.new
|
|
301
|
+
win.parent = self
|
|
120
302
|
win.has_arrow = false
|
|
121
|
-
win.set_pointing_to(rec)
|
|
122
303
|
win.autohide = false
|
|
123
|
-
win.
|
|
124
|
-
|
|
304
|
+
win.focusable = false
|
|
305
|
+
sw = Gtk::ScrolledWindow.new
|
|
306
|
+
sw.set_policy(:never, :automatic)
|
|
307
|
+
sw.propagate_natural_height = true
|
|
308
|
+
sw.propagate_natural_width = true
|
|
309
|
+
sw.max_content_height = (cnf.autocomplete.visible_items! || 10) * AUTOCP_ROW_HEIGHT
|
|
310
|
+
list = Gtk::ListBox.new
|
|
311
|
+
list.selection_mode = :browse
|
|
312
|
+
list.focusable = false
|
|
313
|
+
list.signal_connect("row-activated") do |_l, row|
|
|
314
|
+
@autocp_selected = row.index
|
|
315
|
+
autocp_select
|
|
316
|
+
end
|
|
317
|
+
sw.child = list
|
|
318
|
+
win.set_child(sw)
|
|
319
|
+
gui_remove_controllers(win) # don't let the popover steal key events
|
|
125
320
|
@acwin = win
|
|
321
|
+
@ac_sw = sw
|
|
322
|
+
@ac_list = list
|
|
323
|
+
return win
|
|
126
324
|
end
|
|
127
325
|
|
|
128
|
-
def
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
326
|
+
def autocp_update_list(items)
|
|
327
|
+
autocp_ensure_win
|
|
328
|
+
while (row = @ac_list.first_child)
|
|
329
|
+
@ac_list.remove(row)
|
|
330
|
+
end
|
|
331
|
+
show_kind = items.any? { |x| x[:kind] }
|
|
332
|
+
for it in items
|
|
333
|
+
hbox = Gtk::Box.new(:horizontal, 8)
|
|
334
|
+
if show_kind
|
|
335
|
+
kl = Gtk::Label.new(it[:kind].to_s)
|
|
336
|
+
kl.width_chars = 5
|
|
337
|
+
kl.xalign = 0
|
|
338
|
+
kl.add_css_class("dim-label")
|
|
339
|
+
hbox.append(kl)
|
|
340
|
+
end
|
|
341
|
+
tl = Gtk::Label.new(it[:text])
|
|
342
|
+
tl.xalign = 0
|
|
343
|
+
hbox.append(tl)
|
|
344
|
+
if it[:detail] and !it[:detail].empty?
|
|
345
|
+
dl = Gtk::Label.new(it[:detail])
|
|
346
|
+
dl.xalign = 0
|
|
347
|
+
dl.ellipsize = :end
|
|
348
|
+
dl.max_width_chars = 40
|
|
349
|
+
dl.add_css_class("dim-label")
|
|
350
|
+
hbox.append(dl)
|
|
351
|
+
end
|
|
352
|
+
@ac_list.append(hbox)
|
|
353
|
+
end
|
|
354
|
+
end
|
|
135
355
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
356
|
+
def autocp_set_selected(i)
|
|
357
|
+
@autocp_selected = i
|
|
358
|
+
row = @ac_list.get_row_at_index(i)
|
|
359
|
+
return if row.nil?
|
|
360
|
+
@ac_list.select_row(row)
|
|
361
|
+
# Keep the selection visible; allocation is valid only once mapped
|
|
362
|
+
GLib::Idle.add do
|
|
363
|
+
r = @ac_list.get_row_at_index(@autocp_selected)
|
|
364
|
+
if r and @ac_sw
|
|
365
|
+
a = r.allocation
|
|
366
|
+
@ac_sw.vadjustment.clamp_page(a.y, a.y + a.height)
|
|
367
|
+
end
|
|
368
|
+
false
|
|
369
|
+
end
|
|
142
370
|
end
|
|
143
371
|
end
|
|
372
|
+
end # module Vimamsa
|
data/lib/vimamsa/gui_text.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
module Gui
|
|
2
|
-
def self.hilight_range(bf, r, color:
|
|
4
|
+
def self.hilight_range(bf, r, color: theme_color(:highlight_default), weight: nil, tag: nil)
|
|
3
5
|
vbuf = bf.view.buffer
|
|
4
6
|
|
|
5
7
|
if tag.nil?
|
|
@@ -13,7 +15,65 @@ module Gui
|
|
|
13
15
|
vbuf.apply_tag(tag, itr, itr2)
|
|
14
16
|
end
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
# Briefly highlight buffer range `r`, then clear it after cnf.flash.duration.
|
|
19
|
+
# If a block is given it runs *after* the flash clears — used by delete so the
|
|
20
|
+
# range is shown before the text is removed. When flashing is inactive
|
|
21
|
+
# (disabled in config, running under --test, running a macro, no GUI view, or
|
|
22
|
+
# an empty/inverted range) the block runs immediately and no highlight is
|
|
23
|
+
# drawn, preserving synchronous behaviour. Macros must stay synchronous: the
|
|
24
|
+
# deferred timeout used for the flash reorders the delete relative to the rest
|
|
25
|
+
# of the macro and breaks playback.
|
|
26
|
+
def self.flash_range(bf, r, &after)
|
|
27
|
+
active = cnf.flash.enabled? && !ARGV.include?("--test") &&
|
|
28
|
+
!vma.macro&.running_macro &&
|
|
29
|
+
bf.view && r && r.begin <= r.last
|
|
30
|
+
unless active
|
|
31
|
+
after&.call
|
|
32
|
+
return
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
vbuf = bf.view.buffer
|
|
36
|
+
tag = vbuf.tag_table.lookup("vma_flash")
|
|
37
|
+
if tag.nil?
|
|
38
|
+
tag = vbuf.create_tag("vma_flash")
|
|
39
|
+
tag.background = cnf.match.highlight.color!
|
|
40
|
+
end
|
|
41
|
+
# An earlier flash's edit must land before this range is computed on.
|
|
42
|
+
flush_flash
|
|
43
|
+
lo = r.begin
|
|
44
|
+
hi = [r.last + 1, bf.size].min # +1: cover the last char inclusively
|
|
45
|
+
vbuf.apply_tag(tag, vbuf.get_iter_at(:offset => lo), vbuf.get_iter_at(:offset => hi))
|
|
46
|
+
|
|
47
|
+
finish = proc {
|
|
48
|
+
vbuf.remove_tag(tag, vbuf.get_iter_at(:offset => lo), vbuf.get_iter_at(:offset => hi))
|
|
49
|
+
after&.call
|
|
50
|
+
# `after` may have edited the buffer (e.g. delete-to-mark). The normal
|
|
51
|
+
# post-action refresh already ran when the key was pressed, so flush the
|
|
52
|
+
# deferred edit to the GTK view and redraw the cursor here.
|
|
53
|
+
bf.view.handle_deltas
|
|
54
|
+
bf.view.draw_cursor
|
|
55
|
+
}
|
|
56
|
+
src = GLib::Timeout.add((cnf.flash.duration! * 1000).to_i) do
|
|
57
|
+
@pending_flash = nil
|
|
58
|
+
finish.call
|
|
59
|
+
false
|
|
60
|
+
end
|
|
61
|
+
@pending_flash = [src, finish]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Finish a flash that is still showing now: clear it and run its deferred
|
|
65
|
+
# block (e.g. the delete). Called when the next key arrives, so that key's
|
|
66
|
+
# action sees the edit done — otherwise typing "d w j" within
|
|
67
|
+
# cnf.flash.duration moves first and the late delete snaps the cursor back.
|
|
68
|
+
def self.flush_flash
|
|
69
|
+
pf = @pending_flash
|
|
70
|
+
return if pf.nil?
|
|
71
|
+
@pending_flash = nil
|
|
72
|
+
GLib::Source.remove(pf[0])
|
|
73
|
+
pf[1].call
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def self.highlight_match(bf, str, color: theme_color(:highlight_default), weight: 650)
|
|
17
77
|
r = Regexp.new(Regexp.escape(str), Regexp::IGNORECASE)
|
|
18
78
|
tag = vma.gui.view.buffer.create_tag
|
|
19
79
|
tag.weight = weight
|
|
@@ -25,3 +85,4 @@ module Gui
|
|
|
25
85
|
}
|
|
26
86
|
end
|
|
27
87
|
end
|
|
88
|
+
end # module Vimamsa
|