feat: Make tab toggle between git add and git restore in builtin.git_status() (#289)

Very useful functionality to use git_status for. Now users can add a file or restore it by <tab>

authored by: @cempassi
This commit is contained in:
Cedric M'Passi
2020-11-27 12:15:02 +01:00
committed by GitHub
parent 4a8ea7763e
commit 6edbd1db5f
2 changed files with 24 additions and 20 deletions

View File

@@ -243,11 +243,20 @@ actions.git_checkout = function(prompt_bufnr)
os.execute('git checkout ' .. val)
end
actions.git_add = function(prompt_bufnr)
actions.git_staging_toggle = function(prompt_bufnr)
local selection = actions.get_selected_entry(prompt_bufnr)
-- If parts of the file are staged and unstaged at the same time, stage
-- changes. Else toggle between staged and unstaged if the file is tracked,
-- and between added and untracked if the file is untracked.
if selection.status:sub(2) == ' ' then
os.execute('git restore --staged ' .. selection.value)
else
os.execute('git add ' .. selection.value)
end
actions.close(prompt_bufnr)
local val = selection.value
os.execute('git add ' .. val)
require('telescope.builtin').git_status()
vim.api.nvim_feedkeys('i', 'n', false)
end
-- ==================================================