Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 option_update_notifier:connect(function , grup:int) 用法 #360

Open
shewer opened this issue Aug 4, 2024 · 0 comments
Open

使用 option_update_notifier:connect(function , grup:int) 用法 #360

shewer opened this issue Aug 4, 2024 · 0 comments

Comments

@shewer
Copy link
Contributor

shewer commented Aug 4, 2024

在 option_update_notifier 增加 group 可以超前 engine:OnOptionUpdate()
處理 ,省去 reflash_non_confirmed_composition()

https://github.com/rime/librime/blob/0cdce16a7d0d5a43fdf8183eb632bd3cbfc13a8d/src/rime/engine.cc#L130-L138

local F = {}
function F.init(env)
    env.cand_index = 0
    local context = env.engine.context
     env.notifiers ={}
     env.notifiers[1] =  context.option_update_notifier:connect(
            function(ctx, name)
                 if  not ctx:has_menu() then
                      env.cand_index = 0
                       return
                 end
                      -- 在 engine:OnOptionUpdate()  前備份 selected_index
                  env.cand_index = ctx.composition:back().selected_index
              end, 1)
      env.notifiers[2] = context.option_update_notifier:connect(
              function(ctx, name)
                    if not ctx:has_menu()  then return end
                    -- 在 engine:OnOptionUpdate() 後 ,還原 selected_index
                    if name ==  "option_name" then
                          -- ......
                          ecv.composition:back().selected_index = env.cand_index
                     end
               end)
end
function F.fini(env)
     for i,v in ipairs(env.notifiers) do v:disconnect()  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant