mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 05:24:24 -05:00
fix(snip): unicode engine edge case
This commit is contained in:
@@ -107,24 +107,23 @@ function M.engine(trigger, opts)
|
|||||||
local first_idx = 1
|
local first_idx = 1
|
||||||
if max_length ~= nil then
|
if max_length ~= nil then
|
||||||
first_idx = #line_full - max_length -- include additional char for wordtrig
|
first_idx = #line_full - max_length -- include additional char for wordtrig
|
||||||
if first_idx < 0 then
|
if first_idx < 1 then
|
||||||
if is_fixed_length then
|
if is_fixed_length then
|
||||||
return nil
|
return nil
|
||||||
else
|
else
|
||||||
first_idx = 1
|
first_idx = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if first_idx > 0 then
|
|
||||||
if string.byte(line_full, first_idx) > 127 then return nil end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
if line_full:byte(first_idx) > 127 then first_idx = 1 end -- avoid splitting bytes within unicode characters
|
||||||
local line = line_full:sub(first_idx)
|
local line = line_full:sub(first_idx)
|
||||||
local whole, captures = base_engine(line, trig)
|
local whole, captures = base_engine(line, trig)
|
||||||
if whole == nil then return nil end
|
if whole == nil then return nil end
|
||||||
|
|
||||||
-- custom word trig
|
-- custom word trig
|
||||||
local from = #line - #whole + 1
|
local from = #line - #whole + 1
|
||||||
if opts.wordTrig and from ~= 1 and string.match(line:sub(from - 1, from - 1), '[%w._]') ~= nil then
|
local first_letter = line:sub(from - 1, from - 1)
|
||||||
|
if opts.wordTrig and from ~= 1 and (first_letter:byte(1) > 127 or first_letter:match('[%w._]') ~= nil) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user