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

怎样实现中英文之间自动加空格 #238

Open
H4M5TER opened this issue Apr 4, 2023 · 5 comments
Open

怎样实现中英文之间自动加空格 #238

H4M5TER opened this issue Apr 4, 2023 · 5 comments

Comments

@H4M5TER
Copy link

H4M5TER commented Apr 4, 2023

考虑以下几种方式

  1. 在中英混输上屏时,自动在中英文之间加空格
  2. 在键入任意字符时记录并和上一个字符比对

有哪些接口可能有帮助?

@shewer
Copy link
Contributor

shewer commented Apr 7, 2023

在engine/filters
最後加上一個 lua_filter
檢查前面commit 的字的最後一個 字元不是空白 時 pre_space = " "
候選字是英文時把 候選字 加上空白

local F={}
function F.init(env)
   env.size=20
   env.history={}
   
   env.notifier= env.engine.context.commit_notifier:connect( function(ctx)
      for i=env.size, #env.history do
           env.history[i] = nil
       end
       table.insert( env.history, 1, ctx:get_selected_candidate().text)
   end)
end
function F.fini(env)
   env.notifier:disconnect()
end
function F.tag_match(seg, env)
   -- return  env.engine.context:get_option('auto_space")  -- 可以加上開關
   return true
end


function F.func(inp,env)
  local pre_space = ""
  if env.history[1] and not env.history[1]:find(" $") then
    pre_space= " "
  end

   for cand in inp:iter() do
       if #cand.text == utf8.len(cand.txt) then -- 英文候選加空白
           cand.text = pre_space .. cand.text .. " "
        end
        yield( cand )
   end
end

return F

@H4M5TER
Copy link
Author

H4M5TER commented Apr 27, 2023

非常感谢!

我在 schema 里最后加上 lua_filter@pangu_filter
rime.lua 里加上 local pangu_filter = require("pangu")
新建一个 lua 文件夹,在里面新建 pangu.lua 然后把上面的内容贴进去
重新部署之后遇到问题:任意输入都没有候选词

@H4M5TER
Copy link
Author

H4M5TER commented Apr 27, 2023

是否有可能给 select_notifier 传入一个函数,在其中修改即将上屏的候选词?我没翻到相关的接口

@shewer
Copy link
Contributor

shewer commented Apr 28, 2023

可以耶, 測試狀態,但是
大部份 candidate text 是改不了的, 除了 SimpleCandidate

在notifier func 中,加入 engine:commit_text( "--") 會
commit cand 後 commit -- ( 在commit_history 中會增加一個 record type: "raw" text: "--"

你可參考 librime rime/candidate.h librime-lua src/typess.cc CandidateReg set_xxxxx 會檢查 Candidate 型別

@groverlynn
Copy link
Contributor

然而中英文之间不应该有空格

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