misc previewer title display improvements, grep 'no_esc' option added

main
bhagwan 3 years ago
parent 93ca0a3adf
commit a0f073950b

@ -24,7 +24,9 @@ function M.to_matching_str(path)
end
function M.join(paths)
return table.concat(paths, M.separator())
-- gsub to remove double separator
return table.concat(paths, M.separator()):gsub(
M.separator()..M.separator(), M.separator())
end
function M.split(path)

@ -84,6 +84,9 @@ end
function Previewer:update_border(entry)
if self.title then
if self.opts.cwd then
entry.path = path.relative(entry.path, self.opts.cwd)
end
local title = (' %s '):format(entry.path)
if entry.bufnr then
-- local border_width = api.nvim_win_get_width(self.win.preview_winid)

@ -36,7 +36,7 @@ local get_grep_cmd = function(opts, search_query, no_esc)
end
if search_query == nil then search_query = '""'
elseif not no_esc then
elseif not no_esc and not opts.no_esc then
search_query = '"' .. utils.rg_escape(search_query) .. '"'
end

@ -341,6 +341,8 @@ function FzfWin:redraw_preview()
self.border_buf = self:update_border_buf()
self.preview_winid = api.nvim_open_win(tmp_buf, false, self.prev_winopts)
self.border_winid = api.nvim_open_win(self.border_buf, false, self.border_winopts)
-- nowrap border or long filenames will mess things up
api.nvim_win_set_option(self.border_winid, 'wrap', false)
end
self:reset_win_highlights(self.border_winid, true)
self:reset_win_highlights(self.preview_winid)
@ -485,8 +487,13 @@ end
function FzfWin:update_title(title)
self:update_border_buf()
local right_pad = 7
local border_buf = api.nvim_win_get_buf(self.border_winid)
local top = api.nvim_buf_get_lines(border_buf, 0, 1, 0)[1]
local width = fn.strwidth(top)
if #title > width-right_pad then
title = title:sub(1, width-right_pad) .. " "
end
local prefix = fn.strcharpart(top, 0, 3)
local suffix = fn.strcharpart(top, fn.strwidth(title) + 3, fn.strwidth(top))
title = ('%s%s%s'):format(prefix, title, suffix)

Loading…
Cancel
Save