summaryrefslogtreecommitdiff
path: root/lua/telescope/pickers/scroller.lua
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2020-12-10 23:31:28 -0500
committerTJ DeVries <devries.timothyj@gmail.com>2020-12-10 23:31:28 -0500
commitf3609abd7f9bf34ad482b1beb1c0482b76562af3 (patch)
tree4b298a725cdbcfd400a179a3d6cddede4725f8ea /lua/telescope/pickers/scroller.lua
parentb74c4b3efddf6d6031918c2e2de83e44e26da9f2 (diff)
refactor: Move scroller into own testable module
Diffstat (limited to 'lua/telescope/pickers/scroller.lua')
-rw-r--r--lua/telescope/pickers/scroller.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/lua/telescope/pickers/scroller.lua b/lua/telescope/pickers/scroller.lua
new file mode 100644
index 0000000..f4c90ff
--- /dev/null
+++ b/lua/telescope/pickers/scroller.lua
@@ -0,0 +1,34 @@
+
+local scroller = {}
+
+scroller.create = function(strategy)
+ if strategy == 'cycle' then
+ return function(max_results, num_results, row)
+ local count = math.min(max_results, num_results)
+
+ if row >= count then
+ return 0
+ elseif row < 0 then
+ return count - 1
+ end
+
+ return row
+ end
+ elseif strategy == 'limit' or strategy == nil then
+ return function(max_results, num_results, row)
+ local count = math.min(max_results, num_results)
+
+ if row >= count then
+ return count - 1
+ elseif row < 0 then
+ return 0
+ end
+
+ return row
+ end
+ else
+ error("Unsupported strategy: ", strategy)
+ end
+end
+
+return scroller