From 98d18b74df12e9995be2942ad518cd340e1b33e8 Mon Sep 17 00:00:00 2001 From: mirtlecn Date: Wed, 15 May 2024 11:15:24 +0800 Subject: [PATCH] feat(lua): use translator/keep_comments: true to prevent lua from erasing pinyin comments --- lua/corrector.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/corrector.lua b/lua/corrector.lua index 02491ee..ec72551 100644 --- a/lua/corrector.lua +++ b/lua/corrector.lua @@ -13,6 +13,7 @@ local M = {} function M.init(env) local config = env.engine.schema.config + env.keep_comment = config:get_bool('translator/keep_comments') local delimiter = config:get_string('speller/delimiter') if delimiter and #delimiter > 0 and delimiter:sub(1,1) ~= ' ' then env.delimiter = delimiter:sub(1,1) @@ -122,14 +123,19 @@ function M.func(input, env) -- cand.comment 是目前输入的词汇的完整拼音 local pinyin = cand.comment:match("^[(.-)]$") if pinyin and #pinyin > 0 then + local correction_pinyin = pinyin if env.delimiter then - pinyin = pinyin:gsub(env.delimiter,' ') + correction_pinyin = correction_pinyin:gsub(env.delimiter,' ') end - local c = M.corrections[pinyin] + local c = M.corrections[correction_pinyin] if c and cand.text == c.text then cand:get_genuine().comment = string.gsub(M.style, "{comment}", c.comment) else - cand:get_genuine().comment = "" + if env.keep_comment then + cand:get_genuine().comment = string.gsub(M.style, "{comment}", pinyin) + else + cand:get_genuine().comment = "" + end end end yield(cand)