From 1367537926e36ebbe697573582d406351d56f79c Mon Sep 17 00:00:00 2001 From: JuanZoran <1430359574@qq.com> Date: Fri, 17 Mar 2023 09:01:36 +0800 Subject: [PATCH] feat: remove duplicate strs in web definition --- lua/Trans/frontend/hover/youdao.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lua/Trans/frontend/hover/youdao.lua b/lua/Trans/frontend/hover/youdao.lua index 09eb1a5..a74dfa0 100644 --- a/lua/Trans/frontend/hover/youdao.lua +++ b/lua/Trans/frontend/hover/youdao.lua @@ -11,13 +11,31 @@ function M.web(hover, result) buffer:setline(co('网络释义')) local indent = interval .. interval .. hover.opts.icon.list .. ' ' + local function remove_duplicate(strs) + local uniq_strs = {} + local str_map = {} + local opts = { plain = true, trim_empty = true } + + for i = 1, #strs do + local fields = vim.split(strs[i], '; ', opts) + for j = 1, #fields do + local field = fields[j] + if not str_map[field] then + uniq_strs[#uniq_strs + 1] = field + str_map[field] = true + end + end + end + return uniq_strs + end + for _, w in ipairs(result.web) do buffer:setline(it( interval .. w.key, 'TransWeb' )) - for _, v in ipairs(w.value) do + for _, v in ipairs(remove_duplicate(w.value)) do buffer:setline(it( indent .. v, 'TransWeb'