Skip to content

Commit

Permalink
barbar: update tree offset handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Jun 7, 2024
1 parent a14894f commit d691d74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lua/nxvim/plugins/barbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ require("barbar").setup({

-- { == Events ==> ============================================================

local barbar_api = require("barbar.api")

nx.au({
"FileType",
pattern = { "NeogitStatus", "DiffviewFiles" },
callback = function()
vim.defer_fn(function() require("barbar.api").set_offset(0) end, 75)
vim.defer_fn(function() barbar_api.set_offset(0) end, 75)
end,
})
-- <== }
Expand Down
23 changes: 13 additions & 10 deletions lua/nxvim/plugins/neo-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ local neo_tree_win = {
}

local barbar_ok, barbar_api = pcall(require, "barbar.api")
local utils = require("nxvim.utils")
local spacer = (" "):rep(5)

local function set_offset()
if not barbar_ok then return end
local title = " ó°™… " .. utils.truc_path(vim.fn.getcwd())
local space = neo_tree_win.width - title:len()
local filler = space > 0 and (" "):rep(neo_tree_win.width - title:len()) or ""
barbar_api.set_offset(neo_tree_win.width + 2, title .. filler .. spacer)
end

config.event_handlers = {
{
Expand Down Expand Up @@ -204,11 +214,8 @@ nx.au({
"DirChanged",
callback = function()
if vim.api.nvim_win_is_valid(neo_tree_win.id) then
if not barbar_ok then return end
barbar_api.set_offset(
vim.api.nvim_win_get_width(neo_tree_win.id),
"ó°™… " .. require("nxvim.utils").truc_path(vim.fn.getcwd())
)
neo_tree_win.width = vim.api.nvim_win_get_width(neo_tree_win.id)
set_offset()
end
end,
},
Expand All @@ -217,11 +224,7 @@ nx.au({
callback = function()
if vim.api.nvim_win_is_valid(neo_tree_win.id) then
neo_tree_win.width = vim.api.nvim_win_get_width(neo_tree_win.id)
if not barbar_ok then return end
barbar_api.set_offset(
vim.api.nvim_win_get_width(neo_tree_win.id),
"ó°™… " .. require("nxvim.utils").truc_path(vim.fn.getcwd())
)
set_offset()
end
end,
},
Expand Down

0 comments on commit d691d74

Please sign in to comment.