fix: scroll misbehaving + fixed jump to middle (#547)

* fix: scroll misbehaving + fixed jump to middle

* add test

* fixx

* fix nil
This commit is contained in:
elianiva
2021-02-24 21:40:11 +07:00
committed by GitHub
parent b5051eeb01
commit 8b3d08d7a6
4 changed files with 23 additions and 8 deletions
+5 -1
View File
@@ -80,7 +80,11 @@ end
function actions.move_to_middle(prompt_bufnr)
local current_picker = actions.get_current_picker(prompt_bufnr)
current_picker:set_selection(p_scroller.middle(nil, current_picker.max_results, nil))
current_picker:set_selection(p_scroller.middle(
current_picker.sorting_strategy,
current_picker.max_results,
current_picker.manager:num_results()
))
end
function actions.move_to_bottom(prompt_bufnr)
+1
View File
@@ -28,6 +28,7 @@ local set = setmetatable({}, {
set.shift_selection = function(prompt_bufnr, change)
local count = vim.v.count
count = count == 0 and 1 or count
count = a.nvim_get_mode().mode == "n" and count or 1
action_state.get_current_picker(prompt_bufnr):move_selection(change * count)
end
+9 -1
View File
@@ -81,7 +81,15 @@ scroller.top = function(sorting_strategy, max_results, num_results)
end
scroller.middle = function(sorting_strategy, max_results, num_results)
return math.floor(max_results/2)
local mid_pos
if sorting_strategy == 'ascending' then
mid_pos = math.floor(num_results / 2)
else
mid_pos = math.floor(max_results - num_results / 2)
end
return (num_results < max_results) and mid_pos or math.floor(max_results / 2)
end
scroller.bottom = function(sorting_strategy, max_results, num_results)