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 a521f1d
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 265 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
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
2 changes: 1 addition & 1 deletion 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
64 changes: 30 additions & 34 deletions lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,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 +371,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 +514,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 @@ -717,6 +712,7 @@ function Previewer.buffer_or_file:key_from_entry(entry)
end

function Previewer.buffer_or_file:populate_from_cache(entry)
print("from cache", entry)
local key = self:key_from_entry(entry)
local cached = self.cached_buffers[key]
assert(not cached or self.cached_bufnrs[tostring(cached.bufnr)])
Expand Down Expand Up @@ -877,6 +873,7 @@ function Previewer.base:update_ts_context()
then
return
end
print("update ts", self.last_entry)
TSContext.update(self.win.preview_winid, self.preview_bufnr, vim.tbl_extend("force",
type(self.treesitter.context) == "table" and self.treesitter.context or {}, {
-- `zindex` and `multiwindow` must be set regardless of user options
Expand Down Expand Up @@ -1078,31 +1075,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 +1122,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 +1218,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 +1389,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 +1440,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 a521f1d

Please sign in to comment.