diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2020-12-11 16:48:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-11 16:48:14 +0100 |
| commit | 6e6fbbc49eee19baeeea85c99aa8fb816fbd25e6 (patch) | |
| tree | b7537f8fce4a6f58d0c480e9f3d353c1ea23f93b /lua/telescope/pickers/scroller.lua | |
| parent | d5ee177306da9c977734f84ae016726778e1746f (diff) | |
Fix: scroller for descending (#327)
Diffstat (limited to 'lua/telescope/pickers/scroller.lua')
| -rw-r--r-- | lua/telescope/pickers/scroller.lua | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/lua/telescope/pickers/scroller.lua b/lua/telescope/pickers/scroller.lua index f4c90ff..d9e5a64 100644 --- a/lua/telescope/pickers/scroller.lua +++ b/lua/telescope/pickers/scroller.lua @@ -1,10 +1,33 @@ - local scroller = {} -scroller.create = function(strategy) +local calc_count_fn = function(sorting_strategy) + if sorting_strategy == 'ascending' then + return function(a, b) return math.min(a, b) end + else + return function(a, b, row) + if a == b or not row then + return math.max(a, b) + else + local x = a - b + if row < x then + return math.max(a, b) - 1, true + elseif row == a then + return x, true + else + return math.max(a, b) + end + end + end + end +end + +scroller.create = function(strategy, sorting_strategy) + local calc_count = calc_count_fn(sorting_strategy) + if strategy == 'cycle' then return function(max_results, num_results, row) - local count = math.min(max_results, num_results) + local count, b = calc_count(max_results, num_results, row) + if b then return count end if row >= count then return 0 @@ -16,7 +39,7 @@ scroller.create = function(strategy) end elseif strategy == 'limit' or strategy == nil then return function(max_results, num_results, row) - local count = math.min(max_results, num_results) + local count = calc_count(max_results, num_results) if row >= count then return count - 1 |
