Skip to content

Commit

Permalink
escaping special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Magician11 committed Oct 22, 2024
1 parent 2afa693 commit dcc20ae
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lua/latex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local function wildcard_limited_filter(input, env)
--if prefix~=nil and input_string:sub(1,prefix_len) == prefix then input_string = input_string:sub(1+prefix_len) end
if suffix~=nil and input_string:sub(-1,-suffix_len) == suffix then input_string = input_string:sub(1,-(1+suffix_len)) end
log_error("input_string_new: "..input_string)
local pattern = input_string:gsub(wildcard, ".*") --create pattern that repalce custom wildcard to lua wildcard ".*"
local pattern = input_string:gsub(wildcard, ".*"):gsub("([%-%+%[%]%(%)])", "%%%1") --create pattern that repalce custom wildcard to lua wildcard ".*"
log_error("pattern: "..pattern)
local newcand = {start = context:get_preedit().sel_start, _end = context:get_preedit().sel_end}

Expand Down Expand Up @@ -104,7 +104,8 @@ local function fuzzy_search_filter(input, env)
--if prefix~=nil and input_string:sub(1,prefix_len) == prefix then input_string = input_string:sub(1+prefix_len) end
if suffix~=nil and input_string:sub(-1,-suffix_len) == suffix then input_string = input_string:sub(1,-(1+suffix_len)) end
log_error("input_string_new: "..input_string)
local pattern = input_string:gsub(".", "%0.*") --e.g. \abc -> \.*a.*b.*c.*
--local pattern = input_string:gsub(".", "%0.*") --e.g. \abc -> \.*a.*b.*c.*
local pattern = input_string:gsub(".", "%0.*"):gsub("([%-%+%[%]%(%)])", "%%%1") -- escaping special characters
log_error("pattern: "..pattern)
-- return candidates that match the pattern
for _, cand in pairs(cands) do
Expand Down Expand Up @@ -160,8 +161,8 @@ local function wildcard_search_filter(input, env)
--if prefix~=nil and input_string:sub(1,prefix_len) == prefix then input_string = input_string:sub(1+prefix_len) end
if suffix~=nil and input_string:sub(-1,-suffix_len) == suffix then input_string = input_string:sub(1,-(1+suffix_len)) end
log_error("input_string_new: "..input_string)
-- local pattern = input_string:gsub(".", "%0.*") --e.g. \abc -> \.*a.*b.*c.*
local pattern = input_string:gsub(wildcard, ".*") -- e.g. \*ab*c -> \.*ab.*c.*
-- local pattern = input_string:gsub(wildcard, ".*") -- e.g. \*ab*c -> \.*ab.*c.*
local pattern = input_string:gsub(wildcard, ".*"):gsub("([%-%+%[%]%(%)])", "%%%1") -- escaping special characters
log_error("pattern: "..pattern)
-- return candidates that match the pattern
for _, cand in pairs(cands) do
Expand Down Expand Up @@ -219,6 +220,6 @@ latex_reverse_lookup:
recognizer:
patterns:
latex: "^\\\\[a-zA-Z0-9^_*]*'?$" # *代表任意次 \会直接识别出tag
latex: "^\\\\[<>a-zA-Z0-9^_*()\\[\\]+-]*'?$"
]]--

0 comments on commit dcc20ae

Please sign in to comment.