Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(diffthis): retain cursor position from source window #578

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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