hchunhui / librime-lua

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

ShadowCandidate无法通过API修改comment #279

Closed HowcanoeWang closed 1 year ago

HowcanoeWang commented 1 year ago

将问题简化之后,使用下面的代码修改所有的candidate的comment,问题依然能复现:

lua/aux_code.lua

local function aux_filter (input, env)
    for cand in input:iter() do
        cand.comment = '<ab>'
        yield(cand)
    end
end

return aux_filter

但是输入法并没有给所有的candidate都加上comment,效果如下:

image

image

不确定是这个插件的bug还是fcitx5的性能限制,还是我打开的方式不对


其他的配置供参考:

input.schema.yaml:

...

engine:
  processors:
    - ascii_composer
    - recognizer
    - key_binder
    - speller
    - punctuator
    - selector
    - navigator
    - express_editor
  segmentors:
    - ascii_segmentor
    - matcher
    - abc_segmentor
    - punct_segmentor
    - fallback_segmentor
  translators:
    - punct_translator
    - reverse_lookup_translator
    - table_translator@479k_english
    - table_translator@custom_phrase
    - table_translator@nihongo-r
    - script_translator
  filters:
    - simplifier@emoji_suggestion
    - simplifier
    - uniquifier
    - lua_filter@aux_filter
...

rime.lua:

aux_filter = require("aux_code")
shewer commented 1 year ago

simplifier 轉換後會變成 ShadowCandidate ,此candidate 無法設定

HowcanoeWang commented 1 year ago

simplifier 轉換後會變成 ShadowCandidate ,此candidate 無法設定

竟然真的是繁簡轉換的問題=_=,這個無法設定是底層被鎖死的,還是該lua插件暫時沒有支持?

我看官方文檔裏面是有這個API的:

https://github.com/hchunhui/librime-lua/wiki/Scripting#shadowcandidate ShadowCandidate(cand,type,text,comment)類似 simplifier 的作法

构造方法:ShadowCandidate(cand, type, text, comment, inherit_comment) cand type text comment inherit_comment: (可选)

有沒有方法可以獲取這些shadowcandiate並修改?

shewer commented 1 year ago

方法1 最近 librime commit : simplifier 新增 一個選項 append_comment , 就是 加在 現存 comment 後面 把你的 filter 置換到 simpifier 前

方法2 方在 simplifier 以後,檢查 candidate type 分開處理


local function filter(input, env)
    for cand in input:iter() do 
        if cand:dynamic_type() == "Shadow" then
               local s_text= cand.text
                local s_comment = cand.comment 
                local org_cand = cand:get_genuine()  
                yield(                
                     ShadowCandidate( org_cand, s_text,  org_cand.comment .. s_comment .. "...." ) )
        else
              --local comment = cand:get_geuine().comment
              --cand:get_genuine().comment =  comment .. "...."
               cand.comment = cand.comment .. "..."   -- comment 
              yield(cand)
        end
     end
end

return filter
HowcanoeWang commented 1 year ago

先尝试了一下方法一,似乎archlinux还没有更新到最新版,所以不起作用

然后尝试方法二,思路很清晰,部分api的细节有点问题,我稍微对着api改了改就能用了:

最终效果没有任何问题:

image

感谢您的耐心解答!