Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Jan 5, 2025
1 parent e1eab46 commit e32b0f4
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 356 deletions.
2 changes: 1 addition & 1 deletion OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Scrollbar style in the builtin previewer, set to `false` to disable, possible va

#### globals.winopts.preview.scrolloff

Type: `number`, Default: `-2`
Type: `number`, Default: `-1`

Float style scrollbar offset from the right edge of the preview window.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ winopts = {
scrollbar = 'float', -- `false` or string:'float|border'
-- float: in-window floating border
-- border: in-border "block" marker
scrolloff = '-2', -- float scrollbar offset from right
scrolloff = -1, -- float scrollbar offset from right
-- applies only when scrollbar = 'float'
delay = 20, -- delay(ms) displaying the preview
-- prevents lag on fast scrolling
Expand Down
4 changes: 2 additions & 2 deletions doc/fzf-lua-opts.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 December 18
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2024 December 27

==============================================================================
Table of Contents *fzf-lua-opts-table-of-contents*
Expand Down Expand Up @@ -504,7 +504,7 @@ values are `float|border`.

globals.winopts.preview.scrolloff*fzf-lua-opts-globals.winopts.preview.scrolloff*

Type: `number`, Default: `-2`
Type: `number`, Default: `-1`

Float style scrollbar offset from the right edge of the preview window.

Expand Down
25 changes: 1 addition & 24 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ M.defaults = {
title = true,
title_pos = "center",
scrollbar = "border",
scrolloff = "-2",
scrolloff = -1,
-- default preview delay, fzf native previewers has a 100ms delay:
-- https://github.com/junegunn/fzf/issues/2417#issuecomment-809886535
delay = 20,
Expand Down Expand Up @@ -1255,27 +1255,4 @@ M.defaults.__HLS = {
}
}

M.defaults.__WINOPTS = {
borderchars = {
["none"] = { "", "", "", "", "", "", "", "" },
["empty"] = { " ", " ", " ", " ", " ", " ", " ", " " },
["single"] = { "", "", "", "", "", "", "", "" },
["double"] = { "", "", "", "", "", "", "", "" },
["rounded"] = { "", "", "", "", "", "", "", "" },
["thicc"] = { "", "", "", "", "", "", "", "" },
["thiccc"] = { "", "", "", "", "", "", "", "" },
["thicccc"] = { "", "", "", "", "", "", "", "" },
},
-- border chars reverse lookup for ambiwidth="double"
border2string = {
[" "] = "empty",
[""] = "single",
[""] = "double",
[""] = "rounded",
[""] = "double",
[""] = "double",
[""] = "double",
},
}

return M
72 changes: 36 additions & 36 deletions lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ function TSContext.update(winid, bufnr, opts)
TSContext._winids[tostring(winid)] = bufnr
end
end
if TSContext.is_attached(winid) == bufnr then
-- NOTE: when previewer win has border, calling `open` on the same win/buf combo
-- while using `winopts.previewer.border=none` or "noboder" works correctly, most
-- likely an upstream issue and we've seen no cooperation from upstream so defer
-- to the same "hack"
-- local open_once = false
local open_once = TSContext.is_attached(winid) == bufnr
if open_once then
open()
else
-- HACK: but the entire nvim-treesitter-context is essentially a hack
-- https://github.com/ibhagwan/fzf-lua/issues/1552#issuecomment-2525456813
for _, t in ipairs({ 0, 20 }) do
for _, t in ipairs({ 0, 20, 50 }) do
vim.defer_fn(function() open() end, t)
end
end
Expand Down Expand Up @@ -322,8 +328,7 @@ function Previewer.base:clear_preview_buf(newbuf)
retbuf = self:get_tmp_buffer()
utils.win_set_buf_noautocmd(self.win.preview_winid, retbuf)
-- redraw the title line and clear the scrollbar
self.win:redraw_preview_border()
self.win:update_scrollbar(true)
self.win:update_preview_scrollbar(true)
end
-- since our temp buffers have 'bufhidden=wipe' the tmp
-- buffer will be automatically wiped and 'nvim_buf_is_valid'
Expand Down Expand Up @@ -372,10 +377,6 @@ function Previewer.base:display_entry(entry_str)
local populate_preview_buf = function(entry_str_)
if not self.win or not self.win:validate_preview() then return end

-- redraw the preview border, resets title
-- border scrollbar and border highlights
self.win:redraw_preview_border()

-- specialized previewer populate function
self:populate_preview_buf(entry_str_)

Expand Down Expand Up @@ -519,7 +520,7 @@ function Previewer.base:scroll(direction)
end
self:update_ts_context()
self:update_render_markdown()
self.win:update_scrollbar()
self.win:update_preview_scrollbar()
end

function Previewer.base:ts_ctx_toggle()
Expand Down Expand Up @@ -1078,31 +1079,29 @@ function Previewer.buffer_or_file:set_cursor_hl(entry)
end)
end

