Skip to content

Commit 1ea46f5

Browse files
authored
fix: minor issues with buf/win state management (#73)
* fix: minor issues with buf/win state management * Problem: A buffer being entered may have become invalid, if there is a BufEnter that `:bwipeout`s that buffer. For example, vim-fern-hijack does this. * Solution: Check validity of buffer. * Problem: `state.winnr` can be nil even when ther current window is dap-view window, if the user opened the dap-view buffer with some other method, e.g., CTRL-O. * Solution: Set `state.winnr` on BufEnter. * Comment: Maybe we can avoid these kind of problem altogether by setting winfixbuf. The problem "can't use winfixbuf since the window shares many buffers" can be circumvented by temporarily unsetting winfixbuf. * fixup! fix: minor issues with buf/win state management
1 parent 0fc730b commit 1ea46f5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lua/dap-view/autocmds.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ api.nvim_create_autocmd("TabEnter", {
4848
api.nvim_create_autocmd("BufEnter", {
4949
callback = function(args)
5050
local buf = args.buf
51-
local win = vim.fn.bufwinid(buf)
51+
if not api.nvim_buf_is_valid(buf) then
52+
return
53+
end
54+
local win = api.nvim_get_current_win()
5255
local ft = vim.bo[buf].filetype
5356

5457
-- Reset the winnr if the buffer changed
@@ -63,8 +66,16 @@ api.nvim_create_autocmd("BufEnter", {
6366
if not vim.tbl_contains({ "dap-view", "dap-view-term", "dap-repl" }, ft) then
6467
state.winnr = nil
6568
end
69+
elseif not state.winnr then
70+
if
71+
vim.tbl_contains({ "dap-view", "dap-repl" }, ft)
72+
or (ft == "dap-view-term" and state.current_section == "console")
73+
then
74+
state.winnr = win
75+
end
6676
end
67-
-- For good measure, also handle term_winr
77+
78+
-- For good measure, also handle term_winnr
6879
if state.term_winnr == win and ft ~= "dap-view-term" then
6980
state.term_winnr = nil
7081
end

0 commit comments

Comments
 (0)