Escape parentheses from titles when searching for backlinks

This commit is contained in:
Anderson Lizarazo Tellez
2023-10-30 10:58:06 -05:00
committed by Anderson Lizarazo Tellez
parent 3fd50c62c1
commit d6e4990425

View File

@@ -1873,12 +1873,16 @@ local function ShowBacklinks(opts)
local title = local title =
Pinfo:new({ filepath = vim.fn.expand("%:p"), M.Cfg }).title Pinfo:new({ filepath = vim.fn.expand("%:p"), M.Cfg }).title
-- or vim.api.nvim_buf_get_name(0) -- or vim.api.nvim_buf_get_name(0)
local escaped_title = string.gsub(title, "%(", "\\(")
escaped_title = string.gsub(escaped_title, "%)", "\\)")
builtin.live_grep({ builtin.live_grep({
results_title = "Backlinks to " .. title, results_title = "Backlinks to " .. title,
prompt_title = "Search", prompt_title = "Search",
cwd = M.Cfg.home, cwd = M.Cfg.home,
search_dirs = { M.Cfg.home }, search_dirs = { M.Cfg.home },
default_text = "\\[\\[" .. title .. "([#|].+)?\\]\\]", default_text = "\\[\\[" .. escaped_title .. "([#|].+)?\\]\\]",
find_command = M.Cfg.find_command, find_command = M.Cfg.find_command,
attach_mappings = function(_, map) attach_mappings = function(_, map)
actions.select_default:replace(picker_actions.select_default) actions.select_default:replace(picker_actions.select_default)