feat: add auto_play for hover mode
This commit is contained in:
@ -22,6 +22,7 @@ M.conf = {
|
||||
pin = '<leader>[',
|
||||
close = '<leader>]',
|
||||
toggle_entry = '<leader>;',
|
||||
play = '_',
|
||||
},
|
||||
animation = {
|
||||
-- open = 'fold',
|
||||
@ -35,6 +36,7 @@ M.conf = {
|
||||
'CursorMoved',
|
||||
'BufLeave',
|
||||
},
|
||||
auto_play = true,
|
||||
},
|
||||
float = {
|
||||
width = 0.8,
|
||||
@ -69,13 +71,13 @@ M.conf = {
|
||||
},
|
||||
icon = {
|
||||
star = '',
|
||||
notfound = '❔',
|
||||
yes = '✔️',
|
||||
no = '❌'
|
||||
-- notfound = '❔',
|
||||
notfound = ' ',
|
||||
yes = ' ',
|
||||
no = ''
|
||||
-- yes = '✔️',
|
||||
-- no = '❌'
|
||||
-- star = '⭐',
|
||||
-- notfound = '',
|
||||
-- yes = '',
|
||||
-- no = ''
|
||||
},
|
||||
|
||||
db_path = '$HOME/.vim/dict/ultimate.db',
|
||||
|
@ -2,6 +2,7 @@ if vim.fn.executable('sqlite3') ~= 1 then
|
||||
error('Please check out sqlite3')
|
||||
end
|
||||
|
||||
|
||||
vim.api.nvim_create_user_command('Translate', function()
|
||||
require("Trans").translate()
|
||||
end, { desc = ' 单词翻译', })
|
||||
|
@ -186,6 +186,8 @@ end
|
||||
|
||||
local action
|
||||
local next
|
||||
local _word
|
||||
|
||||
action = {
|
||||
pageup = function()
|
||||
m_window:normal('gg')
|
||||
@ -251,7 +253,12 @@ action = {
|
||||
else
|
||||
vim.keymap.del('n', conf.hover.keymap.toggle_entry, { buffer = true })
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
play = function()
|
||||
local file = debug.getinfo(1, "S").source:sub(2):match('(.*)lua/') .. 'tts/say.js'
|
||||
vim.fn.jobstart('node ' .. file .. ' ' .. _word)
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
@ -259,11 +266,15 @@ return function(word)
|
||||
vim.validate {
|
||||
word = { word, 's' },
|
||||
}
|
||||
|
||||
_word = word
|
||||
-- 目前只处理了本地数据库的查询
|
||||
m_result = require('Trans.query.offline')(word)
|
||||
local hover = conf.hover
|
||||
local opt = {
|
||||
if hover.auto_play then
|
||||
action.play()
|
||||
end
|
||||
|
||||
local opt = {
|
||||
relative = 'cursor',
|
||||
width = hover.width,
|
||||
height = hover.height,
|
||||
@ -298,6 +309,7 @@ return function(word)
|
||||
end)
|
||||
|
||||
|
||||
|
||||
-- Auto Close
|
||||
cmd_id = api.nvim_create_autocmd(
|
||||
hover.auto_close_events, {
|
||||
@ -310,7 +322,9 @@ return function(word)
|
||||
end,
|
||||
})
|
||||
|
||||
for act, key in pairs(hover.keymap) do
|
||||
vim.keymap.set('n', key, action[act], { buffer = true, silent = true })
|
||||
if m_result then
|
||||
for act, key in pairs(hover.keymap) do
|
||||
vim.keymap.set('n', key, action[act], { buffer = true, silent = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user