From 6e941e0ecec1ab6a1b4ce40c693ef1272c505abb Mon Sep 17 00:00:00 2001 From: elianiva Date: Fri, 5 Mar 2021 20:13:48 +0700 Subject: feat: define scroll speed + smart_send to qflist (#610) * smart send to qflist * Previewer scrolling for half window height * Start doing cleanup in readme * feat: add ability to define the scrolling speed * move scrolling action to action.set * docs: added more docs for actions * [docgen] Update doc/telescope.txt skip-checks: true Co-authored-by: Simon Hauser Co-authored-by: Github Actions --- lua/telescope/actions/init.lua | 16 ++++++++++++---- lua/telescope/actions/set.lua | 13 +++++++++++++ lua/telescope/pickers/layout_strategies.lua | 5 +++++ 3 files changed, 30 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 79bcb23..cf230e7 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -144,13 +144,11 @@ function actions.toggle_selection(prompt_bufnr) end function actions.preview_scrolling_up(prompt_bufnr) - -- TODO: Make number configurable. - action_state.get_current_picker(prompt_bufnr).previewer:scroll_fn(-30) + action_set.scroll_previewer(prompt_bufnr, -1) end function actions.preview_scrolling_down(prompt_bufnr) - -- TODO: Make number configurable. - action_state.get_current_picker(prompt_bufnr).previewer:scroll_fn(30) + action_set.scroll_previewer(prompt_bufnr, 1) end function actions.center(_) @@ -413,6 +411,16 @@ actions.send_to_qflist = function(prompt_bufnr) vim.fn.setqflist(qf_entries, 'r') end +actions.smart_send_to_qflist = function(prompt_bufnr) + local picker = action_state.get_current_picker(prompt_bufnr) + if table.getn(picker:get_multi_selection()) > 0 then + actions.send_selected_to_qflist(prompt_bufnr) + else + actions.send_to_qflist(prompt_bufnr) + end +end + +--- Open the quickfix list actions.open_qflist = function(_) vim.cmd [[copen]] end diff --git a/lua/telescope/actions/set.lua b/lua/telescope/actions/set.lua index f55f3e7..ea46e83 100644 --- a/lua/telescope/actions/set.lua +++ b/lua/telescope/actions/set.lua @@ -2,6 +2,7 @@ local a = vim.api local log = require('telescope.log') local path = require('telescope.path') +local state = require('telescope.state') local action_state = require('telescope.actions.state') @@ -124,6 +125,18 @@ set.edit = function(prompt_bufnr, command) end end +--- Scrolls the previewer up or down +---@param prompt_bufnr number: The prompt bufnr +---@param direction number: The direction of the scrolling +-- Valid directions include: "1", "-1" +set.scroll_previewer = function (prompt_bufnr, direction) + local status = state.get_status(prompt_bufnr) + local default_speed = vim.api.nvim_win_get_height(status.preview_win) / 2 + local speed = status.picker.layout_config.scroll_speed or default_speed + + action_state.get_current_picker(prompt_bufnr).previewer:scroll_fn(math.floor(speed * direction)) +end + -- ================================================== -- Transforms modules and sets the corect metatables. -- ================================================== diff --git a/lua/telescope/pickers/layout_strategies.lua b/lua/telescope/pickers/layout_strategies.lua index 691ee06..b8d9aea 100644 --- a/lua/telescope/pickers/layout_strategies.lua +++ b/lua/telescope/pickers/layout_strategies.lua @@ -53,6 +53,9 @@ --- --- - preview_width: --- - Change the width of Telescope's preview window +--- +--- - scroll_speed: +--- - Change the scrolling speed of the previewer ---@brief ]] local config = require('telescope.config') @@ -99,6 +102,7 @@ layout_strategies.horizontal = function(self, max_columns, max_lines) height_padding = "How many cells to pad the height", preview_width = "(Resolvable): Determine preview width", mirror = "Flip the location of the results/prompt and preview windows", + scroll_speed = "The speed when scrolling through the previewer", }) local initial_options = self:_get_initial_window_options() @@ -266,6 +270,7 @@ layout_strategies.vertical = function(self, max_columns, max_lines) height_padding = "How many cells to pad the height", preview_height = "(Resolvable): Determine preview height", mirror = "Flip the locations of the results and prompt windows", + scroll_speed = "The speed when scrolling through the previewer", }) local initial_options = self:_get_initial_window_options() -- cgit v1.2.3