fix: fix some bugs and need to refator this project

This commit is contained in:
JuanZoran 2023-01-04 23:06:09 +08:00
parent 79348ec4c5
commit c51937c6cf
3 changed files with 17 additions and 25 deletions

View File

@ -1,6 +0,0 @@
local M = {}
function M.query(arg)
end
return M

View File

@ -1,17 +1,15 @@
local M = {} local M = {}
M.conf = require("Trans.conf") M.conf = require("Trans.conf")
function M.setup(conf) function M.setup(conf)
conf = conf or {} conf = conf or {}
if conf.display then for k, v in pairs(conf) do
conf.display = vim.tbl_extend('force', M.conf.display, conf.display) if type(v) == 'table' then
M.conf[k] = vim.tbl_extend('force', M.conf[k], v)
else
M.conf[k] = v
end
end end
if conf.icon then
conf.icon = vim.tbl_extend('force', M.conf.icon, conf.icon)
end
M.conf = vim.tbl_extend('force', M.conf, conf) M.conf = vim.tbl_extend('force', M.conf, conf)
require("Trans.setup") require("Trans.setup")
end end

View File

@ -1,14 +1,17 @@
local db = require("Trans").db local db = require("Trans").db
-- local conf = require("Trans").conf
vim.api.nvim_create_user_command('TranslateCursorWord', require("Trans.display").query_cursor, {}) vim.api.nvim_create_user_command('TranslateCursorWord', require("Trans.display").query_cursor, {
vim.api.nvim_create_user_command('TranslateSelectWord', require("Trans.display").query_select, {}) desc = '翻译光标下的单词',
vim.api.nvim_create_user_command('TranslateInputWord', require("Trans.display").query_input, {}) })
vim.api.nvim_create_user_command('TranslateSelectWord', require("Trans.display").query_select, {
desc = '翻译选中的单词',
})
vim.api.nvim_create_user_command('TranslateInputWord', require("Trans.display").query_input, {
desc = '翻译输入的单词',
})
vim.api.nvim_create_autocmd('VimLeavePre', {
local group = vim.api.nvim_create_augroup("Trans", { clear = true }) group = vim.api.nvim_create_augroup("Trans", { clear = true }),
vim.api.nvim_create_autocmd('VimLeave', {
group = group,
pattern = '*', pattern = '*',
callback = function() callback = function()
if db:isopen() then if db:isopen() then
@ -17,9 +20,6 @@ vim.api.nvim_create_autocmd('VimLeave', {
end, end,
}) })
-- vim.keymap.set('n', 'mm', '<cmd>TranslateCurosorWord<cr>')
-- vim.keymap.set('v', 'mm', '<Esc><cmd>TranslateSelectWord<cr>')
local highlights = require("Trans").conf.highlight local highlights = require("Trans").conf.highlight
for highlight, opt in pairs(highlights) do for highlight, opt in pairs(highlights) do
vim.nvim_set_hl(0, highlight, opt) vim.nvim_set_hl(0, highlight, opt)