refactor: 重写了类的逻辑, 引入了部分bug待解决

This commit is contained in:
JuanZoran
2023-02-03 11:57:42 +08:00
parent 6737090710
commit 8b8879b2cd
9 changed files with 695 additions and 653 deletions

View File

@ -41,16 +41,16 @@ return function(word)
callback = function(str)
local ok, res = pcall(vim.json.decode, str)
if ok and res and res.trans_result then
result.value = {
word = word,
result[1] = {
title = { word = word },
[isEn and 'translation' or 'definition'] = res.trans_result[1].dst,
}
if result.callback then
result.callback(result.value)
result.callback(result[1])
end
else
result.value = false
result[1] = false
end
end,
})

View File

@ -16,8 +16,9 @@ vim.api.nvim_create_autocmd('VimLeavePre', {
end
})
return function(word)
local res = dict:select('stardict', {
local res = (dict:select('stardict', {
where = {
word = word,
},
@ -33,6 +34,20 @@ return function(word)
'exchange',
},
limit = 1,
})
return res[1]
}))[1]
if res then
res.title = {
word = res.word,
oxford = res.oxford,
collins = res.collins,
phonetic = res.phonetic,
}
res.word = nil
res.oxford = nil
res.collins = nil
res.phonetic = nil
end
return res
end