Skip to content

Commit

Permalink
Reset char filter
Browse files Browse the repository at this point in the history
  • Loading branch information
forFudan committed May 12, 2024
1 parent 40a11ed commit aa4232b
Show file tree
Hide file tree
Showing 19 changed files with 19,436 additions and 424 deletions.
51 changes: 51 additions & 0 deletions beta/schema/lua/yuhao/yuhao_auto_select.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- Name: yuhao_auto_select.lua
-- 名稱: 自動選擇候選項
-- Version: 20240510
-- Author: 譚淞宸 <https://github.com/tansongchen>
-- Purpose: 對於過長的整句輸入,當字數超過一定數量時,下一擊自動選擇第二候選項.
-- 這個插件可使得第一候選項的字數不超過8.
-- 版權聲明:
-- 專爲宇浩輸入法製作 <https://yuhao.forfudan.com>
-- 轉載請保留作者名和出處
-- Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International
-- 版本:
-- 20240510: 當字數超過一定數量時,下一擊自動選擇第二候選項.
---------------------------------------

local this = {}

function this.init(env)
end

local number_of_chars_to_display = 8
local kNoop = 2

---@param key_event KeyEvent
---@param env Env
function this.func(key_event, env)
local context = env.engine.context
-- 只接受单个字母键
if key_event:release() or key_event:alt() or key_event:ctrl() or key_event:shift() or key_event:caps() then
return kNoop
end
if key_event.keycode < ('a'):byte() or key_event.keycode > ('z'):byte() then
return kNoop
end
-- 取出输入中当前正在翻译的一部分
local segment = context.composition:toSegmentation():back();
if not segment then
return kNoop
end
local first_candidate = segment:get_candidate_at(0)
local second_candidate = segment:get_candidate_at(1)
if not first_candidate or not second_candidate then
return kNoop
end
if utf8.len(first_candidate.text) < number_of_chars_to_display then
return kNoop
end
env.engine:process_key(KeyEvent('2'))
return kNoop
end

return this
117 changes: 117 additions & 0 deletions beta/schema/lua/yuhao/yuhao_char_filter.lua

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions beta/schema/lua/yuhao/yuhao_charset_filter.lua

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions beta/schema/lua/yuhao/yuhao_charset_filter_common.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local yuhao_charset_filter = require("yuhao.yuhao_charset_filter")
return yuhao_charset_filter.yuhao_charset_filter_common
2 changes: 2 additions & 0 deletions beta/schema/lua/yuhao/yuhao_charset_filter_tonggui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local yuhao_charset_filter = require("yuhao.yuhao_charset_filter")
return yuhao_charset_filter.yuhao_charset_filter_tonggui
Loading

0 comments on commit aa4232b

Please sign in to comment.