Skip to content

Commit

Permalink
opti: word_append_space
Browse files Browse the repository at this point in the history
  • Loading branch information
boomker committed Oct 12, 2024
1 parent b400778 commit 3d20ad4
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 54 deletions.
4 changes: 2 additions & 2 deletions lua/fly_fixed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function F.func(input, env)
and first_char_ycode:match(first_syllable_code)
then
yield(cand)
elseif last_char_ycode and last_char_ycode:match(preedit_last_code) then
yield(cand)
-- elseif last_char_ycode and last_char_ycode:match(preedit_last_code) then
-- yield(cand)
else
table.insert(low_priority_cands, cand)
table.insert(hide_emoji_texts, cand_text)
Expand Down
73 changes: 51 additions & 22 deletions lua/word_append_space.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,40 @@ local rime_api_helper = require("tools/rime_api_helper")
local space_leader_word = {}

function space_leader_word.init(env)

env.return_keys = {
["Return"] = true,
["Alt+Return"] = true,
["Control+Return"] = true,
}

env.symbol_keys = {
["35"] = true, -- numbersign
["38"] = true, -- ampersand
["64"] = true, -- at,@
["95"] = true, -- underscore
["minus"] = true,
["slash"] = true,
}
rime_api_helper.reset_commited_cand_state(env)
end

function space_leader_word.func(key, env)
local engine = env.engine
local key_value = key:repr()
local key_code = key.keycode
local context = engine.context
local input_code = context.input
local caret_pos = context.caret_pos
local composition = context.composition
local page_size = engine.schema.page_size
local page_size = engine.schema.page_size
local segment = composition:back()

if input_code:match("^/.*") then return 2 end
if input_code:match("^/.*") then
return 2
end

local current_focus_app = context:get_property("client_app")
local prev_cand_is_null = context:get_property("prev_cand_is_null")
local prev_cand_is_word = context:get_property("prev_cand_is_word")
local prev_cand_is_symbol = context:get_property("prev_cand_is_symbol")
local prev_cand_is_symbol = context:get_property("prev_cand_is_symbol")
local prev_cand_is_chinese = context:get_property("prev_cand_is_chinese")
local prev_cand_is_preedit = context:get_property("prev_cand_is_preedit")

Expand All @@ -44,29 +52,48 @@ function space_leader_word.func(key, env)
context:set_property("prev_cand_is_null", "1")
end

