Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Fix invalid window id #340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
44 changes: 24 additions & 20 deletions lua/hop/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,32 @@ function M.get_window_context(multi_windows)
end

for _, w in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
local b = vim.api.nvim_win_get_buf(w)
if w ~= cur_hwin then

-- check duplicated buffers; the way this is done is by accessing all the already known contexts and checking that
-- the buffer we are accessing is already present in; if it is, we then append the window context to that buffer
local bctx = nil
for _, buffer_ctx in ipairs(all_ctxs) do
if b == buffer_ctx.hbuf then
bctx = buffer_ctx.contexts
break
end
end
if vim.api.nvim_win_is_valid(w) then
if vim.api.nvim_win_get_config(w).relative == '' then
local b = vim.api.nvim_win_get_buf(w)
if w ~= cur_hwin then

-- check duplicated buffers; the way this is done is by accessing all the already known contexts and checking that
-- the buffer we are accessing is already present in; if it is, we then append the window context to that buffer
local bctx = nil
for _, buffer_ctx in ipairs(all_ctxs) do
if b == buffer_ctx.hbuf then
bctx = buffer_ctx.contexts
break
end
end

if bctx then
bctx[#bctx + 1] = window_context(w, vim.api.nvim_win_get_cursor(w))
else
all_ctxs[#all_ctxs + 1] = {
hbuf = b,
contexts = { window_context(w, vim.api.nvim_win_get_cursor(w)) }
}
end

if bctx then
bctx[#bctx + 1] = window_context(w, vim.api.nvim_win_get_cursor(w))
else
all_ctxs[#all_ctxs + 1] = {
hbuf = b,
contexts = { window_context(w, vim.api.nvim_win_get_cursor(w)) }
}
end
end

end
end

Expand Down