From 4dd35ef0e154ab1836fc923a33196a4101a97a9c Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Tue, 23 Feb 2021 22:10:19 +0100 Subject: feat: file browser & refresh interface (#290) and more picker api stuff for sunjon. refresh is implemented for file_browser and git_status --- lua/telescope/builtin/git.lua | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'lua/telescope/builtin/git.lua') diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index ba08aba..c403f14 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -1,4 +1,5 @@ local actions = require('telescope.actions') +local action_state = require('telescope.actions.state') local finders = require('telescope.finders') local make_entry = require('telescope.make_entry') local pickers = require('telescope.pickers') @@ -108,22 +109,35 @@ git.branches = function(opts) end git.status = function(opts) - local output = utils.get_os_command_output({ 'git', 'status', '-s' }, opts.cwd) + local gen_new_finder = function() + local output = utils.get_os_command_output({ 'git', 'status', '-s' }, opts.cwd) - if table.getn(output) == 0 then - print('No changes found') - return + if table.getn(output) == 0 then + print('No changes found') + return + end + + return finders.new_table { + results = output, + entry_maker = opts.entry_maker or make_entry.gen_from_git_status(opts) + } end + local initial_finder = gen_new_finder() + if not initial_finder then return end + pickers.new(opts, { prompt_title = 'Git Status', - finder = finders.new_table { - results = output, - entry_maker = make_entry.gen_from_git_status(opts) - }, + finder = initial_finder, previewer = previewers.git_file_diff.new(opts), sorter = conf.file_sorter(opts), - attach_mappings = function(_, map) + attach_mappings = function(prompt_bufnr, map) + actions.git_staging_toggle:enhance { + post = function() + action_state.get_current_picker(prompt_bufnr):refresh(gen_new_finder(), { reset_prompt = true }) + end, + } + map('i', '', actions.git_staging_toggle) map('n', '', actions.git_staging_toggle) return true -- cgit v1.2.3