From 65e32958269d48e54ba75e95633d587a05d0d14f Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Thu, 16 Jan 2025 23:09:50 +0100 Subject: [PATCH] fix(snip): unicode matching problems --- lua/typstar/autosnippets.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/typstar/autosnippets.lua b/lua/typstar/autosnippets.lua index 5c81d28..b292ae2 100644 --- a/lua/typstar/autosnippets.lua +++ b/lua/typstar/autosnippets.lua @@ -91,7 +91,15 @@ function M.engine(trigger, opts) -- matching return function(line, trig) if not M.snippets_toggle or not condition() then return nil end - if fixed_length ~= nil then line = line:sub(#line - fixed_length) end + if fixed_length ~= nil then + local first_idx = #line - fixed_length -- include additional char for wordtrig + if first_idx < 0 then + return nil + elseif first_idx > 0 then + if string.byte(line, first_idx) > 127 then return nil end + end + line = line:sub(first_idx) + end local whole, captures = base_engine(line, trig) if whole == nil then return nil end