forked from eugenpt/lite-xl-vibe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisual_mode.lua
75 lines (58 loc) · 2.13 KB
/
visual_mode.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
--[[
VISUAL mode. Kind of.
What I do here is I simply look for keymaps nmapping to move-to-<sth>
Aand add v/d/c keymaps for select-to-/delete-to/change-to- <sth>
]]--
local core = require "core"
local common = require "core.common"
local command = require "core.command"
local config = require "core.config"
local keymap = require "core.keymap"
local style = require "core.style"
local DocView = require "core.docview"
local CommandView = require "core.commandview"
local config = require "plugins.vibe.config"
local misc = require "plugins.vibe.misc"
local vibe = core.vibe
vibe.translate = require "plugins.vibe.translate"
require "plugins.vibe.keymap"
----------------------------------------------------------------------------
local doc_move_to = 'doc:move-to-'
local doc_select_to = 'doc:select-to-'
local doc_delete_to = 'doc:delete-to-'
for bind,coms in pairs(keymap.nmap) do
local com_name = misc.find_in_list(coms, function(item) return (item:sub(1,#doc_move_to)==doc_move_to) end)
if com_name then
local verbose = com_name:find_literal('-start-of-line') or com_name:find_literal('-doc')
if verbose then
core.log('[%s] -> %s', bind, misc.str(coms))
end
local sel_name = doc_select_to .. com_name:sub(#doc_move_to+1)
if verbose then
core.log('sel_name=[%s]',sel_name)
core.log('command.map[sel_name]=%s',misc.str(command.map[sel_name]))
end
if command.map[sel_name] then
if verbose then
core.log(sel_name)
end
-- make a command to do the same as sel- but only if we have selection
local vibe_sel_name = 'vibe:'..sel_name:sub(5)
if command.map[vibe_sel_name] == nil then
command.add(misc.has_selection, {
[vibe_sel_name] = function()
command.perform(sel_name)
end,
})
end
-- and map it to be tried first
table.insert(keymap.nmap[bind], 1, vibe_sel_name)
-- and map the v<stroke> to do selection itself
keymap.add_nmap({
['v'..bind] = sel_name,
['d'..bind] = 'v'..bind..'d',
['c'..bind] = 'v'..bind..'di',
})
end
end
end