From 15435f0ac7b339b5cef0b5007166aa22b97dc664 Mon Sep 17 00:00:00 2001 From: Fabian David Schmidt Date: Fri, 7 Jan 2022 16:19:37 +0100 Subject: [PATCH 1/2] feat: toggle view of multi selections --- lua/telescope/_extensions/file_browser.lua | 2 + .../_extensions/file_browser/actions.lua | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lua/telescope/_extensions/file_browser.lua b/lua/telescope/_extensions/file_browser.lua index 45c3b5dd..cdabaf56 100644 --- a/lua/telescope/_extensions/file_browser.lua +++ b/lua/telescope/_extensions/file_browser.lua @@ -73,6 +73,7 @@ local pconf = { [""] = fb_actions.goto_home_dir, [""] = fb_actions.change_cwd, [""] = fb_actions.copy_file, + [""] = fb_actions.toggle_selections, }, ["n"] = { ["dd"] = fb_actions.remove_file, @@ -87,6 +88,7 @@ local pconf = { ["s"] = fb_actions.goto_home_dir, ["t"] = fb_actions.change_cwd, ["y"] = fb_actions.copy_file, + ["k"] = fb_actions.toggle_selections, }, }, attach_mappings = function(prompt_bufnr, _) diff --git a/lua/telescope/_extensions/file_browser/actions.lua b/lua/telescope/_extensions/file_browser/actions.lua index d2d03df2..eb3cf7d5 100644 --- a/lua/telescope/_extensions/file_browser/actions.lua +++ b/lua/telescope/_extensions/file_browser/actions.lua @@ -506,5 +506,47 @@ fb_actions.select_all = function(prompt_bufnr) end) end +--- Toggle between view of multi-selections and previous browser. +--- - Note: +--- - WARNING: many |fb_actions| might not work. +--- - De-selections are persisted to other finders! +---@param prompt_bufnr number: The prompt bufnr +fb_actions.toggle_selections = function(prompt_bufnr) + local current_picker = action_state.get_current_picker(prompt_bufnr) + if current_picker._cached_finder == nil then + local finder = current_picker.finder + current_picker._cached_finder = current_picker.finder + local selections = current_picker:get_multi_selection() + local entries = {} + for _, sel in ipairs(selections) do + table.insert(entries, sel.value) + end + local make_entry = finder.entry_maker + local new_finder = require("telescope.finders").new_table { + results = entries, + entry_maker = make_entry { cwd = vim.loop.cwd() }, + } + if current_picker.prompt_border then + current_picker.prompt_border:change_title "File Browser: Multi Selections" + end + if current_picker.results_border then + current_picker.results_border:change_title(vim.loop.cwd()) + end + current_picker:refresh(new_finder, { reset_prompt = true, multi = current_picker._multi }) + else + local finder = current_picker._cached_finder + current_picker._cached_finder = nil + if current_picker.prompt_border then + local new_title = finder.files and "File Browser" or "Folder Browser" + current_picker.prompt_border:change_title(new_title) + end + if current_picker.results_border then + local new_title = finder.files and Path:new(finder.path):make_relative(vim.loop.cwd()) .. os_sep or finder.cwd + current_picker.results_border:change_title(new_title) + end + current_picker:refresh(finder, { reset_prompt = true, multi = current_picker._multi }) + end +end + fb_actions = transform_mod(fb_actions) return fb_actions From 35953e1ce23810563af2ee1af60968a0a4551bc7 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Fri, 7 Jan 2022 15:20:01 +0000 Subject: [PATCH 2/2] [docgen] Update doc/telescope-file-browser.txt skip-checks: true --- doc/telescope-file-browser.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/telescope-file-browser.txt b/doc/telescope-file-browser.txt index 0fe2fa47..f5e2b6a0 100644 --- a/doc/telescope-file-browser.txt +++ b/doc/telescope-file-browser.txt @@ -265,6 +265,17 @@ fb_actions.select_all({prompt_bufnr}) *fb_actions.select_all()* {prompt_bufnr} (number) The prompt bufnr +fb_actions.toggle_selections({prompt_bufnr}) *fb_actions.toggle_selections()* + Toggle between view of multi-selections and previous browser. + - Note: + - WARNING: many |fb_actions| might not work. + - De-selections are persisted to other finders! + + + Parameters: ~ + {prompt_bufnr} (number) The prompt bufnr + + ================================================================================ *telescope-file-browser.finders*