Skip to content

Commit

Permalink
feat(diffthis): retain cursor position from source window
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Rubin <me@jawa.dev>
  • Loading branch information
joshuarubin committed Jun 8, 2022
1 parent 27aeb2e commit 51997f5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 46 deletions.
39 changes: 16 additions & 23 deletions lua/gitsigns/diffthis.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 16 additions & 23 deletions teal/gitsigns/diffthis.tl
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,10 @@ local function run(base: string, diffthis: boolean, vertical: boolean)
local comp_rev = bcache:get_compare_rev(util.calc_base(base))
local bufname = bcache:get_rev_bufname(comp_rev)

if diffthis then
-- Enable diff on the currently open buffer
vim.cmd'diffthis'

vim.cmd(table.concat({
'keepalt', 'aboveleft',
vertical and 'vertical' or '',
'split', bufname
}, ' '))
else
-- TODO(lewis6991): Pull in mods from the :Gitsigns command (split, vsplit,
-- etc)
vim.cmd(table.concat({
'edit', bufname
}, ' '))
end

local dbuf = vim.api.nvim_get_current_buf()
local dbuf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(dbuf, bufname)

local ok, err = pcall(bufread as function, bufnr, dbuf, base, bcache)

if diffthis then
vim.cmd'diffthis'
end

if not ok then
message.error(err as string)
scheduler()
Expand Down Expand Up @@ -133,6 +112,20 @@ local function run(base: string, diffthis: boolean, vertical: boolean)
vim.bo[dbuf].buftype = 'nowrite'
vim.bo[dbuf].modifiable = false
end

if diffthis then
vim.cmd(table.concat({
'keepalt', 'aboveleft',
vertical and 'vertical' or '',
'diffsplit', bufname
}, ' '))
else
-- TODO(lewis6991): Pull in mods from the :Gitsigns command (split, vsplit,
-- etc)
vim.cmd(table.concat({
'edit', bufname
}, ' '))
end
end

M.diffthis = void(function(base: string, vertical: boolean)
Expand Down

0 comments on commit 51997f5

Please sign in to comment.