fix: multiple navigation fixes for splits/popup terminal

chore: update Keybinds.md

more navigation fixes (primarly disabling mouse when terminal is open)

rm session
This commit is contained in:
Wesley van Tilburg
2026-03-14 13:56:36 +01:00
committed by Wesley van Tilburg
parent bb91392a21
commit 6dfbb4ec22
5 changed files with 213 additions and 185 deletions

View File

@@ -28,24 +28,42 @@ opt.splitright = true
opt.equalalways = false
opt.cursorline = true
-- Per-window buffer tabs (winbar)
-- Track which buffers were opened in each window
-- Per-window buffer tabs (exclusive: each file belongs to one split only)
_G.win_bufs = {}
-- Remove a buffer from all windows' tracking
function _G.untrack_buf_everywhere(buf)
for win, bufs in pairs(_G.win_bufs) do
for i, b in ipairs(bufs) do
if b == buf then
table.remove(bufs, i)
break
end
end
end
end
function _G.track_buf()
local win = vim.api.nvim_get_current_win()
local buf = vim.api.nvim_get_current_buf()
if not vim.bo[buf].buflisted or vim.bo[buf].filetype == "oil" then return end
if not _G.win_bufs[win] then _G.win_bufs[win] = {} end
-- Remove if already tracked, then add to end
for i, b in ipairs(_G.win_bufs[win]) do
if b == buf then table.remove(_G.win_bufs[win], i) break end
if not vim.bo[buf].buflisted
or vim.bo[buf].filetype == "oil"
or vim.bo[buf].buftype == "terminal"
or vim.api.nvim_buf_get_name(buf) == "" then
return
end
if not _G.win_bufs[win] then _G.win_bufs[win] = {} end
-- Already tracked in this window, skip
for _, b in ipairs(_G.win_bufs[win]) do
if b == buf then return end
end
-- Remove from any other window (exclusive ownership)
_G.untrack_buf_everywhere(buf)
table.insert(_G.win_bufs[win], buf)
end
function _G.get_win_bufs()
local win = vim.api.nvim_get_current_win()
function _G.get_win_bufs(win)
win = win or vim.api.nvim_get_current_win()
local bufs = {}
for _, buf in ipairs(_G.win_bufs[win] or {}) do
if vim.api.nvim_buf_is_valid(buf) and vim.bo[buf].buflisted then
@@ -57,13 +75,13 @@ function _G.get_win_bufs()
end
function _G.winbar_tabs()
local bufs = _G.get_win_bufs()
local win = vim.api.nvim_get_current_win()
local bufs = _G.get_win_bufs(win)
if #bufs == 0 then return "" end
local current = vim.api.nvim_get_current_buf()
local parts = {}
for _, buf in ipairs(bufs) do
local name = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(buf), ":t")
if name == "" then name = "[No Name]" end
local mod = vim.bo[buf].modified and " +" or ""
if buf == current then
table.insert(parts, "%#TabLineSel# " .. name .. mod .. " %#WinBar#")
@@ -79,6 +97,15 @@ vim.api.nvim_create_autocmd("BufEnter", {
callback = function() _G.track_buf() end,
})
-- Clean up tracking when a window closes
vim.api.nvim_create_autocmd("WinClosed", {
group = vim.api.nvim_create_augroup("clean_win_bufs", { clear = true }),
callback = function(ev)
local win = tonumber(ev.match)
if win then _G.win_bufs[win] = nil end
end,
})
opt.winbar = "%{%v:lua.winbar_tabs()%}"
-- Clipboard (system)