From 546017504ac5bc9181dff5a406bccc9c5b9bb9bb Mon Sep 17 00:00:00 2001 From: mirtlecn Date: Sat, 27 Jul 2024 23:33:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20en=5Fspacer=20=E7=8E=B0=E5=9C=A8?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E5=9C=A8=E4=B8=AD=E8=8B=B1=E6=A0=87=E7=82=B9?= =?UTF-8?q?=E3=80=81=E7=A9=BA=E5=AD=97=E7=AC=A6=E5=89=8D=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/en_spacer.lua | 24 ++++++++++-------------- rime.lua | 4 ++-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lua/en_spacer.lua b/lua/en_spacer.lua index 0a8090a..ae368a5 100644 --- a/lua/en_spacer.lua +++ b/lua/en_spacer.lua @@ -1,20 +1,16 @@ --- 这个 Lua 给英文单词后面自动加一个空格 #496 +-- 中文或者英文后,再输入英文单词自动添加空格 +local F = {} -local function add_space_to_english_word(input) - -- 匹配纯英文单词(don't 算纯英文单词)并在单词后添加空格 - input = input:gsub("(%a+'?%a*)", "%1 ") - return input -end - --- 在候选项上屏时触发的函数 -local function en_spacer(input, env) +function F.func( input, env ) + local latest_text = env.engine.context.commit_history:latest_text() for cand in input:iter() do - if cand.text:match("^[%a']+[%a']*$") then - -- 如果候选项是纯英文单词,则在输入后添加一个空格 - cand = cand:to_shadow_candidate(cand.type, add_space_to_english_word(cand.text), cand.comment) + if cand.text:match( '^[%a\']+[%a\']*$' ) and latest_text and #latest_text > 0 and + not latest_text:find( '[%p%s。,;?:—!《》‘’“”、¥…()【】「」『』]$' ) then + cand = cand:to_shadow_candidate( 'en_spacer', cand.text:gsub( '(%a+\'?%a*)', ' %1' ), cand.comment ) end - yield(cand) + yield( cand ) end end -return en_spacer +return F + diff --git a/rime.lua b/rime.lua index aadf369..92262a1 100644 --- a/rime.lua +++ b/rime.lua @@ -50,8 +50,8 @@ long_word_filter = require("long_word_filter") -- 在 engine/filters 增加 - lua_filter@cn_en_spacer cn_en_spacer = require("cn_en_spacer") --- 英文词条上屏自动空格 --- 在 engine/filters 增加 - lua_filter@en_spacer +-- 英文词条上屏自动添加空格 +-- 在 engine/filters 的倒数第二个位置,增加 - lua_filter@en_spacer en_spacer = require("en_spacer") -- 九宫格,将输入框的数字转为对应的拼音或英文,iRime 用,Hamster 不需要。