From c355eafedc72c9bea79e190d2706c34cbdfd6506 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Sat, 31 May 2025 15:04:52 +0800 Subject: [PATCH] =?UTF-8?q?fix=20nvim:=20=E4=BF=AE=E6=AD=A3neo-tree?= =?UTF-8?q?=E7=9A=84winbar=E9=96=8B=E5=95=9F=E5=BE=8C=EF=BC=8C=E5=88=87?= =?UTF-8?q?=E6=8F=9Bwinbat=20tab=E6=9C=83=E5=B0=8E=E8=87=B4barbar=20offset?= =?UTF-8?q?=E8=B7=91=E6=8E=89=E7=9A=84=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exact_plugins/exact_components/barbar.lua | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_components/barbar.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_components/barbar.lua index 26943c0..35f1e7b 100644 --- a/dot_config/nvim/exact_lua/exact_plugins/exact_components/barbar.lua +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_components/barbar.lua @@ -49,11 +49,21 @@ return { -- } require('barbar').setup(opts) + -- 修正neo-tree的winbar開啟後,切換winbat tab會導致barbar offset跑掉的問題 + -- + local function neo_tree_is_visible() + for _, win in ipairs(vim.api.nvim_list_wins()) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.bo[buf].filetype == "neo-tree" then + return true + end + end + return false + end vim.api.nvim_create_autocmd("BufEnter", { pattern = "*", callback = function() - local ft = vim.bo.filetype - if ft == "neo-tree" then + if vim.bo.filetype == "neo-tree" then for _, win in ipairs(vim.api.nvim_list_wins()) do local buf = vim.api.nvim_win_get_buf(win) if vim.bo[buf].filetype == "neo-tree" then @@ -68,9 +78,12 @@ return { vim.api.nvim_create_autocmd("BufLeave", { pattern = "*", callback = function() - if vim.bo.filetype == "neo-tree" then - require("barbar.api").set_offset(0) - end + -- ⚠️ 只有在「沒有任何 neo-tree 視窗」時才清除 offset + vim.defer_fn(function() + if not neo_tree_is_visible() then + require("barbar.api").set_offset(0) + end + end, 10) -- 使用 defer 確保事件序列完成 end, })