feat: add window animation option for window close

This commit is contained in:
JuanZoran 2023-01-15 14:55:48 +08:00
parent 0a645c3988
commit 7a03ccc82a
3 changed files with 48 additions and 5 deletions

View File

@ -1,5 +1,20 @@
# 字段说明
<!--toc:start-->
- [字段说明](#字段说明)
- [本地](#本地)
- [有道](#有道)
- [中英](#中英)
- [百度](#百度)
- [返回结果](#返回结果)
- [彩云小译](#彩云小译)
- [必应](#必应)
- [腾讯翻译君](#腾讯翻译君)
- [阿里翻译](#阿里翻译)
- [火山翻译](#火山翻译)
- [金山词霸](#金山词霸)
<!--toc:end-->
## 本地
- `word`
查询的字符串
@ -105,3 +120,10 @@ dict string 中英词典资源 返回中文或英文词典资源,包含音标
## 腾讯翻译君
## 阿里翻译
## 火山翻译
## 金山词霸
## Dictionary

View File

@ -81,20 +81,18 @@ M.load_hover_opts = function()
{ 'InsertEnter', 'CursorMoved', 'BufLeave', }, {
buffer = 0,
once = true,
callback = function()
if api.nvim_win_is_valid(M.id) then
api.nvim_win_close(M.id, true)
end
end,
callback = M.close,
})
api.nvim_win_set_option(M.id, 'wrap', M.view ~= 'float')
local height = util.get_height(M.bufnr, M.id)
if M.height > height then
api.nvim_win_set_height(M.id, height)
M.height = height
end
end
M.load_float_opts = function()
vim.keymap.set('n', 'q', function()
if api.nvim_win_is_valid(M.id) then
@ -110,6 +108,28 @@ M.load_float_opts = function()
end
M.close = function()
if api.nvim_win_is_valid(M.id) then
if conf.window.animation then
local function narrow()
if M.height > 1 then
M.height = M.height - 1
api.nvim_win_set_height(M.id, M.height)
vim.defer_fn(narrow, 13)
else
api.nvim_win_close(M.id, true)
end
end
vim.defer_fn(narrow, 10)
else
api.nvim_win_close(M.id, true)
end
end
end
M.show = function()
M.init(M.view or 'float')
M.load_opts()

View File

@ -8,6 +8,7 @@ M.conf = {
},
window = {
border = 'rounded',
animation = true,
hover = {
width = 36,
height = 26,