Implements horizontal scrolling in previewer & results. (#2437)

* Implements horizontal scrolling in previewer & results.

* docs: update wrt. horizontal scrolling in previewer &  results
This commit is contained in:
Lucía Andrea Illanes Albornoz
2023-06-24 21:17:55 +02:00
committed by GitHub
parent ffe35cb433
commit 5fff2a138b
8 changed files with 135 additions and 0 deletions

View File

@@ -189,6 +189,19 @@ local scroll_fn = function(self, direction)
end)
end
local scroll_horizontal_fn = function(self, direction)
if not self.state then
return
end
local input = direction > 0 and [[zl]] or [[zh]]
local count = math.abs(direction)
vim.api.nvim_win_call(self.state.winid, function()
vim.cmd([[normal! ]] .. count .. input)
end)
end
previewers.file_maker = function(filepath, bufnr, opts)
opts = vim.F.if_nil(opts, {})
-- TODO(conni2461): here shouldn't be any hardcoded magic numbers ...
@@ -462,6 +475,10 @@ previewers.new_buffer_previewer = function(opts)
opts.scroll_fn = scroll_fn
end
if not opts.scroll_horizontal_fn then
opts.scroll_horizontal_fn = scroll_horizontal_fn
end
return Previewer:new(opts)
end

View File

@@ -47,6 +47,7 @@ local previewers = {}
--- - `:teardown()`
--- - `:send_input(input)`
--- - `:scroll_fn(direction)`
--- - `:scroll_horizontal_fn(direction)`
---
--- `Previewer:new()` expects a table as input with following keys:
--- - `setup` function(self): Will be called the first time preview will be
@@ -64,6 +65,8 @@ local previewers = {}
--- used to send input to the terminal
--- application, like less.
--- - `scroll_fn` function(self, direction): Used to make scrolling work.
--- - `scroll_horizontal_fn` function(self, direction): Used to make
--- horizontal scrolling work.
previewers.Previewer = Previewer
--- A shorthand for creating a new Previewer.

View File

@@ -26,6 +26,7 @@ function Previewer:new(opts)
_teardown_func = opts.teardown,
_send_input = opts.send_input,
_scroll_fn = opts.scroll_fn,
_scroll_horizontal_fn = opts.scroll_horizontal_fn,
preview_fn = opts.preview_fn,
_empty_bufnr = nil,
}, Previewer)
@@ -95,4 +96,12 @@ function Previewer:scroll_fn(direction)
end
end
function Previewer:scroll_horizontal_fn(direction)
if self._scroll_horizontal_fn then
self:_scroll_horizontal_fn(direction)
else
vim.api.nvim_err_writeln "scroll_horizontal_fn is not defined for this previewer"
end
end
return Previewer