feat: add auto_resize config for hover window
This commit is contained in:
parent
e5f0f2bf34
commit
da8b037523
@ -58,6 +58,8 @@ return {
|
||||
spinner = 'dots',
|
||||
---@type string -- TODO :support replace with {{special word}}
|
||||
fallback_message = '翻译超时或没有找到相关的翻译',
|
||||
auto_resize = true,
|
||||
padding = 10, -- only work when auto_resize is true
|
||||
keymaps = {
|
||||
play = '_',
|
||||
pageup = '[[',
|
||||
|
@ -95,21 +95,17 @@ end
|
||||
---@param opts
|
||||
---|{ width: integer, height: integer }
|
||||
function window:resize(opts)
|
||||
local width = opts.width
|
||||
local height = opts.height
|
||||
|
||||
|
||||
if self:height() ~= height then
|
||||
if opts.height and self:height() ~= opts.height then
|
||||
self:smooth_expand {
|
||||
field = 'height',
|
||||
to = height
|
||||
to = opts.height
|
||||
}
|
||||
end
|
||||
|
||||
if self:width() ~= width then
|
||||
if opts.width and self:width() ~= opts.width then
|
||||
self:smooth_expand {
|
||||
field = 'width',
|
||||
to = width
|
||||
to = opts.width
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -128,7 +128,6 @@ function M:wait(tbl, name, timeout)
|
||||
buffer[1] = ''
|
||||
end
|
||||
|
||||
|
||||
---Display Result in hover window
|
||||
---@param _ TransData
|
||||
---@param result TransResult
|
||||
@ -148,8 +147,8 @@ function M:process(_, result)
|
||||
local window = self.window
|
||||
local display_size = Trans.util.display_size(self.buffer:lines(), opts.width)
|
||||
if window and window:is_valid() then
|
||||
-- win:adjust_height(opts.height)
|
||||
display_size.width = math.min(opts.width, display_size.width + 6)
|
||||
---@diagnostic disable-next-line: assign-type-mismatch
|
||||
display_size.width = opts.auto_resize and math.min(opts.width, display_size.width + opts.padding) or nil
|
||||
window:resize(display_size)
|
||||
else
|
||||
window = self:init_window {
|
||||
|
Loading…
x
Reference in New Issue
Block a user