Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
125 lines
2.9 KiB
Lua
125 lines
2.9 KiB
Lua
local scroller = {}
|
|
|
|
local range_calculators = {
|
|
ascending = function(max_results, num_results)
|
|
return 0, math.min(max_results, num_results)
|
|
end,
|
|
|
|
descending = function(max_results, num_results)
|
|
return math.max(max_results - num_results, 0), max_results
|
|
end,
|
|
}
|
|
|
|
local scroll_calculators = {
|
|
cycle = function(range_fn)
|
|
return function(max_results, num_results, row)
|
|
local start, finish = range_fn(max_results, num_results)
|
|
|
|
if row >= finish then
|
|
return start
|
|
elseif row < start then
|
|
return (finish - 1 < 0) and finish or finish - 1
|
|
end
|
|
|
|
return row
|
|
end
|
|
end,
|
|
|
|
limit = function(range_fn)
|
|
return function(max_results, num_results, row)
|
|
local start, finish = range_fn(max_results, num_results)
|
|
|
|
if row >= finish and finish > 0 then
|
|
return finish - 1
|
|
elseif row < start then
|
|
return start
|
|
end
|
|
|
|
return row
|
|
end
|
|
end,
|
|
}
|
|
|
|
scroller.create = function(scroll_strategy, sorting_strategy)
|
|
local range_fn = range_calculators[sorting_strategy]
|
|
if not range_fn then
|
|
error(debug.traceback("Unknown sorting strategy: " .. sorting_strategy))
|
|
end
|
|
|
|
local scroll_fn = scroll_calculators[scroll_strategy]
|
|
if not scroll_fn then
|
|
error(debug.traceback("Unknown scroll strategy: " .. (scroll_strategy or "")))
|
|
end
|
|
|
|
local calculator = scroll_fn(range_fn)
|
|
return function(max_results, num_results, row)
|
|
local result = calculator(max_results, num_results, row)
|
|
|
|
if result < 0 then
|
|
error(
|
|
string.format(
|
|
"Must never return a negative row: { result = %s, args = { %s %s %s } }",
|
|
result,
|
|
max_results,
|
|
num_results,
|
|
row
|
|
)
|
|
)
|
|
end
|
|
|
|
if result > max_results then
|
|
error(
|
|
string.format(
|
|
"Must never exceed max results: { result = %s, args = { %s %s %s } }",
|
|
result,
|
|
max_results,
|
|
num_results,
|
|
row
|
|
)
|
|
)
|
|
end
|
|
|
|
return result
|
|
end
|
|
end
|
|
|
|
scroller.top = function(sorting_strategy, max_results, num_results)
|
|
if sorting_strategy == "ascending" then
|
|
return 0
|
|
end
|
|
return (num_results > max_results) and 0 or (max_results - num_results)
|
|
end
|
|
|
|
scroller.middle = function(sorting_strategy, max_results, num_results)
|
|
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)
|
|
if sorting_strategy == "ascending" then
|
|
return math.min(max_results, num_results) - 1
|
|
end
|
|
return max_results - 1
|
|
end
|
|
|
|
scroller.better = function(sorting_strategy)
|
|
if sorting_strategy == "ascending" then
|
|
return -1
|
|
else
|
|
return 1
|
|
end
|
|
end
|
|
|
|
scroller.worse = function(sorting_strategy)
|
|
return -(scroller.better(sorting_strategy))
|
|
end
|
|
|
|
return scroller
|