Skip to content

Commit

Permalink
fix(lua): 分號處理器不應該依賴於 selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ksqsf committed Dec 7, 2024
1 parent 1ed54f4 commit 95d8d60
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lua/moran_semicolon_processor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- Synopsis: 選擇第二個首選項,但可用於跳過 emoji 濾鏡產生的候選
-- Author: ksqsf
-- License: MIT license
-- Version: 0.1.2
-- Version: 0.1.3

-- NOTE: This processor depends on, and thus should be placed before,
-- the built-in "selector" processor.
Expand Down Expand Up @@ -35,15 +35,16 @@ local function processor(key_event, env)

-- Special case: if there is only one candidate, just select it!
if menu:candidate_count() == 1 then
env.engine:process_key(KeyEvent("1"))
context:select(0)
return kAccepted
end

-- If it is not the first page, simply send 2.
local page_size = env.engine.schema.page_size
local selected_index = segment.selected_index
if selected_index >= page_size then
env.engine:process_key(KeyEvent("2"))
local page_num = selected_index // page_size
context:select(page_num * page_size + 1)
return kAccepted
end

Expand All @@ -57,14 +58,14 @@ local function processor(key_event, env)
or (codepoint >= 97 and codepoint <= 122)
or (codepoint >= 65 and codepoint <= 90)
then
env.engine:process_key(KeyEvent(tostring(i+1)))
context:select(i)
return kAccepted
end
i = i + 1
end

-- No good candidates found. Just select the second candidate.
env.engine:process_key(KeyEvent("2"))
context:select(1)
return kAccepted
end

Expand Down

0 comments on commit 95d8d60

Please sign in to comment.