fix(action): horizontal scroll after preview toggling (#2915)
This commit is contained in:
@@ -227,6 +227,24 @@ action_set.edit = function(prompt_bufnr, command)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param prompt_bufnr integer
|
||||||
|
---@return table? previewer
|
||||||
|
---@return number? speed
|
||||||
|
local __scroll_previewer = function(prompt_bufnr)
|
||||||
|
local previewer = action_state.get_current_picker(prompt_bufnr).previewer
|
||||||
|
local status = state.get_status(prompt_bufnr)
|
||||||
|
local preview_winid = status.layout.preview and status.layout.preview.winid
|
||||||
|
|
||||||
|
-- Check if we actually have a previewer and a preview window
|
||||||
|
if type(previewer) ~= "table" or not preview_winid then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local default_speed = vim.api.nvim_win_get_height(preview_winid) / 2
|
||||||
|
local speed = status.picker.layout_config.scroll_speed or default_speed
|
||||||
|
return previewer, speed
|
||||||
|
end
|
||||||
|
|
||||||
--- Scrolls the previewer up or down.
|
--- Scrolls the previewer up or down.
|
||||||
--- Defaults to a half page scroll, but can be overridden using the `scroll_speed`
|
--- Defaults to a half page scroll, but can be overridden using the `scroll_speed`
|
||||||
--- option in `layout_config`. See |telescope.layout| for more details.
|
--- option in `layout_config`. See |telescope.layout| for more details.
|
||||||
@@ -234,20 +252,11 @@ end
|
|||||||
---@param direction number: The direction of the scrolling
|
---@param direction number: The direction of the scrolling
|
||||||
-- Valid directions include: "1", "-1"
|
-- Valid directions include: "1", "-1"
|
||||||
action_set.scroll_previewer = function(prompt_bufnr, direction)
|
action_set.scroll_previewer = function(prompt_bufnr, direction)
|
||||||
local previewer = action_state.get_current_picker(prompt_bufnr).previewer
|
local previewer, speed = __scroll_previewer(prompt_bufnr)
|
||||||
local status = state.get_status(prompt_bufnr)
|
if previewer and previewer.scroll_fn then
|
||||||
|
|
||||||
local preview_winid = status.layout.preview and status.layout.preview.winid
|
|
||||||
-- Check if we actually have a previewer and a preview window
|
|
||||||
if type(previewer) ~= "table" or previewer.scroll_fn == nil or preview_winid == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local default_speed = vim.api.nvim_win_get_height(status.layout.preview.winid) / 2
|
|
||||||
local speed = status.picker.layout_config.scroll_speed or default_speed
|
|
||||||
|
|
||||||
previewer:scroll_fn(math.floor(speed * direction))
|
previewer:scroll_fn(math.floor(speed * direction))
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Scrolls the previewer to the left or right.
|
--- Scrolls the previewer to the left or right.
|
||||||
--- Defaults to a half page scroll, but can be overridden using the `scroll_speed`
|
--- Defaults to a half page scroll, but can be overridden using the `scroll_speed`
|
||||||
@@ -256,19 +265,11 @@ end
|
|||||||
---@param direction number: The direction of the scrolling
|
---@param direction number: The direction of the scrolling
|
||||||
-- Valid directions include: "1", "-1"
|
-- Valid directions include: "1", "-1"
|
||||||
action_set.scroll_horizontal_previewer = function(prompt_bufnr, direction)
|
action_set.scroll_horizontal_previewer = function(prompt_bufnr, direction)
|
||||||
local previewer = action_state.get_current_picker(prompt_bufnr).previewer
|
local previewer, speed = __scroll_previewer(prompt_bufnr)
|
||||||
local status = state.get_status(prompt_bufnr)
|
if previewer and previewer.scroll_horizontal_fn then
|
||||||
|
|
||||||
-- Check if we actually have a previewer and a preview window
|
|
||||||
if type(previewer) ~= "table" or previewer.scroll_horizontal_fn == nil or status.preview_win == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local default_speed = vim.api.nvim_win_get_height(status.preview_win) / 2
|
|
||||||
local speed = status.picker.layout_config.scroll_speed or default_speed
|
|
||||||
|
|
||||||
previewer:scroll_horizontal_fn(math.floor(speed * direction))
|
previewer:scroll_horizontal_fn(math.floor(speed * direction))
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--- Scrolls the results up or down.
|
--- Scrolls the results up or down.
|
||||||
--- Defaults to a half page scroll, but can be overridden using the `scroll_speed`
|
--- Defaults to a half page scroll, but can be overridden using the `scroll_speed`
|
||||||
|
|||||||
Reference in New Issue
Block a user