refactor: replace conf.window with conf.hover and conf.float

This commit is contained in:
JuanZoran
2023-01-19 23:44:27 +08:00
parent 373a1e4914
commit e6b02ba5ce
3 changed files with 70 additions and 55 deletions

View File

@@ -1,23 +1,28 @@
local conf = require('Trans').conf
local m_window
local m_result
return function(word)
-- TODO :online query
m_result = require('Trans.query.offline')(word)
m_window = require('Trans.window')
local float = conf.window.float
float.row = math.floor((vim.o.lines - float.height) / 2)
float.col = math.floor((vim.o.columns - float.width) / 2)
float.relative = 'editor'
m_result = require('Trans.query.offline')(word)
m_window = require('Trans.window')
local float = require('Trans').conf.float
local opt = {
relative = 'editor',
width = float.width,
height = float.height,
border = float.border,
title = float.title,
row = math.floor((vim.o.lines - float.height) / 2),
col = math.floor((vim.o.columns - float.width) / 2),
}
-- 创建窗口
m_window.init(true, float)
m_window.init(true, opt)
m_window.center('https:github.com/JuanZoran/Trans.nvim', '@text.uri') -- only show color with treesiter
m_window.draw()
m_window.map('q', function ()
m_window.try_close(9)
m_window.map('q', function()
m_window.try_close(float.animation)
end)
end

View File

@@ -182,18 +182,26 @@ local action = {
}
return function (word)
return function(word)
vim.validate {
word = { word, 's' },
}
-- 目前只处理了本地数据库的查询
m_result = require('Trans.query.offline')(word)
local hover = conf.window.hover
hover.relative = 'cursor'
hover.col = 2
hover.row = 2
m_window.init(false, hover)
m_result = require('Trans.query.offline')(word)
local hover = conf.hover
local opt = {
relative = 'cursor',
width = hover.width,
height = hover.height,
title = hover.title,
border = hover.border,
col = 2,
row = 2,
}
m_window.init(false, opt)
if m_result then
for _, field in ipairs(conf.order) do
@@ -209,15 +217,15 @@ return function (word)
{ --[[ 'InsertEnter', ]] 'CursorMoved', 'BufLeave', }, {
buffer = 0,
once = true,
callback = function ()
m_window.try_close(13) -- NOTE :maybe can be passed by uesr
callback = function()
m_window.try_close(hover.animation) -- NOTE :maybe can be passed by uesr
end,
})
m_window.set('wrap', true)
m_window.adjust()
for act, key in pairs(conf.keymap.hover) do
for act, key in pairs(hover.keymap) do
vim.keymap.set('n', key, function()
if m_window.is_open() then
action[act]()