first commit
This commit is contained in:
BIN
Rime/lua/._candidate_sorting
Normal file
BIN
Rime/lua/._candidate_sorting
Normal file
Binary file not shown.
BIN
Rime/lua/._date_translator.lua
Normal file
BIN
Rime/lua/._date_translator.lua
Normal file
Binary file not shown.
BIN
Rime/lua/._select_character.lua
Normal file
BIN
Rime/lua/._select_character.lua
Normal file
Binary file not shown.
BIN
Rime/lua/._unicode_input.lua
Normal file
BIN
Rime/lua/._unicode_input.lua
Normal file
Binary file not shown.
BIN
Rime/lua/candidate_sorting/._long_phrase_first.lua
Normal file
BIN
Rime/lua/candidate_sorting/._long_phrase_first.lua
Normal file
Binary file not shown.
BIN
Rime/lua/candidate_sorting/._single_char_first.lua
Normal file
BIN
Rime/lua/candidate_sorting/._single_char_first.lua
Normal file
Binary file not shown.
BIN
Rime/lua/candidate_sorting/._single_char_only.lua
Normal file
BIN
Rime/lua/candidate_sorting/._single_char_only.lua
Normal file
Binary file not shown.
30
Rime/lua/candidate_sorting/long_phrase_first.lua
Normal file
30
Rime/lua/candidate_sorting/long_phrase_first.lua
Normal file
@@ -0,0 +1,30 @@
|
||||
--- 过滤器:最长词组和单字在先
|
||||
local function long_phrase_first(input)
|
||||
local l = {}
|
||||
local s = {}
|
||||
local c = {}
|
||||
local max = 1
|
||||
for cand in input:iter() do
|
||||
if (utf8.len(cand.text) > max) then
|
||||
max = utf8.len(cand.text)
|
||||
end
|
||||
if (utf8.len(cand.text) == 1) then
|
||||
table.insert(c, cand)
|
||||
elseif (utf8.len(cand.text) < max) then
|
||||
table.insert(s, cand)
|
||||
else
|
||||
table.insert(l, cand)
|
||||
end
|
||||
end
|
||||
for i, cand in ipairs(l) do
|
||||
yield(cand)
|
||||
end
|
||||
for i, cand in ipairs(c) do
|
||||
yield(cand)
|
||||
end
|
||||
for i, cand in ipairs(s) do
|
||||
yield(cand)
|
||||
end
|
||||
end
|
||||
|
||||
return long_phrase_first
|
||||
16
Rime/lua/candidate_sorting/single_char_first.lua
Normal file
16
Rime/lua/candidate_sorting/single_char_first.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
--- 过滤器:单字在先
|
||||
local function single_char_first(input)
|
||||
local l = {}
|
||||
for cand in input:iter() do
|
||||
if (utf8.len(cand.text) == 1) then
|
||||
yield(cand)
|
||||
else
|
||||
table.insert(l, cand)
|
||||
end
|
||||
end
|
||||
for i, cand in ipairs(l) do
|
||||
yield(cand)
|
||||
end
|
||||
end
|
||||
|
||||
return single_char_first
|
||||
10
Rime/lua/candidate_sorting/single_char_only.lua
Normal file
10
Rime/lua/candidate_sorting/single_char_only.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
--- 过滤器:只显示单字
|
||||
local function single_char_only(input)
|
||||
for cand in input:iter() do
|
||||
if (utf8.len(cand.text) == 1) then
|
||||
yield(cand)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return single_char_only
|
||||
46
Rime/lua/date_translator.lua
Normal file
46
Rime/lua/date_translator.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
-- date_translator: 时间/日期快捷输入
|
||||
|
||||
local function date_translator(input, seg)
|
||||
if (input == "date") then
|
||||
--- Candidate(type, start, end, text, comment)
|
||||
yield(Candidate("date", seg.start, seg._end, os.date("%Y-%m-%d"), ""))
|
||||
yield(Candidate("date", seg.start, seg._end, os.date("%Y年%m月%d日"), ""))
|
||||
yield(Candidate("date", seg.start, seg._end, os.date("%Y%m%d"), ""))
|
||||
end
|
||||
if (input == "time") then
|
||||
--- Candidate(type, start, end, text, comment)
|
||||
yield(Candidate("time", seg.start, seg._end, os.date("%H:%M:%S"), ""))
|
||||
yield(Candidate("time", seg.start, seg._end, os.date("%H时%M分%S秒"), ""))
|
||||
yield(Candidate("time", seg.start, seg._end, os.date("%H%M%S"), ""))
|
||||
end
|
||||
if (input == "timestamp") then
|
||||
--- Candidate(type, start, end, text, comment)
|
||||
yield(Candidate("time", seg.start, seg._end, os.time(), ""))
|
||||
end
|
||||
if (input == "datetime") then
|
||||
--- Candidate(type, start, end, text, comment)
|
||||
yield(Candidate("datetime", seg.start, seg._end, os.date("%Y-%m-%d %H:%M:%S"), ""))
|
||||
yield(Candidate("datetime", seg.start, seg._end, os.date("%Y-%m-%dT%H:%M:%S+08:00"), ""))
|
||||
yield(Candidate("datetime", seg.start, seg._end, os.date("%Y%m%d%H%M"), ""))
|
||||
end
|
||||
|
||||
-- 输入星期
|
||||
-- -- @JiandanDream
|
||||
-- -- https://github.com/KyleBing/rime-wubi86-jidian/issues/54
|
||||
if (input == "week") then
|
||||
local weekTab = {'日', '一', '二', '三', '四', '五', '六', '七'}
|
||||
yield(Candidate("week", seg.start, seg._end, "周" .. weekTab[tonumber(os.date("%w") + 1)], ""))
|
||||
yield(Candidate("week", seg.start, seg._end, "星期" .. weekTab[tonumber(os.date("%w") + 1)], ""))
|
||||
yield(Candidate("week", seg.start, seg._end, os.date("%A"), ""))
|
||||
yield(Candidate("week", seg.start, seg._end, os.date("%a"), ""))
|
||||
yield(Candidate("week", seg.start, seg._end, os.date("%W"), "周数"))
|
||||
end
|
||||
|
||||
-- 输入月份英文
|
||||
if (input == "month") then
|
||||
yield(Candidate("month", seg.start, seg._end, os.date("%B"), ""))
|
||||
yield(Candidate("month", seg.start, seg._end, os.date("%b"), ""))
|
||||
end
|
||||
end
|
||||
|
||||
return date_translator
|
||||
93
Rime/lua/select_character.lua
Normal file
93
Rime/lua/select_character.lua
Normal file
@@ -0,0 +1,93 @@
|
||||
-- select_character: 以词定字
|
||||
-- 详见: https://github.com/BlindingDark/rime-lua-select-character
|
||||
|
||||
-- http://lua-users.org/lists/lua-l/2014-04/msg00590.html
|
||||
local function utf8_sub(s, i, j)
|
||||
i = i or 1
|
||||
j = j or -1
|
||||
|
||||
if i < 1 or j < 1 then
|
||||
local n = utf8.len(s)
|
||||
if not n then
|
||||
return nil
|
||||
end
|
||||
if i < 0 then
|
||||
i = n + 1 + i
|
||||
end
|
||||
if j < 0 then
|
||||
j = n + 1 + j
|
||||
end
|
||||
if i < 0 then
|
||||
i = 1
|
||||
elseif i > n then
|
||||
i = n
|
||||
end
|
||||
if j < 0 then
|
||||
j = 1
|
||||
elseif j > n then
|
||||
j = n
|
||||
end
|
||||
end
|
||||
|
||||
if j < i then
|
||||
return ""
|
||||
end
|
||||
|
||||
i = utf8.offset(s, i)
|
||||
j = utf8.offset(s, j + 1)
|
||||
|
||||
if i and j then
|
||||
return s:sub(i, j - 1)
|
||||
elseif i then
|
||||
return s:sub(i)
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
local function first_character(s)
|
||||
return utf8_sub(s, 1, 1)
|
||||
end
|
||||
|
||||
local function last_character(s)
|
||||
return utf8_sub(s, -1, -1)
|
||||
end
|
||||
|
||||
local function get_commit_text(context, fun)
|
||||
local candidate_text = context:get_selected_candidate().text
|
||||
local selected_character = fun(candidate_text)
|
||||
|
||||
context:clear_previous_segment()
|
||||
local commit_text = context:get_commit_text()
|
||||
|
||||
context:clear()
|
||||
|
||||
return commit_text .. selected_character
|
||||
end
|
||||
|
||||
local function select_character(key, env)
|
||||
local engine = env.engine
|
||||
local context = engine.context
|
||||
local config = engine.schema.config
|
||||
|
||||
local first_key = config:get_string('key_binder/select_first_character') or 'bracketleft'
|
||||
local last_key = config:get_string('key_binder/select_last_character') or 'bracketright'
|
||||
|
||||
local commit_text = context:get_commit_text()
|
||||
|
||||
if (key:repr() == first_key and commit_text ~= "") then
|
||||
engine:commit_text(get_commit_text(context, first_character))
|
||||
|
||||
return 1 -- kAccepted
|
||||
end
|
||||
|
||||
if (key:repr() == last_key and commit_text ~= "") then
|
||||
engine:commit_text(get_commit_text(context, last_character))
|
||||
|
||||
return 1 -- kAccepted
|
||||
end
|
||||
|
||||
return 2 -- kNoop
|
||||
end
|
||||
|
||||
return select_character
|
||||
19
Rime/lua/unicode_input.lua
Normal file
19
Rime/lua/unicode_input.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Unicode 输入支持
|
||||
-- -- @shewer
|
||||
-- -- https://github.com/shewer/librime-lua-script/blob/main/lua/component/unicode.lua
|
||||
local function unicode_input(input, seg, env)
|
||||
local ucodestr = seg:has_tag("unicode") and input:match("U(%x+)")
|
||||
if ucodestr and #ucodestr > 1 then
|
||||
local code = tonumber(ucodestr, 16)
|
||||
local text = utf8.char(code)
|
||||
yield(Candidate("unicode", seg.start, seg._end, text, string.format("U%x", code)))
|
||||
if #ucodestr < 5 then
|
||||
for i = 0, 15 do
|
||||
local text = utf8.char(code * 16 + i)
|
||||
yield(Candidate("unicode", seg.start, seg._end, text, string.format("U%x~%x", code, i)))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return unicode_input
|
||||
Reference in New Issue
Block a user