fix: from_entry escape and validation (#2058)
This commit is contained in:
@@ -12,13 +12,7 @@ local from_entry = {}
|
|||||||
|
|
||||||
function from_entry.path(entry, validate, escape)
|
function from_entry.path(entry, validate, escape)
|
||||||
escape = vim.F.if_nil(escape, true)
|
escape = vim.F.if_nil(escape, true)
|
||||||
local path
|
local path = entry.path
|
||||||
if escape then
|
|
||||||
path = entry.path and vim.fn.fnameescape(entry.path) or nil
|
|
||||||
else
|
|
||||||
path = entry.path
|
|
||||||
end
|
|
||||||
|
|
||||||
if path == nil then
|
if path == nil then
|
||||||
path = entry.filename
|
path = entry.filename
|
||||||
end
|
end
|
||||||
@@ -35,7 +29,9 @@ function from_entry.path(entry, validate, escape)
|
|||||||
if validate and invalid == 0 then
|
if validate and invalid == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if escape then
|
||||||
|
return vim.fn.fnameescape(path)
|
||||||
|
end
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -415,11 +415,11 @@ previewers.cat = defaulter(function(opts)
|
|||||||
return previewers.new_buffer_previewer {
|
return previewers.new_buffer_previewer {
|
||||||
title = "File Preview",
|
title = "File Preview",
|
||||||
dyn_title = function(_, entry)
|
dyn_title = function(_, entry)
|
||||||
return Path:new(from_entry.path(entry, true)):normalize(cwd)
|
return Path:new(from_entry.path(entry, false, false)):normalize(cwd)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_buffer_by_name = function(_, entry)
|
get_buffer_by_name = function(_, entry)
|
||||||
return from_entry.path(entry, true)
|
return from_entry.path(entry, false)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
define_preview = function(self, entry, status)
|
define_preview = function(self, entry, status)
|
||||||
@@ -454,11 +454,11 @@ previewers.vimgrep = defaulter(function(opts)
|
|||||||
return previewers.new_buffer_previewer {
|
return previewers.new_buffer_previewer {
|
||||||
title = "Grep Preview",
|
title = "Grep Preview",
|
||||||
dyn_title = function(_, entry)
|
dyn_title = function(_, entry)
|
||||||
return Path:new(from_entry.path(entry, true)):normalize(cwd)
|
return Path:new(from_entry.path(entry, false, false)):normalize(cwd)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_buffer_by_name = function(_, entry)
|
get_buffer_by_name = function(_, entry)
|
||||||
return from_entry.path(entry, true)
|
return from_entry.path(entry, false)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
define_preview = function(self, entry, status)
|
define_preview = function(self, entry, status)
|
||||||
|
|||||||
@@ -250,11 +250,11 @@ previewers.cat = defaulter(function(opts)
|
|||||||
return previewers.new_termopen_previewer {
|
return previewers.new_termopen_previewer {
|
||||||
title = "File Preview",
|
title = "File Preview",
|
||||||
dyn_title = function(_, entry)
|
dyn_title = function(_, entry)
|
||||||
return Path:new(from_entry.path(entry, true)):normalize(cwd)
|
return Path:new(from_entry.path(entry, false, false)):normalize(cwd)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_command = function(entry)
|
get_command = function(entry)
|
||||||
local p = from_entry.path(entry, true)
|
local p = from_entry.path(entry, true, false)
|
||||||
if p == nil or p == "" then
|
if p == nil or p == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -273,14 +273,14 @@ previewers.vimgrep = defaulter(function(opts)
|
|||||||
return previewers.new_termopen_previewer {
|
return previewers.new_termopen_previewer {
|
||||||
title = "Grep Preview",
|
title = "Grep Preview",
|
||||||
dyn_title = function(_, entry)
|
dyn_title = function(_, entry)
|
||||||
return Path:new(from_entry.path(entry, true)):normalize(cwd)
|
return Path:new(from_entry.path(entry, false, false)):normalize(cwd)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_command = function(entry, status)
|
get_command = function(entry, status)
|
||||||
local win_id = status.preview_win
|
local win_id = status.preview_win
|
||||||
local height = vim.api.nvim_win_get_height(win_id)
|
local height = vim.api.nvim_win_get_height(win_id)
|
||||||
|
|
||||||
local p = from_entry.path(entry, true)
|
local p = from_entry.path(entry, true, false)
|
||||||
if p == nil or p == "" then
|
if p == nil or p == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -308,14 +308,14 @@ previewers.qflist = defaulter(function(opts)
|
|||||||
return previewers.new_termopen_previewer {
|
return previewers.new_termopen_previewer {
|
||||||
title = "Grep Preview",
|
title = "Grep Preview",
|
||||||
dyn_title = function(_, entry)
|
dyn_title = function(_, entry)
|
||||||
return Path:new(from_entry.path(entry, true)):normalize(cwd)
|
return Path:new(from_entry.path(entry, false, false)):normalize(cwd)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get_command = function(entry, status)
|
get_command = function(entry, status)
|
||||||
local win_id = status.preview_win
|
local win_id = status.preview_win
|
||||||
local height = vim.api.nvim_win_get_height(win_id)
|
local height = vim.api.nvim_win_get_height(win_id)
|
||||||
|
|
||||||
local p = from_entry.path(entry, true)
|
local p = from_entry.path(entry, true, false)
|
||||||
if p == nil or p == "" then
|
if p == nil or p == "" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user