Skip to content

请问有没有办法读写编码提示 #117

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

Closed
hxse opened this issue Apr 27, 2021 · 10 comments
Closed

请问有没有办法读写编码提示 #117

hxse opened this issue Apr 27, 2021 · 10 comments

Comments

@hxse
Copy link

hxse commented Apr 27, 2021

通过快捷键,改变候选的编码提示,而不改变候选本身
提示指的是,像这个候选中的“日期”,希望可以动态读写修改这个提示
59652590-f6b02c80-91c0-11e9-81cc-821fb3513d24

@shewer
Copy link
Contributor

shewer commented Apr 27, 2021

用 key_binder 可以少寫 lua_processor
{ when: has_menu , accept: "F10" , toggle: data_fmt }

function translator_func( input,seg,env) -- lua_translator@date  
   local context=env.engine.context
   local data_fmt= context:get_option( "data_fmt") 
   if  input== "date" then 
         local type, text, comment  
         comment=  data_fmt  and  "aaaaaaaa"  or  "日期“
         local cand= Candidate(  type, seg.start,seg._end, text , comment  )
         yield(  cand)
    end
end

@hxse
Copy link
Author

hxse commented Apr 27, 2021

用 key_binder 可以少寫 lua_processor
{ when: has_menu , accept: "F10" , toggle: data_fmt }

function translator_func( input,seg,env) -- lua_translator@date  
   local context=env.engine.context
   local data_fmt= context:get_option( "data_fmt") 
   if  input== "date" then 
         local type, text, comment  
         comment=  data_fmt  and  "aaaaaaaa"  or  "日期“
         local cand= Candidate(  type, seg.start,seg._end, text , comment  )
         yield(  cand)
    end
end

请问用 key_binder 有没有办法控制是否释放真实按键呢,就像issues/20里的一样

@shewer
Copy link
Contributor

shewer commented Apr 27, 2021

https://github.com/rime/librime/blob/0ee64d4541b66f7b9397094cdd45260bfb4ac00c/src/rime/engine.cc#L95

https://github.com/rime/librime/blob/0ee64d4541b66f7b9397094cdd45260bfb4ac00c/src/rime/gear/key_binder.cc#L191

看一下 key_binder.cc ProcessKeyEvent
return kNoop
engine 會把KEY 送到下個 processor-> ProcessKeyEvent(key)
return kAccepted
收下 結束 key 收下 ( 吃掉)
return kRejected
拒絕 結束 -- key 未處理

@hxse
Copy link
Author

hxse commented Apr 27, 2021

https://github.com/rime/librime/blob/0ee64d4541b66f7b9397094cdd45260bfb4ac00c/src/rime/engine.cc#L95

https://github.com/rime/librime/blob/0ee64d4541b66f7b9397094cdd45260bfb4ac00c/src/rime/gear/key_binder.cc#L191

看一下 key_binder.cc ProcessKeyEvent
return kNoop
engine 會把KEY 送到下個 processor-> ProcessKeyEvent(key)
return kAccepted
收下 結束 key 收下 ( 吃掉)
return kRejected
拒絕 結束 -- key 未處理

没太看明白,这个要怎么在luna里控制啊

@shewer
Copy link
Contributor

shewer commented Apr 27, 2021

用 key_binder 可以少寫 lua_processor
{ when: has_menu , accept: "F10" , toggle: data_fmt }

function translator_func( input,seg,env) -- lua_translator@date  
   local context=env.engine.context
   local data_fmt= context:get_option( "data_fmt") 
   if  input== "date" then 
         local type, text, comment  
         comment=  data_fmt  and  "aaaaaaaa"  or  "日期“
         local cand= Candidate(  type, seg.start,seg._end, text , comment  )
         yield(  cand)
    end
end

请问用 key_binder 有没有办法控制是否释放真实按键呢,就像issues/20里的一样

key_binder 是 librime的 processor 有沒有释放真实按键 就 在 source code
kNoop kAccepted kRejected 就是判斷 keyevent 收 拒

@shewer
Copy link
Contributor

shewer commented Apr 27, 2021

用 key_binder 可以少寫 lua_processor
{ when: has_menu , accept: "F10" , toggle: data_fmt }

function translator_func( input,seg,env) -- lua_translator@date  
   local context=env.engine.context
   local data_fmt= context:get_option( "data_fmt")    --<< -------
   if  input== "date" then 
         local type, text, comment  
        if data_fimt then  -- 
                 ..........  當  data_fmt  truecand.comment 資料
         end 
         .........
                yield(.....)           
    end
end

请问用 key_binder 有没有办法控制是否释放真实按键呢,就像issues/20里的一样

請調用 sample/date.lua 修改

@hxse
Copy link
Author

hxse commented Apr 27, 2021

用 key_binder 可以少寫 lua_processor
{ when: has_menu , accept: "F10" , toggle: data_fmt }

function translator_func( input,seg,env) -- lua_translator@date  
   local context=env.engine.context
   local data_fmt= context:get_option( "data_fmt") 
   if  input== "date" then 
         local type, text, comment  
         comment=  data_fmt  and  "aaaaaaaa"  or  "日期“
         local cand= Candidate(  type, seg.start,seg._end, text , comment  )
         yield(  cand)
    end
end

这个代码测试了一下,成功运行,就是热键本身被占用了无法释放出来,小白实在不懂啊,该怎么写
看不懂源码,希望能得到 ctrl+c v 式的指导,拜谢

@hxse
Copy link
Author

hxse commented Apr 30, 2021

用 key_binder 可以少写 lua_processor
{ when: has_menu , accept: "F10" , toggle: data_fmt }

function translator_func( input,seg,env) -- lua_translator@date  
   local context=env.engine.context
   local data_fmt= context:get_option( "data_fmt") 
   if  input== "date" then 
         local type, text, comment  
         comment=  data_fmt  and  "aaaaaaaa"  or  "日期“
         local cand= Candidate(  type, seg.start,seg._end, text , comment  )
         yield(  cand)
    end
end

这个代码, translator 可以用, 但是filter 就没有用, 比如说这个, 很奇怪不知道为什么

function single_char(input, env)
   b = env.engine.context:get_option("single_char")
   for cand in input:iter() do
      if (not b or utf8.len(cand.text) == 1) then
         yield(cand)
      end
   end
end
return single_char

@OnchiuLee
Copy link

用 key_binder 可以少写 lua_processor

{ when: has_menu , accept: "F10" , toggle: data_fmt }

function translator_func( input,seg,env) -- lua_translator@date

local context=env.engine.context

local data_fmt= context:get_option( "data_fmt")

if input== "date" then

     local type, text, comment  
     comment=  data_fmt  and  "aaaaaaaa"  or  "日期“
     local cand= Candidate(  type, seg.start,seg._end, text , comment  )
     yield(  cand)
end

end

这个代码, translator 可以用, 但是filter 就没有用, 比如说这个, 很奇怪不知道为什么


function single_char(input, env)

   b = env.engine.context:get_option("single_char")

   for cand in input:iter() do

      if (not b or utf8.len(cand.text) == 1) then

         yield(cand)

      end

   end

end

return single_char

结构都没搞清楚,搞什么……

@hxse
Copy link
Author

hxse commented May 1, 2021

结构都没搞清楚,搞什么……

所以 这个要怎么搞 😂
小白已经蒙圈了

@hxse hxse closed this as completed Jan 8, 2022
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

3 participants