hchunhui / librime-lua

Extending RIME with Lua scripts
BSD 3-Clause "New" or "Revised" License
293 stars 43 forks source link

通过调用 Component.Translator 产出的 cand 为什么改不了属性 #341

Closed boomker closed 1 month ago

boomker commented 1 month ago

我有这样一段代码:

function  p.init(env)
    env.custom_phrase_tran = Component.Translator(env.engine, "", "table_translator@custom_phrase")
end

function  p.func(input, seg, env)
    -- 自定义短语的置顶字词加标记
    env.custom_tran = env.custom_phrase_tran:query(input, seg)
    for cand in env.custom_tran:iter() do
        cand.comment = custom_mark
        -- yield(cand)
        -- yield(ShadowCandidate(cand, "custom_top", cand.text, cand.comment))
        -- yield(cand:to_shadow_candidate("custom_top", cand.text, env.comment_mark))
        table.insert(custom_phrase_cands, cand)
    end
end

上述代码里, 我想改 cand 的 comment 属性, 然后 yield 出来,然而实际上这个属性修改并没有生效。 我现在只能是把修改属性后的 cand 放到一个表里, 然后在 filter 里 yield 出来,这样做可以生效,但是感觉不优雅。

@shewer 大佬, 可以指点一下吗,🙏。

shewer commented 1 month ago

到 issue 中找 ShadowCandidate 問題 simplecandidate 隨便改 Phrase Unique text 無法改 ShadowCandidate 全都無法改 參考 librime code 有關 Candidate 類

boomker commented 1 month ago

意思是, 这类 candidate 都是 ShadowCandidate, 没法改咯?