mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2025-02-22 07:47:02 +00:00
Add ability to reset hunks
This commit is contained in:
parent
6a51cc061a
commit
ae695a803c
@ -53,6 +53,7 @@ require('gitsigns').setup {
|
||||
['[c'] = '<cmd>lua require("gitsigns").prev_hunk()<CR>',
|
||||
['<leader>hs'] = '<cmd>lua require("gitsigns").stage_hunk()<CR>',
|
||||
['<leader>hu'] = '<cmd>lua require("gitsigns").undo_stage_hunk()<CR>',
|
||||
['<leader>hr'] = '<cmd>lua require("gitsigns").reset_hunk()<CR>',
|
||||
['<leader>gh'] = '<cmd>lua require("gitsigns").get_hunk()<CR>'
|
||||
},
|
||||
watch_index = {
|
||||
@ -80,6 +81,6 @@ set statusline+=%{get(b:,'gitsigns_status','')}
|
||||
## TODO
|
||||
|
||||
- [x] Add action for undoing a stage of a hunk
|
||||
- [ ] Add action for undoing a hunk
|
||||
- [x] Add action for ~~undoing~~ reseting a hunk
|
||||
- [ ] Add action for showing diff (or original text) in a floating window
|
||||
- [ ] Add ability to show staged hunks with different signs (maybe in a different sign column?)
|
||||
|
@ -372,16 +372,14 @@ local function create_patch(relpath, hunk, invert)
|
||||
if invert then
|
||||
ps, pc, ns, nc = ns, nc, ps, pc
|
||||
|
||||
local tlines = {}
|
||||
for _, l in ipairs(lines) do
|
||||
lines = vim.tbl_map(function(l)
|
||||
if vim.startswith(l, '+') then
|
||||
l = '-'..string.sub(l, 2, -1)
|
||||
elseif vim.startswith(l, '-') then
|
||||
l = '+'..string.sub(l, 2, -1)
|
||||
end
|
||||
table.insert(tlines, l)
|
||||
end
|
||||
lines = tlines
|
||||
return l
|
||||
end, lines)
|
||||
end
|
||||
|
||||
return {
|
||||
@ -424,6 +422,36 @@ local stage_hunk = async(function()
|
||||
end
|
||||
end)
|
||||
|
||||
local reset_hunk = async(function()
|
||||
local bufnr = current_buf()
|
||||
local bcache = cache[bufnr]
|
||||
local hunk = get_hunk(bufnr, bcache.diffs)
|
||||
|
||||
if not hunk then
|
||||
return
|
||||
end
|
||||
|
||||
local orig_lines = vim.tbl_map(function(l)
|
||||
return string.sub(l, 2, -1)
|
||||
end, vim.tbl_filter(function(l)
|
||||
return vim.startswith(l, '-')
|
||||
end, hunk.lines))
|
||||
|
||||
local lstart, lend
|
||||
if hunk.type == 'delete' then
|
||||
lstart = hunk.start
|
||||
lend = hunk.start
|
||||
else
|
||||
local length = vim.tbl_count(vim.tbl_filter(function(l)
|
||||
return vim.startswith(l, '+')
|
||||
end, hunk.lines))
|
||||
|
||||
lstart = hunk.start - 1
|
||||
lend = hunk.start - 1 + length
|
||||
end
|
||||
api.nvim_buf_set_lines(bufnr, lstart, lend, false, orig_lines)
|
||||
end)
|
||||
|
||||
local undo_stage_hunk = async(function()
|
||||
local bufnr = current_buf()
|
||||
local bcache = cache[bufnr]
|
||||
@ -549,6 +577,7 @@ return {
|
||||
get_hunk = get_hunk,
|
||||
stage_hunk = stage_hunk,
|
||||
undo_stage_hunk = undo_stage_hunk,
|
||||
reset_hunk = reset_hunk,
|
||||
next_hunk = next_hunk,
|
||||
prev_hunk = prev_hunk,
|
||||
attach = attach,
|
||||
|
@ -11,6 +11,7 @@ return {
|
||||
['[c'] = '<cmd>lua require"gitsigns".prev_hunk()<CR>',
|
||||
['<leader>hs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
|
||||
['<leader>hu'] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
|
||||
['<leader>hr'] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
|
||||
['<leader>gh'] = '<cmd>lua require"gitsigns".get_hunk()<CR>'
|
||||
},
|
||||
watch_index = {
|
||||
|
Loading…
Reference in New Issue
Block a user