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,6 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
module Vimamsa
|
|
1
3
|
# class VSourceView < Gtk::TextView
|
|
2
4
|
class VSourceView < GtkSource::View
|
|
3
|
-
attr_accessor :bufo, :autocp_active
|
|
5
|
+
attr_accessor :bufo, :autocp_active
|
|
6
|
+
|
|
7
|
+
# Link / file under the last right-click. Class-wide: the app.ctx_* actions
|
|
8
|
+
# are registered once, by the first view, but serve the menus of all views.
|
|
9
|
+
@@context_link = nil
|
|
10
|
+
@@context_file = nil
|
|
4
11
|
|
|
5
12
|
# def initialize(title = nil,bufo=nil)
|
|
6
13
|
def initialize(title, bufo)
|
|
@@ -16,6 +23,9 @@ class VSourceView < GtkSource::View
|
|
|
16
23
|
self.highlight_current_line = true
|
|
17
24
|
|
|
18
25
|
@tt = nil
|
|
26
|
+
@applying_delta = false
|
|
27
|
+
@last_key_press_text = nil
|
|
28
|
+
autocp_init
|
|
19
29
|
|
|
20
30
|
# Mainly after page-up or page-down
|
|
21
31
|
|
|
@@ -52,11 +62,14 @@ class VSourceView < GtkSource::View
|
|
|
52
62
|
end
|
|
53
63
|
|
|
54
64
|
def set_content(str)
|
|
65
|
+
@applying_delta = true
|
|
55
66
|
if @bufo&.lang == "hyperplaintext"
|
|
56
67
|
self.buffer.set_text(mask_for_display(str))
|
|
57
68
|
else
|
|
58
69
|
self.buffer.set_text(str)
|
|
59
70
|
end
|
|
71
|
+
@applying_delta = false
|
|
72
|
+
$hook&.call(:view_content_set, self)
|
|
60
73
|
end
|
|
61
74
|
|
|
62
75
|
# Sync the GTK buffer to mask_for_display(@bufo.to_s).
|
|
@@ -77,10 +90,12 @@ class VSourceView < GtkSource::View
|
|
|
77
90
|
j = expected.length - 1
|
|
78
91
|
j -= 1 while j >= i && expected[j] == gtk_text[j]
|
|
79
92
|
|
|
93
|
+
@applying_delta = true
|
|
80
94
|
s_iter = buffer.get_iter_at(:offset => i)
|
|
81
95
|
e_iter = buffer.get_iter_at(:offset => j + 1)
|
|
82
96
|
buffer.delete(s_iter, e_iter)
|
|
83
97
|
buffer.insert(buffer.get_iter_at(:offset => i), expected[i..j])
|
|
98
|
+
@applying_delta = false
|
|
84
99
|
end
|
|
85
100
|
|
|
86
101
|
# Returns [word, word_start, word_end] if +pos+ (Ruby-buffer offset) is
|
|
@@ -99,10 +114,12 @@ class VSourceView < GtkSource::View
|
|
|
99
114
|
|
|
100
115
|
# Replace the masked (***) span with the real word from the Ruby buffer.
|
|
101
116
|
def unmask_gtk_region(word, word_start, word_end)
|
|
117
|
+
@applying_delta = true
|
|
102
118
|
s_iter = buffer.get_iter_at(:offset => word_start)
|
|
103
119
|
e_iter = buffer.get_iter_at(:offset => word_end)
|
|
104
120
|
buffer.delete(s_iter, e_iter)
|
|
105
121
|
buffer.insert(buffer.get_iter_at(:offset => word_start), word)
|
|
122
|
+
@applying_delta = false
|
|
106
123
|
end
|
|
107
124
|
|
|
108
125
|
# When in insert mode with cursor on a «word, expose the real text in the GTK
|
|
@@ -253,6 +270,13 @@ class VSourceView < GtkSource::View
|
|
|
253
270
|
self.add_controller(@cnt_drag)
|
|
254
271
|
@cnt_drag.signal_connect "drag-begin" do |gesture, x, y|
|
|
255
272
|
debug "drag-begin", 2
|
|
273
|
+
@drag_start_x = x
|
|
274
|
+
@drag_start_y = y
|
|
275
|
+
# Pressed inside the selection: drag-end moves it (see "pressed")
|
|
276
|
+
if @move_sel
|
|
277
|
+
set_cursor_from_name("grabbing")
|
|
278
|
+
next
|
|
279
|
+
end
|
|
256
280
|
i = coord_to_iter(x, y, true)
|
|
257
281
|
pp i
|
|
258
282
|
@range_start = i
|
|
@@ -262,6 +286,13 @@ class VSourceView < GtkSource::View
|
|
|
262
286
|
end
|
|
263
287
|
|
|
264
288
|
@cnt_drag.signal_connect "drag-update" do |gesture, offset_x, offset_y|
|
|
289
|
+
if @move_sel
|
|
290
|
+
t = drop_pos(@drag_start_x + offset_x, @drag_start_y + offset_y)
|
|
291
|
+
# Dropping inside (or right after) the selection would not move it
|
|
292
|
+
no_op = t.nil? || (t >= @move_sel.begin && t <= @move_sel.end + 1)
|
|
293
|
+
show_drop_marker(no_op ? nil : t)
|
|
294
|
+
next
|
|
295
|
+
end
|
|
265
296
|
next unless @range_start
|
|
266
297
|
cur_x = @drag_start_x + offset_x
|
|
267
298
|
cur_y = @drag_start_y + offset_y
|
|
@@ -276,6 +307,25 @@ class VSourceView < GtkSource::View
|
|
|
276
307
|
|
|
277
308
|
@cnt_drag.signal_connect "drag-end" do |gesture, offsetx, offsety|
|
|
278
309
|
debug "drag-end", 2
|
|
310
|
+
if @move_sel
|
|
311
|
+
r = @move_sel
|
|
312
|
+
@move_sel = nil
|
|
313
|
+
set_cursor_from_name("text")
|
|
314
|
+
show_drop_marker(nil)
|
|
315
|
+
if offsetx.abs < 5 and offsety.abs < 5
|
|
316
|
+
# Just a click inside the selection: clear it like any other click
|
|
317
|
+
@bufo.end_visual_mode
|
|
318
|
+
i = coord_to_iter(@drag_start_x, @drag_start_y, true)
|
|
319
|
+
@bufo.set_pos(i) if !i.nil?
|
|
320
|
+
else
|
|
321
|
+
target = drop_pos(@drag_start_x + offsetx, @drag_start_y + offsety)
|
|
322
|
+
# Dropping ends the selection, whether or not the text moved
|
|
323
|
+
@bufo.end_visual_mode || @bufo.end_selection
|
|
324
|
+
@bufo.move_text(r, target)
|
|
325
|
+
end
|
|
326
|
+
handle_deltas
|
|
327
|
+
next
|
|
328
|
+
end
|
|
279
329
|
if offsetx.abs < 5 and offsety.abs < 5
|
|
280
330
|
debug "Not enough drag", 2
|
|
281
331
|
buf.end_selection
|
|
@@ -312,15 +362,25 @@ class VSourceView < GtkSource::View
|
|
|
312
362
|
debug "SourceView, GestureClick released x=#{x} y=#{y}"
|
|
313
363
|
vma.gui.instance_variable_set(:@kbd_passthrough, false)
|
|
314
364
|
|
|
315
|
-
if buf.visual_mode?
|
|
316
|
-
buf.end_visual_mode
|
|
317
|
-
end
|
|
318
|
-
|
|
319
365
|
xloc = (x - gutter_width).to_i
|
|
320
366
|
yloc = (y + visible_rect.y).to_i
|
|
321
367
|
debug "xloc=#{xloc} yloc=#{yloc}"
|
|
322
368
|
|
|
323
369
|
i = coord_to_iter(xloc, yloc)
|
|
370
|
+
|
|
371
|
+
# Pressing inside the selection grabs it for a drag-and-drop move
|
|
372
|
+
# (cnf.mouse.drag_selection). The selection stays until drag-end.
|
|
373
|
+
@move_sel = nil
|
|
374
|
+
if cnf.mouse.drag_selection? and n_press == 1 and !i.nil? and
|
|
375
|
+
vma.gui.current_view == self and @bufo.visual_mode? and
|
|
376
|
+
@bufo.get_visual_mode_range.include?(i)
|
|
377
|
+
@move_sel = @bufo.get_visual_mode_range
|
|
378
|
+
next true
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
if buf.visual_mode?
|
|
382
|
+
buf.end_visual_mode
|
|
383
|
+
end
|
|
324
384
|
# @range_start = i
|
|
325
385
|
|
|
326
386
|
# This needs to happen after xloc calculation, otherwise xloc gets a wrong value (around 200 bigger)
|
|
@@ -331,8 +391,14 @@ class VSourceView < GtkSource::View
|
|
|
331
391
|
@bufo.set_pos(i) if !i.nil?
|
|
332
392
|
if n_press == 2
|
|
333
393
|
#TODO: refactor to have one function for all line actions
|
|
334
|
-
|
|
335
|
-
|
|
394
|
+
# Same as Enter (Buffer#handle_line_action): the buffer's own line
|
|
395
|
+
# handler first. Ack's select_line takes the line number, so it is
|
|
396
|
+
# only reachable that way.
|
|
397
|
+
m = @bufo.module
|
|
398
|
+
if [Proc, Method].include?(@bufo.line_action_handler.class)
|
|
399
|
+
@bufo.line_action_handler.call(@bufo.lpos)
|
|
400
|
+
elsif m&.respond_to?(:select_line) && m.method(:select_line).arity == 0
|
|
401
|
+
m.select_line
|
|
336
402
|
else
|
|
337
403
|
@bufo.cur_nonwhitespace_word_action()
|
|
338
404
|
end
|
|
@@ -342,6 +408,7 @@ class VSourceView < GtkSource::View
|
|
|
342
408
|
|
|
343
409
|
click.signal_connect "released" do |gesture, n_press, x, y, z|
|
|
344
410
|
debug "SourceView, GestureClick released x=#{x} y=#{y} button=#{gesture.button}"
|
|
411
|
+
next true if @move_sel # drag-end handles it
|
|
345
412
|
|
|
346
413
|
xloc = (x - gutter_width).to_i
|
|
347
414
|
yloc = (y + visible_rect.y).to_i
|
|
@@ -362,6 +429,93 @@ class VSourceView < GtkSource::View
|
|
|
362
429
|
# @range_start = nil
|
|
363
430
|
true
|
|
364
431
|
end
|
|
432
|
+
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
# Must be called after set_buffer(buf) so the signal connects to the live buffer,
|
|
436
|
+
# not the temporary internal one created by super().
|
|
437
|
+
def register_buffer_signals
|
|
438
|
+
# Catch Wayland IM text commits (e.g. AltGr+q → ä).
|
|
439
|
+
# On Wayland the compositor feeds composed characters directly into the
|
|
440
|
+
# GtkTextBuffer via the text-input protocol, bypassing key events entirely.
|
|
441
|
+
# Our key handler never sees a key_press for these characters, so they are
|
|
442
|
+
# routed into the key binding tree here instead — what a character does is
|
|
443
|
+
# then up to the bindings ("I <char>" inserts, "C r <char>" replaces), not
|
|
444
|
+
# to this handler.
|
|
445
|
+
buffer.signal_connect("insert-text") do |_buf, _iter, text, _len|
|
|
446
|
+
unless @applying_delta || @bufo.nil?
|
|
447
|
+
# Cancel the insertion before it happens: the Ruby buffer is the source
|
|
448
|
+
# of truth, and letting the text land here first would put it on screen
|
|
449
|
+
# in the wrong place (or in the wrong mode) until a delete took it back
|
|
450
|
+
# out. Stopping the emission keeps the default handler from running, so
|
|
451
|
+
# nothing is ever inserted and nothing has to be undone.
|
|
452
|
+
_buf.signal_emit_stop("insert-text")
|
|
453
|
+
# A printable key arrives twice: as a key event AND as this IM commit.
|
|
454
|
+
# The key event already went to the key binding tree, so only a commit
|
|
455
|
+
# with no matching key press (AltGr, dead keys, compose) still needs to
|
|
456
|
+
# be fed in. Consume the record either way — the next keystroke, even a
|
|
457
|
+
# repeat of the same character, gets its own.
|
|
458
|
+
im_keys = (@last_key_press_text == text) ? nil : text
|
|
459
|
+
@last_key_press_text = nil
|
|
460
|
+
# The binding that handles the character ("I <char>", "C r <char>", ...)
|
|
461
|
+
# puts it in through the normal delta path.
|
|
462
|
+
dispatch_im_text_as_keys(im_keys) if im_keys
|
|
463
|
+
end
|
|
464
|
+
false
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
# Hand IM-committed text to the key binding tree as if it had arrived as key
|
|
469
|
+
# presses. Deferred to an idle because we are inside the "insert-text"
|
|
470
|
+
# emission, whose emitter still holds iterators into the buffer that the
|
|
471
|
+
# action is free to mutate. Whatever the action queued is flushed afterwards,
|
|
472
|
+
# the same way handle_key_event flushes after a real key press.
|
|
473
|
+
def dispatch_im_text_as_keys(text)
|
|
474
|
+
GLib::Idle.add(proc {
|
|
475
|
+
text.each_char { |c| vma.kbd.match_key_conf(c, nil, :key_press) }
|
|
476
|
+
handle_deltas
|
|
477
|
+
false
|
|
478
|
+
})
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
# Insertion point (char boundary nearest to widget coords x, y) for dropping
|
|
482
|
+
# dragged text: past the middle of a char means after it.
|
|
483
|
+
def drop_pos(x, y)
|
|
484
|
+
bx = (x - gutter_width).to_i
|
|
485
|
+
by = (y + visible_rect.y).to_i
|
|
486
|
+
iter, trailing = get_iter_at_position(bx, by)
|
|
487
|
+
if iter.nil? # Not over text (e.g. right of a line's end): end of that line
|
|
488
|
+
ls = coord_to_iter(x, y, true)
|
|
489
|
+
return nil if ls.nil?
|
|
490
|
+
return bx > 0 ? (@bufo.index("\n", ls) || ls) : ls
|
|
491
|
+
end
|
|
492
|
+
# Not past a line's "\n": that would drop onto the start of the next line
|
|
493
|
+
return iter.offset if @bufo[iter.offset] == "\n"
|
|
494
|
+
return iter.offset + trailing.to_i
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
# Thin bar showing where dragged text would land; pos nil hides it.
|
|
498
|
+
attr_reader :drop_marker_pos
|
|
499
|
+
def show_drop_marker(pos)
|
|
500
|
+
@drop_marker_pos = pos
|
|
501
|
+
if pos.nil?
|
|
502
|
+
@drop_marker.visible = false if @drop_marker
|
|
503
|
+
return
|
|
504
|
+
end
|
|
505
|
+
rect = get_iter_location(buffer.get_iter_at(:offset => pos))
|
|
506
|
+
if @drop_marker.nil?
|
|
507
|
+
@drop_marker = Gtk::Box.new(:horizontal, 0)
|
|
508
|
+
@drop_marker.can_target = false # never steal the pointer from the view
|
|
509
|
+
prov = Gtk::CssProvider.new
|
|
510
|
+
bg = $confh[:mode][:command][:cursor][:background] rescue nil
|
|
511
|
+
prov.load(data: "box { background-color: #{bg || "#05c5a0"}; }")
|
|
512
|
+
@drop_marker.style_context.add_provider(prov, Gtk::StyleProvider::PRIORITY_APPLICATION)
|
|
513
|
+
add_overlay(@drop_marker, rect.x, rect.y)
|
|
514
|
+
else
|
|
515
|
+
move_overlay(@drop_marker, rect.x, rect.y)
|
|
516
|
+
end
|
|
517
|
+
@drop_marker.set_size_request(2, rect.height)
|
|
518
|
+
@drop_marker.visible = true
|
|
365
519
|
end
|
|
366
520
|
|
|
367
521
|
def coord_to_iter(xloc, yloc, transform_coord = false)
|
|
@@ -403,6 +557,30 @@ class VSourceView < GtkSource::View
|
|
|
403
557
|
}
|
|
404
558
|
end
|
|
405
559
|
|
|
560
|
+
# Buffer offset of the line at the top of the visible area
|
|
561
|
+
def top_visible_pos
|
|
562
|
+
r = get_line_at_y(visible_rect.y)
|
|
563
|
+
return nil if r.nil? || r[0].nil?
|
|
564
|
+
r[0].offset
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
# Number of (logical) lines that fit in the visible area
|
|
568
|
+
def visible_line_count
|
|
569
|
+
vr = visible_rect
|
|
570
|
+
a = get_line_at_y(vr.y)
|
|
571
|
+
b = get_line_at_y(vr.y + vr.height - 1)
|
|
572
|
+
return nil if a.nil? || b.nil? || a[0].nil? || b[0].nil?
|
|
573
|
+
b[0].line - a[0].line
|
|
574
|
+
end
|
|
575
|
+
|
|
576
|
+
# Scroll so that the line containing pos is at the top of the view
|
|
577
|
+
def scroll_to_top_pos(pos)
|
|
578
|
+
itr = buffer.get_iter_at(:offset => pos)
|
|
579
|
+
@top_mark ||= buffer.create_mark("top", itr, true)
|
|
580
|
+
buffer.move_mark(@top_mark, itr)
|
|
581
|
+
scroll_to_mark(@top_mark, 0.0, true, 0.0, 0.0)
|
|
582
|
+
end
|
|
583
|
+
|
|
406
584
|
def set_cursor_to_top
|
|
407
585
|
debug "set_cursor_to_top", 2
|
|
408
586
|
bc = window_to_buffer_coords(Gtk::TextWindowType::WIDGET, gutter_width + 2, 60)
|
|
@@ -461,6 +639,13 @@ class VSourceView < GtkSource::View
|
|
|
461
639
|
keyval_trans[Gdk::Keyval::KEY_Tab] = "tab"
|
|
462
640
|
keyval_trans[Gdk::Keyval::KEY_ISO_Left_Tab] = "tab"
|
|
463
641
|
|
|
642
|
+
keyval_trans[Gdk::Keyval::KEY_Home] = "home"
|
|
643
|
+
keyval_trans[Gdk::Keyval::KEY_KP_Home] = "home"
|
|
644
|
+
keyval_trans[Gdk::Keyval::KEY_End] = "end"
|
|
645
|
+
keyval_trans[Gdk::Keyval::KEY_KP_End] = "end"
|
|
646
|
+
keyval_trans[Gdk::Keyval::KEY_Delete] = "delete"
|
|
647
|
+
keyval_trans[Gdk::Keyval::KEY_KP_Delete] = "delete"
|
|
648
|
+
|
|
464
649
|
key_trans = {}
|
|
465
650
|
key_trans["\e"] = "esc"
|
|
466
651
|
tk = keyval_trans[keyval]
|
|
@@ -501,6 +686,13 @@ class VSourceView < GtkSource::View
|
|
|
501
686
|
if key_str == "\u0000"
|
|
502
687
|
key_str = ""
|
|
503
688
|
end
|
|
689
|
+
|
|
690
|
+
# if keyname == "\u0000"
|
|
691
|
+
# puts "FOOOO 0000"
|
|
692
|
+
# return false
|
|
693
|
+
# keyname= ""
|
|
694
|
+
# end
|
|
695
|
+
|
|
504
696
|
|
|
505
697
|
keynfo = { :key_str => key_str, :key_name => keyname, :keyval => keyval }
|
|
506
698
|
debug keynfo.inspect
|
|
@@ -512,6 +704,9 @@ class VSourceView < GtkSource::View
|
|
|
512
704
|
vma.kbd.match_key_conf(key_str + "!", nil, :key_release)
|
|
513
705
|
@last_event = [keynfo, :key_release]
|
|
514
706
|
elsif sig == :key_press
|
|
707
|
+
# Remember a printable key so the IM commit that echoes it (see
|
|
708
|
+
# register_buffer_signals) is not fed to the bindings a second time.
|
|
709
|
+
@last_key_press_text = key_str.size == 1 ? key_str.dup : nil
|
|
515
710
|
vma.kbd.match_key_conf(key_str, nil, :key_press)
|
|
516
711
|
@last_event = [keynfo, key_str, :key_press]
|
|
517
712
|
end
|
|
@@ -549,7 +744,9 @@ class VSourceView < GtkSource::View
|
|
|
549
744
|
return pos_to_coord(buffer.cursor_position)
|
|
550
745
|
end
|
|
551
746
|
|
|
552
|
-
|
|
747
|
+
# scroll: false places the cursor without scrolling to it (the caller
|
|
748
|
+
# positions the view itself, e.g. Buffer#revert_by_diff).
|
|
749
|
+
def handle_deltas(scroll: true)
|
|
553
750
|
any_change = false
|
|
554
751
|
while d = @bufo.deltas.shift
|
|
555
752
|
any_change = true
|
|
@@ -562,14 +759,17 @@ class VSourceView < GtkSource::View
|
|
|
562
759
|
enditer = buffer.get_iter_at(:offset => pos + num)
|
|
563
760
|
buffer.delete(startiter, enditer)
|
|
564
761
|
elsif op == INSERT
|
|
762
|
+
@applying_delta = true
|
|
565
763
|
startiter = buffer.get_iter_at(:offset => pos)
|
|
566
764
|
buffer.insert(startiter, txt)
|
|
765
|
+
@applying_delta = false
|
|
567
766
|
end
|
|
568
767
|
end
|
|
569
768
|
if any_change
|
|
570
769
|
remask_gtk_buffer
|
|
571
770
|
#TODO: only when necessary
|
|
572
|
-
self.set_cursor_pos(pos)
|
|
771
|
+
self.set_cursor_pos(@bufo.pos, scroll: scroll)
|
|
772
|
+
$hook&.call(:view_text_changed, self)
|
|
573
773
|
end
|
|
574
774
|
|
|
575
775
|
# sanity_check #TODO
|
|
@@ -590,7 +790,7 @@ class VSourceView < GtkSource::View
|
|
|
590
790
|
end
|
|
591
791
|
end
|
|
592
792
|
|
|
593
|
-
def set_cursor_pos(pos)
|
|
793
|
+
def set_cursor_pos(pos, scroll: true)
|
|
594
794
|
itr = buffer.get_iter_at(:offset => pos)
|
|
595
795
|
itr2 = buffer.get_iter_at(:offset => pos + 1)
|
|
596
796
|
buffer.place_cursor(itr)
|
|
@@ -605,6 +805,7 @@ class VSourceView < GtkSource::View
|
|
|
605
805
|
else
|
|
606
806
|
buffer.move_mark(@curpos_mark, itr)
|
|
607
807
|
end
|
|
808
|
+
return true if !scroll
|
|
608
809
|
scroll_to_mark(@curpos_mark, within_margin, use_align, xalign, yalign)
|
|
609
810
|
$idle_scroll_to_mark = true
|
|
610
811
|
ensure_cursor_visible
|
|
@@ -682,13 +883,14 @@ class VSourceView < GtkSource::View
|
|
|
682
883
|
def set_cursor_color(ctype)
|
|
683
884
|
if @ctype != ctype
|
|
684
885
|
bg = $confh[:mode][ctype][:cursor][:background]
|
|
886
|
+
bg = "#000000" if ctype == :insert && vma.gui.scheme_is_light
|
|
685
887
|
if bg.class == String
|
|
686
888
|
if !@cursor_prov.nil?
|
|
687
889
|
self.style_context.remove_provider(@cursor_prov)
|
|
688
890
|
end
|
|
689
891
|
prov = Gtk::CssProvider.new
|
|
690
892
|
# prov.load(data: ".view text selection { background-color: #{bg}; color: #ffffff; }")
|
|
691
|
-
prov.load(data: ".view text selection { background-color: #{bg}; color: #
|
|
893
|
+
prov.load(data: ".view text selection { background-color: #{bg}; color: #{theme_color(:selection_fg)}; } .view { caret-color: #{bg}; }")
|
|
692
894
|
self.style_context.add_provider(prov)
|
|
693
895
|
@cursor_prov = prov
|
|
694
896
|
end
|
|
@@ -745,7 +947,8 @@ class VSourceView < GtkSource::View
|
|
|
745
947
|
|
|
746
948
|
# Sometimes we lose focus and the cursor vanishes because of that
|
|
747
949
|
# TODO: determine why&when
|
|
748
|
-
|
|
950
|
+
# Not when an entry widget (e.g. the ":" command line) has focus on purpose.
|
|
951
|
+
if !self.has_focus? and !vma.gui.entry_focused?
|
|
749
952
|
self.grab_focus
|
|
750
953
|
self.cursor_visible = false
|
|
751
954
|
self.cursor_visible = true
|
|
@@ -778,20 +981,45 @@ class VSourceView < GtkSource::View
|
|
|
778
981
|
end
|
|
779
982
|
end
|
|
780
983
|
|
|
984
|
+
unless vma.gui.app.lookup_action("ctx_lsp_jump_to_definition")
|
|
985
|
+
act = Gio::SimpleAction.new("ctx_lsp_jump_to_definition")
|
|
986
|
+
vma.gui.app.add_action(act)
|
|
987
|
+
act.signal_connect("activate") do
|
|
988
|
+
call_action(:lsp_jump_to_definition)
|
|
989
|
+
after_action
|
|
990
|
+
end
|
|
991
|
+
end
|
|
992
|
+
|
|
781
993
|
unless vma.gui.app.lookup_action("ctx_open_link")
|
|
782
994
|
act = Gio::SimpleAction.new("ctx_open_link")
|
|
783
995
|
vma.gui.app.add_action(act)
|
|
784
996
|
act.signal_connect("activate") do
|
|
785
|
-
next unless
|
|
786
|
-
if is_url(
|
|
787
|
-
open_url(
|
|
997
|
+
next unless @@context_link
|
|
998
|
+
if is_url(@@context_link)
|
|
999
|
+
open_url(@@context_link)
|
|
788
1000
|
else
|
|
789
|
-
fn = hpt_check_cur_word(
|
|
790
|
-
|
|
1001
|
+
fn = hpt_check_cur_word(@@context_link)
|
|
1002
|
+
open_new_file(fn) if fn
|
|
791
1003
|
end
|
|
792
1004
|
end
|
|
793
1005
|
end
|
|
794
1006
|
|
|
1007
|
+
unless vma.gui.app.lookup_action("ctx_open_file")
|
|
1008
|
+
act = Gio::SimpleAction.new("ctx_open_file")
|
|
1009
|
+
vma.gui.app.add_action(act)
|
|
1010
|
+
act.signal_connect("activate") do
|
|
1011
|
+
open_new_file(@@context_file) if @@context_file
|
|
1012
|
+
end
|
|
1013
|
+
end
|
|
1014
|
+
|
|
1015
|
+
unless vma.gui.app.lookup_action("ctx_open_file_external")
|
|
1016
|
+
act = Gio::SimpleAction.new("ctx_open_file_external")
|
|
1017
|
+
vma.gui.app.add_action(act)
|
|
1018
|
+
act.signal_connect("activate") do
|
|
1019
|
+
open_with_default_program(@@context_file) if @@context_file
|
|
1020
|
+
end
|
|
1021
|
+
end
|
|
1022
|
+
|
|
795
1023
|
@context_menu = Gtk::PopoverMenu.new
|
|
796
1024
|
@context_menu.set_parent(self)
|
|
797
1025
|
@context_menu.has_arrow = false
|
|
@@ -808,11 +1036,36 @@ class VSourceView < GtkSource::View
|
|
|
808
1036
|
nil
|
|
809
1037
|
end
|
|
810
1038
|
|
|
1039
|
+
def file_at(x, y)
|
|
1040
|
+
bx, by = window_to_buffer_coords(:widget, x.to_i, y.to_i)
|
|
1041
|
+
iter = get_iter_at_location(bx, by)
|
|
1042
|
+
return nil unless iter
|
|
1043
|
+
@bufo.file_path_at(iter.offset)
|
|
1044
|
+
end
|
|
1045
|
+
|
|
811
1046
|
def show_context_menu(x, y)
|
|
812
1047
|
init_context_menu if @context_menu.nil?
|
|
1048
|
+
|
|
1049
|
+
# Move the text cursor to the right-click position so that cursor-dependent
|
|
1050
|
+
# actions (e.g. Jump to Definition) operate on the clicked symbol.
|
|
1051
|
+
# Skip if there is an active selection — the user may be right-clicking
|
|
1052
|
+
# inside it to copy/paste, and moving the cursor would clear it.
|
|
1053
|
+
unless @bufo.selection_active?
|
|
1054
|
+
bx, by = window_to_buffer_coords(:widget, x.to_i, y.to_i)
|
|
1055
|
+
iter = get_iter_at_location(bx, by)
|
|
1056
|
+
@bufo.set_pos(iter.offset) if iter
|
|
1057
|
+
end
|
|
1058
|
+
|
|
813
1059
|
menu = Gio::Menu.new
|
|
814
|
-
|
|
815
|
-
menu.append("Open link", "app.ctx_open_link") if
|
|
1060
|
+
@@context_link = link_at(x, y)
|
|
1061
|
+
menu.append("Open link", "app.ctx_open_link") if @@context_link
|
|
1062
|
+
# Clicked text names an existing file (e.g. "report.pdf")
|
|
1063
|
+
@@context_file = @@context_link ? nil : file_at(x, y)
|
|
1064
|
+
if @@context_file
|
|
1065
|
+
menu.append("Open file", "app.ctx_open_file") if file_is_text_file(@@context_file)
|
|
1066
|
+
menu.append("Open file (external)", "app.ctx_open_file_external")
|
|
1067
|
+
end
|
|
1068
|
+
menu.append("Jump to Definition", "app.ctx_lsp_jump_to_definition") if @bufo.lsp
|
|
816
1069
|
CONTEXT_MENU_ITEMS.each { |label, action_id| menu.append(label, "app.ctx_#{action_id}") }
|
|
817
1070
|
if @bufo.selection_active?
|
|
818
1071
|
CONTEXT_MENU_ITEMS_SELECTION.each { |label, action_id| menu.append(label, "app.ctx_#{action_id}") }
|
|
@@ -822,3 +1075,4 @@ class VSourceView < GtkSource::View
|
|
|
822
1075
|
@context_menu.popup
|
|
823
1076
|
end
|
|
824
1077
|
end
|
|
1078
|
+
end # module Vimamsa
|