local index = segment.selected_index or 7
local selected_cand_idx = rime_api_helper.get_selected_candidate_index(key_value, index, page_size)
if (#input_code >= 1 ) and (prev_cand_is_symbol == "1") and (selected_cand_idx >= 0) then
local selected_cand = segment:get_candidate_at(selected_cand_idx)
if not selected_cand then return 2 end
local cand_text = selected_cand.text
engine:commit_text(cand_text)
rime_api_helper.set_commited_cand_is_chinese(env)
context:set_property("prev_focus_app", current_focus_app)
context:clear()
return 1 -- kAccepted
end

if (#input_code >= 1) and env.return_keys[key_value] then
local cand_text = input_code
if (prev_cand_is_chinese == "1") or (prev_cand_is_word == "1") then
local commit_text_is_symbol = false
if (prev_cand_is_chinese == "1") or (prev_cand_is_word == "1") or (prev_cand_is_preedit == "1") then
cand_text = " " .. input_code
engine:commit_text(cand_text)
elseif (prev_cand_is_symbol == "1") and (input_code:match("^[%p]+$")) then
engine:commit_text(cand_text)
commit_text_is_symbol = true
else
engine:commit_text(cand_text)
end
rime_api_helper.reset_commited_cand_state(env)
context:set_property("prev_cand_is_preedit", "1")
if commit_text_is_symbol then
context:set_property("prev_cand_is_symbol", "1")
else
context:set_property("prev_cand_is_preedit", "1")
end
context:set_property("prev_focus_app", current_focus_app)
context:clear()
return 1 -- kAccepted
end

if (env.symbol_keys[key_value] or env.symbol_keys[tostring(key_code)]) and (#input_code <= 1) then
rime_api_helper.reset_commited_cand_state(env)
context:set_property("prev_cand_is_symbol", "1")
end

local index = segment.selected_index or 7
local selected_cand_idx = rime_api_helper.get_selected_candidate_index(key_value, index, page_size)
if (#input_code >= 1) and (prev_cand_is_symbol == "1") and (selected_cand_idx >= 0) then
local selected_cand = segment:get_candidate_at(selected_cand_idx)
if not selected_cand then
return 2
end
local cand_text = selected_cand.text
engine:commit_text(cand_text)
if input_code:match("^[%p]+$") then
rime_api_helper.set_commited_cand_is_pairSymbol(env)
else
rime_api_helper.set_commited_cand_is_chinese(env)
end
context:set_property("prev_focus_app", current_focus_app)
context:clear()
return 1 -- kAccepted
Expand Down Expand Up @@ -99,7 +126,9 @@ function space_leader_word.func(key, env)

if #input_code >= 1 and (selected_cand_idx >= 0) then
local selected_cand = segment:get_candidate_at(selected_cand_idx)
if not selected_cand then return 2 end
if not selected_cand then
return 2
end
local cand_text = selected_cand.text

if (prev_cand_is_null ~= "1") and ((prev_cand_is_preedit == "1") or (prev_cand_is_word == "1")) then
Expand Down
50 changes: 25 additions & 25 deletions symbols.custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -498,28 +498,28 @@ symbols:
';fvt' : ["[猪头]"]
';fdg' : ["[蛋糕]"]
';fxk' : ["[破涕为笑]"]
';fnl' : ['🔔'] # bell
';frl' : ['📅'] # clendar
';fyj' : ['👀'] # eye
';fho' : ['🔥'] # fire
';fhj' : ['🚀'] # huojian
';fdp' : ['💡'] # idea
';flb' : ['📢'] # jinggao
';fqm' : ['💰'] # money
';ftd' : ['📌'] # pushpin
';fqz' : ['🚩'] # qizi
';fyz' : ['👉'] # right
';fzr' : ['👉'] # right
';fzl' : ['👈'] # left
';fzu' : ['👆'] # up
';fzd' : ['👇'] # down
';fcd' : ['👎'] # down
';fdc' : ['👎'] # down
';fdz' : ['👍'] # up
';fup' : ['👍'] # up
';fth' : ['❗'] #
';fwh' : ['❓'] # ?
';fdv' : ['✅'] # todo
';fco' : ['❌'] # xx
';fzz' : ['💤'] # zz
';fxx' : ['⭐'] # star
';fnl' : ['🔔'] # bell
';frl' : ['📅'] # clendar
';fyj' : ['👀'] # eye
';fho' : ['🔥'] # fire
';fhj' : ['🚀'] # huojian
';fdp' : ['💡'] # idea
';flb' : ['📢'] # jinggao
';fqm' : ['💰'] # money
';ftd' : ['📌'] # pushpin
';fqz' : ['🚩'] # qizi
';fyz' : ['👉'] # right
';fzr' : ['👉'] # right
';fzl' : ['👈'] # left
';fzu' : ['👆'] # up
';fzd' : ['👇'] # down
';fcd' : ['👎'] # down
';fdc' : ['👎'] # down
';fdz' : ['👍'] # up
';fup' : ['👍'] # up
';fth' : ['❗'] #
';fwh' : ['❓'] # ?
';fdv' : ['✅'] # todo
';fco' : ['❌'] # xx
';fzz' : ['💤'] # zz
';fxx' : ['⭐'] # star
10 changes: 5 additions & 5 deletions weasel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ config_version: "2024-04-19"
# 针对特定应用的设置
app_options:
firefox.exe:
inline_preedit: true # 行内显示预编辑区: 规避 <https://github.com/rime/weasel/issues/946>
inline_preedit: true # 行内显示预编辑区: 规避 <https://github.com/rime/weasel/issues/946>
code.exe:
ascii_mode: true
conhost.exe:
Expand All @@ -27,9 +27,9 @@ app_options:
wechat_flag: true

# [global settings]
global_ascii: false # 切换为 ascii 模式时, 是否影响所有窗口: true; false
show_notifications: true # 是否显示状态变化的通知: true; false; option_list(方案内的开头 option)
show_notifications_time: 1200 # 通知显示的时间, 单位 ms
global_ascii: false # 切换为 ascii 模式时, 是否影响所有窗口: true; false
show_notifications: true # 是否显示状态变化的通知: true; false; option_list(方案内的开头 option)
show_notifications_time: 1200 # 通知显示的时间, 单位 ms
# [End of <global settings>]

# 字体; 候选项、候选窗口的行为、布局及样式
Expand All @@ -40,7 +40,7 @@ style:
# 全局字体
# 格式: 字体1:起始码位:结束码位:字重:字形,字体2……, 字体会依次 fallback
# 详细设定请参考 <https://github.com/rime/weasel/wiki/字體設定>
font_face: "Segoe UI Emoji:30:39, Segoe UI Emoji:23:23, Segoe UI Emoji:2a:2a, Segoe UI Emoji:fe0f:fe0f, Segoe UI Emoji:20e3:20e3, Microsoft YaHei, MiSans, Segoe UI Emoji, Noto Color Emoji"
font_face: "Segoe UI Emoji:30:39, Segoe UI Emoji:23:23, Segoe UI Emoji:2a:2a, Segoe UI Emoji:fe0f:fe0f, Segoe UI Emoji:20e3:20e3, Microsoft YaHei, MiSans, MiSans L3, Segoe UI Emoji, Noto Color Emoji"
label_font_face: "Microsoft YaHei" # 标签字体
comment_font_face: "Microsoft YaHei" # 注释字体
font_point: 11 # 全局字体字号
Expand Down

0 comments on commit 3d20ad4

Please sign in to comment.