Skip to content

Commit

Permalink
feat(buffer_previewer): expose scroll_fn()
Browse files Browse the repository at this point in the history
  • Loading branch information
karb94 committed Dec 8, 2024
1 parent 2eca9ba commit fb8716d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,17 @@ append(
Default: require("telescope.previewers").buffer_previewer_maker]]
)

append(
"buffer_scroll_fn",
function(...)
return require("telescope.previewers").buffer_scroll_fn(...)
end,
[[
Function pointer to the default scroll function in buffer previewers.
Default: require("telescope.previewers").buffer_scroll_fn]]
)

-- @param user_defaults table: a table where keys are the names of options,
-- and values are the ones the user wants
-- @param tele_defaults table: (optional) a table containing all of the defaults
Expand Down
4 changes: 2 additions & 2 deletions lua/telescope/previewers/buffer_previewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ local search_teardown = function(self)
end
end

local scroll_fn = function(self, direction)
previewers.scroll_fn = function(self, direction)
if not self.state then
return
end
Expand Down Expand Up @@ -475,7 +475,7 @@ previewers.new_buffer_previewer = function(opts)
end

if not opts.scroll_fn then
opts.scroll_fn = scroll_fn
opts.scroll_fn = conf.buffer_scroll_fn
end

if not opts.scroll_horizontal_fn then
Expand Down
3 changes: 3 additions & 0 deletions lua/telescope/previewers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ previewers.new_buffer_previewer = buffer_previewer.new_buffer_previewer
---@param opts table: keys: `use_ft_detect`, `bufname` and `callback`
previewers.buffer_previewer_maker = buffer_previewer.file_maker

--- A function to scroll the buffer of buffer previewers
previewers.buffer_scroll_fn = buffer_previewer.scroll_fn

--- A previewer that is used to display a file. It uses the `buffer_previewer`
--- interface and won't jump to the line. To integrate this one into your
--- own picker make sure that the field `path` or `filename` is set for
Expand Down

0 comments on commit fb8716d

Please sign in to comment.