Skip to content

Commit 0ad3e4f

Browse files
authored
fix: Workaround for <afile> expanding incorrectly (#374)
1 parent 397ce24 commit 0ad3e4f

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

lua/diffview/init.lua

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,23 @@ function M.setup(user_config)
2222
end
2323

2424
function M.init()
25+
-- Fix the strange behavior that "<afile>" expands non-files
26+
-- as file name in some cases.
27+
--
28+
-- Ref:
29+
-- * sindrets/diffview.nvim#369
30+
-- * neovim/neovim#23943
31+
local function get_tabnr(state)
32+
if vim.fn.has("nvim-0.9.2") ~= 1 then
33+
return tonumber(state.match)
34+
else
35+
return tonumber(state.file)
36+
end
37+
end
38+
2539
local au = api.nvim_create_autocmd
40+
41+
-- Set up highlighting
2642
hl.setup()
2743

2844
-- Set up autocommands
@@ -45,7 +61,7 @@ function M.init()
4561
group = M.augroup,
4662
pattern = "*",
4763
callback = function(state)
48-
M.close(tonumber(state.file))
64+
M.close(get_tabnr(state))
4965
end,
5066
})
5167
au("BufWritePost", {
@@ -59,7 +75,7 @@ function M.init()
5975
group = M.augroup,
6076
pattern = "*",
6177
callback = function(state)
62-
M.emit("win_closed", tonumber(state.file))
78+
M.emit("win_closed", get_tabnr(state))
6379
end,
6480
})
6581
au("ColorScheme", {

0 commit comments

Comments
 (0)