-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters