2023-03-15 16:07:07 +08:00
|
|
|
local api = vim.api
|
|
|
|
|
|
|
|
---@type table<string, fun(hover: TransHover)>
|
2023-03-12 22:12:33 +08:00
|
|
|
local strategy = {
|
2023-03-15 16:07:07 +08:00
|
|
|
pageup = function(hover)
|
2023-03-24 00:56:36 +08:00
|
|
|
hover.buffer:normal 'gg'
|
2023-03-12 22:12:33 +08:00
|
|
|
end,
|
2023-05-06 11:38:37 +08:00
|
|
|
|
2023-03-15 16:07:07 +08:00
|
|
|
pagedown = function(hover)
|
2023-03-24 00:56:36 +08:00
|
|
|
hover.buffer:normal 'G'
|
2023-03-12 22:12:33 +08:00
|
|
|
end,
|
2023-05-06 11:38:37 +08:00
|
|
|
|
2023-03-15 16:07:07 +08:00
|
|
|
pin = function(hover)
|
2023-03-18 13:53:09 +08:00
|
|
|
if hover.pin then
|
|
|
|
return
|
|
|
|
end
|
2023-03-15 19:27:21 +08:00
|
|
|
hover.pin = true
|
2023-03-15 16:07:07 +08:00
|
|
|
local window = hover.window
|
|
|
|
local width, height = window:width(), window:height()
|
|
|
|
local col = vim.o.columns - width - 3
|
|
|
|
window:try_close()
|
|
|
|
|
2023-03-18 13:53:09 +08:00
|
|
|
window = hover:init_window {
|
|
|
|
col = col,
|
|
|
|
width = width,
|
|
|
|
height = height,
|
2023-03-24 00:56:36 +08:00
|
|
|
relative = 'editor',
|
2023-03-18 13:53:09 +08:00
|
|
|
}
|
2023-03-15 16:07:07 +08:00
|
|
|
|
2023-03-24 00:56:36 +08:00
|
|
|
window:set('wrap', true)
|
2023-03-12 22:12:33 +08:00
|
|
|
end,
|
2023-05-06 11:38:37 +08:00
|
|
|
|
2023-03-14 13:18:53 +08:00
|
|
|
close = function(hover)
|
|
|
|
hover:destroy()
|
2023-03-12 22:12:33 +08:00
|
|
|
end,
|
2023-05-06 11:38:37 +08:00
|
|
|
|
2023-03-15 16:07:07 +08:00
|
|
|
toggle_entry = function(hover)
|
|
|
|
if api.nvim_get_current_win() ~= hover.window.winid then
|
|
|
|
api.nvim_set_current_win(hover.window.winid)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, winid in ipairs(api.nvim_list_wins()) do
|
|
|
|
if winid ~= hover.window.winid then
|
|
|
|
api.nvim_set_current_win(winid)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2023-03-12 22:12:33 +08:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
2023-03-14 22:30:25 +08:00
|
|
|
---@class TransHover
|
|
|
|
---@field execute fun(hover: TransHover, action: string)
|
2023-03-14 13:18:53 +08:00
|
|
|
return function(hover, action)
|
2023-05-06 11:38:37 +08:00
|
|
|
return strategy[action](hover)
|
2023-03-12 22:12:33 +08:00
|
|
|
end
|
2023-05-06 11:38:37 +08:00
|
|
|
|
|
|
|
-- This function will be called within coroutine, so we can't use __call
|
|
|
|
-- return setmetatable(strategy, {
|
|
|
|
-- __call = function(_, hover, action)
|
|
|
|
-- return strategy[action](hover)
|
|
|
|
-- end,
|
|
|
|
-- })
|