From 3f45d64e9c47ad9eef273ddab65790a84cced30b Mon Sep 17 00:00:00 2001 From: Zachary Churchill Date: Mon, 11 Oct 2021 12:14:23 -0400 Subject: [PATCH] feat: add `gg` and `G` to default mappings (#1325) * feat: add `gg` and `G` to default mappings * refactor: use action_state.get_current_picker * docs: mention new default gg/G keymaps --- README.md | 1 + lua/telescope/actions/init.lua | 16 ++++++++-------- lua/telescope/mappings.lua | 2 ++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 20eb13a..7f1d902 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ Many familiar mapping patterns are setup as defaults. | `/` | Previous item | | `j/k` | Next/previous (in normal mode) | | `H/M/L` | Select High/Middle/Low (in normal mode) | +| 'gg/G' | Select the first/last item (in normal mode) | | `` | Confirm selection | | `` | Go to file selection as a split | | `` | Go to file selection as a vsplit | diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 91ba554..5358557 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -102,7 +102,7 @@ end --- Move to the top of the picker ---@param prompt_bufnr number: The prompt bufnr function actions.move_to_top(prompt_bufnr) - local current_picker = actions.get_current_picker(prompt_bufnr) + local current_picker = action_state.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()) ) @@ -111,7 +111,7 @@ end --- Move to the middle of the picker ---@param prompt_bufnr number: The prompt bufnr function actions.move_to_middle(prompt_bufnr) - local current_picker = actions.get_current_picker(prompt_bufnr) + local current_picker = action_state.get_current_picker(prompt_bufnr) current_picker:set_selection( p_scroller.middle(current_picker.sorting_strategy, current_picker.max_results, current_picker.manager:num_results()) ) @@ -120,7 +120,7 @@ end --- Move to the bottom of the picker ---@param prompt_bufnr number: The prompt bufnr function actions.move_to_bottom(prompt_bufnr) - local current_picker = actions.get_current_picker(prompt_bufnr) + local current_picker = action_state.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()) ) @@ -632,7 +632,7 @@ actions.git_reset_hard = function(prompt_bufnr) end actions.git_checkout_current_buffer = function(prompt_bufnr) - local cwd = actions.get_current_picker(prompt_bufnr).cwd + local cwd = action_state.get_current_picker(prompt_bufnr).cwd local selection = actions.get_selected_entry() if selection == nil then print "[telescope] Nothing currently selected" @@ -830,7 +830,7 @@ end actions.cycle_history_next = function(prompt_bufnr) local history = action_state.get_current_history() - local current_picker = actions.get_current_picker(prompt_bufnr) + local current_picker = action_state.get_current_picker(prompt_bufnr) local line = action_state.get_current_line() local entry = history:get_next(line, current_picker) @@ -846,7 +846,7 @@ end actions.cycle_history_prev = function(prompt_bufnr) local history = action_state.get_current_history() - local current_picker = actions.get_current_picker(prompt_bufnr) + local current_picker = action_state.get_current_picker(prompt_bufnr) local line = action_state.get_current_line() local entry = history:get_prev(line, current_picker) @@ -889,14 +889,14 @@ end --- This action is not mapped on default. ---@param prompt_bufnr number: The prompt bufnr actions.cycle_previewers_next = function(prompt_bufnr) - actions.get_current_picker(prompt_bufnr):cycle_previewers(1) + action_state.get_current_picker(prompt_bufnr):cycle_previewers(1) end --- Cycle to the previous previewer if there is one available.
--- This action is not mapped on default. ---@param prompt_bufnr number: The prompt bufnr actions.cycle_previewers_prev = function(prompt_bufnr) - actions.get_current_picker(prompt_bufnr):cycle_previewers(-1) + action_state.get_current_picker(prompt_bufnr):cycle_previewers(-1) end --- Removes the selected picker in |builtin.pickers|.
diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua index fa2e2f5..08bc3bb 100644 --- a/lua/telescope/mappings.lua +++ b/lua/telescope/mappings.lua @@ -54,6 +54,8 @@ mappings.default_mappings = config.values.default_mappings [""] = actions.move_selection_next, [""] = actions.move_selection_previous, + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, [""] = actions.preview_scrolling_up, [""] = actions.preview_scrolling_down,