refactor: remove auto setup frontend keymap

This commit is contained in:
JuanZoran
2023-03-24 11:09:04 +08:00
parent 82fa2a008a
commit a4dff90064
4 changed files with 49 additions and 51 deletions

View File

@ -1,20 +1,16 @@
-- local api = vim.api
-- local conf = require('Trans').conf
-- local buffer = require('Trans.buffer')()
local Trans = require 'Trans'
-- local node = require("Trans.node")
-- local t = node.text
-- local it = node.item
-- local f = node.format
---@class TransFloat
local M = {}
function M.new()
-- TODO :
end
-- local engine_map = {
-- baidu = '百度',
-- youdao = '有道',
-- iciba = 'iciba',
-- offline = '本地',
-- }
return M
-- local function set_tag_hl(name, status)
-- local hl = conf.float.tag[status]
-- m_window:set_hl(name, {
@ -118,3 +114,10 @@
-- m_window:map(key, action[act])
-- end
-- end
-- local engine_map = {
-- baidu = '百度',
-- youdao = '有道',
-- iciba = 'iciba',
-- offline = '本地',
-- }

View File

@ -17,6 +17,22 @@ local M = Trans.metatable('frontend.hover', {
})
M.__index = M
function M.setup()
local set = vim.keymap.set
for action, key in pairs(M.opts.keymaps) do
set('n', key, function()
local instance = M.get_active_instance()
if instance then
coroutine.wrap(instance.execute)(instance, action)
else
return key
end
end)
end
end
---Create a new hover instance
---@return TransHover new_instance
function M.new()
@ -27,7 +43,6 @@ function M.new()
}
M.queue[#M.queue + 1] = new_instance
new_instance.buffer:deleteline(1)
return setmetatable(new_instance, M)
end
@ -186,8 +201,8 @@ function M:process(data)
return
end
local opts = self.opts
local util = Trans.util
local opts = self.opts
local buffer = self.buffer
if opts.auto_play then
@ -210,19 +225,20 @@ function M:process(data)
local lines = buffer:lines()
local valid = window and window:is_valid()
local width =
window and window:is_valid() and
(opts.auto_resize and
math.max(
math.min(opts.width, util.display_width(lines) + opts.padding),
math.min(data.str:width(), opts.split_width)
)
or opts.width)
valid and
(opts.auto_resize and
math.max(
math.min(opts.width, util.display_width(lines) + opts.padding),
math.min(data.str:width(), opts.split_width)
)
or opts.width)
or math.min(opts.width, util.display_width(lines) + opts.padding)
local height = math.min(opts.height, util.display_height(lines, width))
if window and window:is_valid() then
if valid then
window:resize { width = width, height = height }
else
window = self:init_window {