summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorHubert Pelczarski <41551030+hoob3rt@users.noreply.github.com>2021-02-24 03:35:52 +0100
committerGitHub <noreply@github.com>2021-02-24 03:35:52 +0100
commit67b06615371465b53a82c39c603c3249286b5b2a (patch)
tree73c93ec151b303c1b892277aa082eda2502e062d /lua
parent10627e889e82a82560b6fc48ea0ca20e1963d07f (diff)
feat: adds M mapping in normal mode (#544)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/actions/init.lua5
-rw-r--r--lua/telescope/mappings.lua1
-rw-r--r--lua/telescope/pickers/scroller.lua4
-rw-r--r--lua/tests/automated/scroller_spec.lua9
4 files changed, 18 insertions, 1 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index 5ae284b..19a6d04 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -78,6 +78,11 @@ function actions.move_to_top(prompt_bufnr)
))
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))
+end
+
function actions.move_to_bottom(prompt_bufnr)
local current_picker = actions.get_current_picker(prompt_bufnr)
current_picker:set_selection(p_scroller.bottom(current_picker.sorting_strategy,
diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua
index 95ce279..9490309 100644
--- a/lua/telescope/mappings.lua
+++ b/lua/telescope/mappings.lua
@@ -39,6 +39,7 @@ mappings.default_mappings = config.values.default_mappings or {
["j"] = actions.move_selection_next,
["k"] = actions.move_selection_previous,
["H"] = actions.move_to_top,
+ ["M"] = actions.move_to_middle,
["L"] = actions.move_to_bottom,
["<Down>"] = actions.move_selection_next,
diff --git a/lua/telescope/pickers/scroller.lua b/lua/telescope/pickers/scroller.lua
index 8b84e7c..d330dec 100644
--- a/lua/telescope/pickers/scroller.lua
+++ b/lua/telescope/pickers/scroller.lua
@@ -80,6 +80,10 @@ scroller.top = function(sorting_strategy, max_results, num_results)
return (num_results > max_results) and 0 or (max_results - num_results)
end
+scroller.middle = function(sorting_strategy, max_results, num_results)
+ return 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
diff --git a/lua/tests/automated/scroller_spec.lua b/lua/tests/automated/scroller_spec.lua
index 98233b4..bd202e8 100644
--- a/lua/tests/automated/scroller_spec.lua
+++ b/lua/tests/automated/scroller_spec.lua
@@ -112,7 +112,14 @@ describe('scroller', function()
end)
end)
- describe('should give top and bottom index', function()
+
+ describe('should give top, middle and bottom index', function()
+ it('should handle middle index', function()
+ eq(5, p_scroller.middle(nil, 11, nil))
+ eq(10, p_scroller.middle(nil, 20, nil))
+ eq(12, p_scroller.middle(nil, 25, nil))
+ end)
+
it('should handle ascending', function()
eq(0, p_scroller.top('ascending', 20, 1000))
eq(19, p_scroller.bottom('ascending', 20, 1000))