Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(buffer_previewer): expose scroll_fn() #3362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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