fix: selector preview (#2362)

This commit is contained in:
yetone
2025-06-28 20:07:25 +08:00
committed by GitHub
parent e2d160aa83
commit e64b5f054c
4 changed files with 37 additions and 0 deletions

View File

@@ -570,6 +570,11 @@ function M.trim_space(text)
return text:gsub("%s*", "")
end
function M.trim_slashes(text)
if not text then return text end
return text:gsub("//n", "/n"):gsub("//r", "/r"):gsub("//t", "/t"):gsub('/"', '"')
end
---@param original_lines string[]
---@param target_lines string[]
---@param compare_fn fun(line_a: string, line_b: string): boolean
@@ -620,6 +625,20 @@ function M.fuzzy_match(original_lines, target_lines)
target_lines,
function(line_a, line_b) return M.trim_space(line_a) == M.trim_space(line_b) end
)
if start_line ~= nil and end_line ~= nil then return start_line, end_line end
---trim slashes match
start_line, end_line = M.try_find_match(
original_lines,
target_lines,
function(line_a, line_b) return line_a == M.trim_slashes(line_b) end
)
if start_line ~= nil and end_line ~= nil then return start_line, end_line end
---trim slashes and trim_space match
start_line, end_line = M.try_find_match(
original_lines,
target_lines,
function(line_a, line_b) return M.trim_space(line_a) == M.trim_space(M.trim_slashes(line_b)) end
)
return start_line, end_line
end