function Previewer.buffer_or_file:update_border(entry)
if self.title then
local filepath = entry.path
if filepath then
if filepath:match("^%[DEBUG]") then
filepath = "[DEBUG]"
else
if self.opts.cwd then
filepath = path.relative_to(entry.path, self.opts.cwd)
end
filepath = path.HOME_to_tilde(filepath)
function Previewer.buffer_or_file:update_title(entry)
if not self.title then return end
local filepath = entry.path
if filepath then
if filepath:match("^%[DEBUG]") then
filepath = "[DEBUG]"
else
if self.opts.cwd then
filepath = path.relative_to(entry.path, self.opts.cwd)
end
filepath = path.HOME_to_tilde(filepath)
end
local title = filepath or entry.uri or entry.bufname
-- was transform function defined?
if self.title_fnamemodify then
local wincfg = vim.api.nvim_win_get_config(self.win.border_winid)
title = self.title_fnamemodify(title, wincfg and wincfg.width)
end
if entry.bufnr then
title = string.format("buf %d: %s", entry.bufnr, title)
end
self.win:update_title(" " .. title .. " ")
end
self.win:update_scrollbar(entry.no_scrollbar)
local title = filepath or entry.uri or entry.bufname
-- was transform function defined?
if self.title_fnamemodify then
local wincfg = vim.api.nvim_win_get_config(self.win.preview_winid)
title = self.title_fnamemodify(title, wincfg and wincfg.width)
end
if entry.bufnr then
title = string.format("buf %d: %s", entry.bufnr, title)
end
self.win:update_preview_title(" " .. title .. " ")
end

function Previewer.buffer_or_file:preview_buf_post(entry, min_winopts)
Expand All @@ -1127,7 +1126,8 @@ function Previewer.buffer_or_file:preview_buf_post(entry, min_winopts)
end
end

self:update_border(entry)
self:update_title(entry)
self.win:update_preview_scrollbar(entry.no_scrollbar)

-- save the loaded entry so we can compare
-- bufnr|path with the next entry. If equal
Expand Down Expand Up @@ -1222,7 +1222,7 @@ function Previewer.man_pages:populate_preview_buf(entry_str)
vim.api.nvim_buf_set_lines(tmpbuf, 0, -1, false, output)
vim.bo[tmpbuf].filetype = self.filetype
self:set_preview_buf(tmpbuf)
self.win:update_scrollbar()
self.win:update_preview_scrollbar()
end

Previewer.marks = Previewer.buffer_or_file:extend()
Expand Down Expand Up @@ -1393,7 +1393,7 @@ function Previewer.highlights:populate_preview_buf(entry_str)
self.orig_pos = api.nvim_win_get_cursor(0)
utils.zz()
end)
self.win:update_scrollbar()
self.win:update_preview_scrollbar()
end

Previewer.quickfix = Previewer.base:extend()
Expand Down Expand Up @@ -1444,8 +1444,8 @@ function Previewer.quickfix:populate_preview_buf(entry_str)
vim.api.nvim_buf_set_lines(self.tmpbuf, 0, -1, false, lines)
vim.bo[self.tmpbuf].filetype = "qf"
self:set_preview_buf(self.tmpbuf)
self.win:update_title(string.format("%s: %s", nr, qf_list.title))
self.win:update_scrollbar()
self.win:update_preview_title(string.format("%s: %s", nr, qf_list.title))
self.win:update_preview_scrollbar()
end

Previewer.autocmds = Previewer.buffer_or_file:extend()
Expand Down
4 changes: 2 additions & 2 deletions lua/fzf-lua/previewer/codeaction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ function M.builtin:populate_preview_buf(entry_str)
vim.api.nvim_buf_set_lines(self.tmpbuf, 0, -1, false, lines)
vim.bo[self.tmpbuf].filetype = "git"
self:set_preview_buf(self.tmpbuf)
self.win:update_title(string.format(" Action #%d ", idx))
self.win:update_scrollbar()
self.win:update_preview_title(string.format(" Action #%d ", idx))
self.win:update_preview_scrollbar()
end

M.native = native.base:extend()
Expand Down
Loading

0 comments on commit e32b0f4

Please sign in to comment.