feat: start to support float view style and add some configuration

This commit is contained in:
JuanZoran
2023-01-19 23:22:46 +08:00
parent e80e6efbc8
commit 373a1e4914
4 changed files with 118 additions and 87 deletions

View File

@@ -1,43 +1,23 @@
-- local function generate_opts(view)
-- -- TODO :
-- vim.validate {
-- view = { view, 's' },
-- }
-- local hover = conf.hover
-- local float = conf.float
-- local title_pos = 'center'
-- local title = {
-- { '', 'TransTitleRound' },
-- -- { '', 'TransTitleRound' },
-- { conf.icon.title .. ' Trans', 'TransTitle' },
-- -- { '', 'TransTitleRound' },
-- { '', 'TransTitleRound' },
-- }
--
-- return ({
-- hover = {
-- relative = 'cursor',
-- width = hover.width,
-- height = hover.height,
-- border = hover.border,
-- title = title,
-- title_pos = title_pos,
-- focusable = false,
-- zindex = 100,
-- col = 2,
-- row = 2,
-- },
-- float = {
-- relative = 'editor',
-- width = float.width,
-- height = float.height,
-- border = float.border,
-- title = title,
-- title_pos = title_pos,
-- focusable = false,
-- zindex = 75,
-- row = math.floor((vim.o.lines - float.height) / 2),
-- col = math.floor((vim.o.columns - float.width) / 2),
-- },
-- })[view]
-- end
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_window.init(true, float)
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)
end)
end

View File

@@ -172,7 +172,17 @@ local process = {
}
local function handle(word)
local action = {
pageup = function()
m_window.normal('gg')
end,
pagedown = function()
m_window.normal('G')
end,
}
return function (word)
vim.validate {
word = { word, 's' },
}
@@ -185,7 +195,6 @@ local function handle(word)
hover.row = 2
m_window.init(false, hover)
if m_result then
for _, field in ipairs(conf.order) do
process[field]()
@@ -197,15 +206,22 @@ local function handle(word)
m_window.draw()
-- Auto Close
vim.api.nvim_create_autocmd(
{ 'InsertEnter', 'CursorMoved', 'BufLeave', }, {
{ --[[ 'InsertEnter', ]] 'CursorMoved', 'BufLeave', }, {
buffer = 0,
once = true,
callback = m_window.try_close,
callback = function ()
m_window.try_close(13) -- NOTE :maybe can be passed by uesr
end,
})
m_window.set('wrap', true)
m_window.adjust()
end
return handle
for act, key in pairs(conf.keymap.hover) do
vim.keymap.set('n', key, function()
if m_window.is_open() then
action[act]()
end
end)
end
end