fix: query strategy

This commit is contained in:
JuanZoran
2023-05-06 11:38:37 +08:00
parent ab212fefe1
commit f17171d28b
10 changed files with 110 additions and 103 deletions

View File

@ -5,9 +5,11 @@ local strategy = {
pageup = function(hover)
hover.buffer:normal 'gg'
end,
pagedown = function(hover)
hover.buffer:normal 'G'
end,
pin = function(hover)
if hover.pin then
return
@ -27,9 +29,11 @@ local strategy = {
window:set('wrap', true)
end,
close = function(hover)
hover:destroy()
end,
toggle_entry = function(hover)
if api.nvim_get_current_win() ~= hover.window.winid then
api.nvim_set_current_win(hover.window.winid)
@ -48,6 +52,12 @@ local strategy = {
---@class TransHover
---@field execute fun(hover: TransHover, action: string)
return function(hover, action)
-- TODO :
strategy[action](hover)
return strategy[action](hover)
end
-- 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,
-- })

View File

@ -19,7 +19,11 @@ local M = Trans.metatable('frontend.hover', {
M.__index = M
---Set up function which will be invoked when this module is loaded
--[[
Set up function which will be invoked when this module is loaded
Because the options are not loaded yet when this module is loaded
--]]
function M.setup()
local set = vim.keymap.set
for action, key in pairs(M.opts.keymaps) do
@ -89,15 +93,18 @@ end
function M:init_window(opts)
opts = opts or {}
local m_opts = self.opts
---@format disable-next
local option = {
buffer = self.buffer,
animation = m_opts.animation,
win_opts = {
relative = opts.relative or 'cursor',
col = opts.col or 1,
row = opts.row or 1,
width = opts.width or m_opts.width,
height = opts.height or m_opts.height,
col = opts.col or 1,
row = opts.row or 1,
width = opts.width or m_opts.width,
height = opts.height or m_opts.height,
title = m_opts.title,
title_pos = m_opts.title and 'center',
zindex = 100,