Problem: running :e on a :Gdiff buffer cleared all content because diffs:// buffers had no BufReadCmd handler. Neovim tried to read the buffer name as a file path, found nothing on disk, and emptied the buffer. This affected all three buffer creation paths (gdiff, gdiff_file, gdiff_section). Solution: register a BufReadCmd autocmd for diffs://* that parses the URL and regenerates diff content from git. Change buffer options from nofile/wipe to nowrite/delete (matching fugitive's approach) so buffer-local autocmds and variables survive across unload/reload cycles. Store old filepath as buffer variable for rename support.
42 lines
1,003 B
Lua
42 lines
1,003 B
Lua
if vim.g.loaded_diffs then
|
|
return
|
|
end
|
|
vim.g.loaded_diffs = 1
|
|
|
|
require('diffs.commands').setup()
|
|
|
|
vim.api.nvim_create_autocmd('FileType', {
|
|
pattern = { 'fugitive', 'git' },
|
|
callback = function(args)
|
|
local diffs = require('diffs')
|
|
if args.match == 'git' and not diffs.is_fugitive_buffer(args.buf) then
|
|
return
|
|
end
|
|
diffs.attach(args.buf)
|
|
|
|
if args.match == 'fugitive' then
|
|
local fugitive_config = diffs.get_fugitive_config()
|
|
if fugitive_config.horizontal or fugitive_config.vertical then
|
|
require('diffs.fugitive').setup_keymaps(args.buf, fugitive_config)
|
|
end
|
|
end
|
|
end,
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd('BufReadCmd', {
|
|
pattern = 'diffs://*',
|
|
callback = function(args)
|
|
require('diffs.commands').read_buffer(args.buf)
|
|
end,
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd('OptionSet', {
|
|
pattern = 'diff',
|
|
callback = function()
|
|
if vim.wo.diff then
|
|
require('diffs').attach_diff()
|
|
else
|
|
require('diffs').detach_diff()
|
|
end
|
|
end,
|
|
})
|