feat: advanced normal mode (#463)

Add <count>j and k to normal mode and H and L to jump at top and bottom of displayed results
This commit is contained in:
Simon Hauser
2021-02-24 02:41:00 +01:00
committed by GitHub
parent 4dd35ef0e1
commit 10627e889e
5 changed files with 60 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ local a = vim.api
local log = require('telescope.log')
local state = require('telescope.state')
local utils = require('telescope.utils')
local p_scroller = require('telescope.pickers.scroller')
local action_state = require('telescope.actions.state')
local action_set = require('telescope.actions.set')
@@ -69,6 +70,22 @@ function actions.move_selection_previous(prompt_bufnr)
action_set.shift_selection(prompt_bufnr, -1)
end
function actions.move_to_top(prompt_bufnr)
local current_picker = actions.get_current_picker(prompt_bufnr)
current_picker:set_selection(p_scroller.top(current_picker.sorting_strategy,
current_picker.max_results,
current_picker.manager:num_results()
))
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,
current_picker.max_results,
current_picker.manager:num_results()
))
end
function actions.add_selection(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
current_picker:add_selection(current_picker:get_selection_row())

View File

@@ -26,7 +26,9 @@ local set = setmetatable({}, {
---@param prompt_bufnr number: The prompt bufnr
---@param change number: The amount to shift the selection by
set.shift_selection = function(prompt_bufnr, change)
action_state.get_current_picker(prompt_bufnr):move_selection(change)
local count = vim.v.count
count = count == 0 and 1 or count
action_state.get_current_picker(prompt_bufnr):move_selection(change * count)
end
--- Select the current entry. This is the action set to overwrite common