Skip to content

Commit

Permalink
Update no quick word
Browse files Browse the repository at this point in the history
  • Loading branch information
forFudan committed May 16, 2024
1 parent c101082 commit e2f816c
Show file tree
Hide file tree
Showing 5 changed files with 5,813 additions and 4,003 deletions.
45 changes: 30 additions & 15 deletions beta/schema/lua/yuhao/yuhao_auto_select.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
-- 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: 當字數超過一定數量時,下一擊自動選擇第二候選項.
--[[
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, 譚淞宸: 當字數超過一定數量時,下一擊自動選擇第二候選項.
20240514, 朱宇浩: 注意到有時第二選項並不是第一選項的頭幾個字,用户可能在
不覺中上屏了其他的字.因此進行一個判斷,只有當第二選項是第一個選項的
頭幾個字的時候纔會選擇上屏.用户可以指定候選區最多顯示的漢字數.
---------------------------------------
]]

local core = require("yuhao.yuhao_core")

local this = {}

function this.init(env)
local config = env.engine.schema.config
env.max_chars = config:get_int('yuhao_auto_select/max_chars') or 8
end

local number_of_chars_to_display = 8
local kNoop = 2

function startswith(text, start)
return text:sub(1, #start) == start
end

---@param key_event KeyEvent
---@param env Env
function this.func(key_event, env)
Expand All @@ -41,10 +53,13 @@ function this.func(key_event, env)
if not first_candidate or not second_candidate then
return kNoop
end
if utf8.len(first_candidate.text) < number_of_chars_to_display then
if utf8.len(first_candidate.text) < env.max_chars then
return kNoop
end
if core.string_starts_with(first_candidate.text, second_candidate.text) then
env.engine:process_key(KeyEvent('2'))
return kNoop
end
env.engine:process_key(KeyEvent('2'))
return kNoop
end

Expand Down
Loading

0 comments on commit e2f816c

Please sign in to comment.