mirror of
https://github.com/CompeyDev/my-nvim-setup.git
synced 2024-12-12 12:50:37 +00:00
fix hidden buffer tabs not showing in tabufline with less space
credits to @ii14 for helping me fix this issue
This commit is contained in:
parent
ae77406a64
commit
d4c71e1472
2 changed files with 59 additions and 38 deletions
|
@ -137,8 +137,7 @@ end
|
|||
M.load_override = function(default_table, plugin_name)
|
||||
local user_table = M.load_config().plugins.override[plugin_name] or {}
|
||||
user_table = type(user_table) == "table" and user_table or user_table()
|
||||
|
||||
return user_table and merge_tb("force", default_table, user_table)
|
||||
return merge_tb("force", default_table, user_table)
|
||||
end
|
||||
|
||||
M.packer_sync = function(...)
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
require("base46").load_highlight "tbline"
|
||||
local api = vim.api
|
||||
local devicons_present, devicons = pcall(require, "nvim-web-devicons")
|
||||
local fn = vim.fn
|
||||
local new_cmd = api.nvim_create_user_command
|
||||
|
||||
require("base46").load_highlight "tbline"
|
||||
|
||||
---------------------------------------------------------- btn onclick functions ----------------------------------------------
|
||||
|
||||
-- btn click functions
|
||||
vim.cmd "function! TbGoToBuf(bufnr,b,c,d) \n execute 'b'..a:bufnr \n endfunction"
|
||||
|
||||
vim.cmd [[
|
||||
|
@ -16,10 +21,7 @@ vim.cmd "function! TbCloseAllBufs(a,b,c,d) \n lua require('core.utils').closeAll
|
|||
vim.cmd "function! TbToggle_theme(a,b,c,d) \n lua require('base46').toggle_theme() \n endfunction"
|
||||
vim.cmd "function! TbToggleTabs(a,b,c,d) \n let g:TbTabsToggled = !g:TbTabsToggled | redrawtabline \n endfunction"
|
||||
|
||||
local devicons_present, devicons = pcall(require, "nvim-web-devicons")
|
||||
local fn = vim.fn
|
||||
local new_cmd = api.nvim_create_user_command
|
||||
|
||||
---------------------------------------------------------- commands ------------------------------------------------------------
|
||||
new_cmd("Tbufnext", function()
|
||||
require("core.utils").tabuflineNext()
|
||||
end, {})
|
||||
|
@ -32,6 +34,7 @@ new_cmd("Tbufclose", function()
|
|||
require("core.utils").close_buffer()
|
||||
end, {})
|
||||
|
||||
-------------------------------------------------------- functions ------------------------------------------------------------
|
||||
local function new_hl(group1, group2)
|
||||
local fg = fn.synIDattr(fn.synIDtrans(fn.hlID(group1)), "fg#")
|
||||
local bg = fn.synIDattr(fn.synIDtrans(fn.hlID(group2)), "bg#")
|
||||
|
@ -48,11 +51,13 @@ local function getNvimTreeWidth()
|
|||
return 0
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
-- covers area of nvimtree on tabufline
|
||||
M.NvimTreeOffset = function()
|
||||
return "%#NvimTreeNormal#" .. string.rep(" ", getNvimTreeWidth())
|
||||
local function getBtnsWidth()
|
||||
local width = 6
|
||||
if fn.tabpagenr "$" ~= 1 then
|
||||
width = width + ((3 * fn.tabpagenr "$") + 2) + 10
|
||||
width = not vim.g.TbTabsToggled and 8 or width
|
||||
end
|
||||
return width
|
||||
end
|
||||
|
||||
local function add_fileInfo(name, bufnr)
|
||||
|
@ -79,35 +84,54 @@ local function add_fileInfo(name, bufnr)
|
|||
end
|
||||
end
|
||||
|
||||
local function styleBufferTab(nr)
|
||||
local close_btn = "%" .. nr .. "@TbKillBuf@ %X"
|
||||
local name = (#api.nvim_buf_get_name(nr) ~= 0) and fn.fnamemodify(api.nvim_buf_get_name(nr), ":t") or " No Name "
|
||||
name = "%" .. nr .. "@TbGoToBuf@" .. add_fileInfo(name, nr) .. "%X"
|
||||
|
||||
-- color close btn for focused / hidden buffers
|
||||
if nr == api.nvim_get_current_buf() then
|
||||
close_btn = (vim.bo[0].modified and "%" .. nr .. "@TbKillBuf@%#TbLineBufOnModified# ")
|
||||
or ("%#TbLineBufOnClose#" .. close_btn)
|
||||
name = "%#TbLineBufOn#" .. name .. close_btn
|
||||
else
|
||||
close_btn = (vim.bo[nr].modified and "%" .. nr .. "@TbKillBuf@%#TbBufLineBufOffModified# ")
|
||||
or ("%#TbLineBufOffClose#" .. close_btn)
|
||||
name = "%#TbLineBufOff#" .. name .. close_btn
|
||||
end
|
||||
|
||||
return name
|
||||
end
|
||||
|
||||
---------------------------------------------------------- components ------------------------------------------------------------
|
||||
local M = {}
|
||||
|
||||
M.CoverNvimTree = function()
|
||||
return "%#NvimTreeNormal#" .. string.rep(" ", getNvimTreeWidth())
|
||||
end
|
||||
|
||||
M.bufferlist = function()
|
||||
local buffers = ""
|
||||
local buffers = {} -- buffersults
|
||||
local available_space = vim.o.columns - getNvimTreeWidth() - getBtnsWidth()
|
||||
local current_buf = api.nvim_get_current_buf()
|
||||
local has_current = false -- have we seen current buffer yet?
|
||||
|
||||
for index, nr in ipairs(vim.t.bufs or {}) do -- buf = bufnr
|
||||
if api.nvim_buf_is_valid(nr) then
|
||||
local close_btn = "%" .. nr .. "@TbKillBuf@ %X"
|
||||
local name = (#api.nvim_buf_get_name(nr) ~= 0) and fn.fnamemodify(api.nvim_buf_get_name(nr), ":t")
|
||||
or " No Name "
|
||||
for _, bufnr in ipairs(vim.t.bufs) do
|
||||
if api.nvim_buf_is_valid(bufnr) then
|
||||
if ((#buffers + 1) * 21) > available_space then
|
||||
if has_current then
|
||||
break
|
||||
end
|
||||
|
||||
name = "%" .. nr .. "@TbGoToBuf@" .. add_fileInfo(name, nr) .. "%X"
|
||||
|
||||
-- color close btn for focused / hidden buffers
|
||||
if nr == api.nvim_get_current_buf() then
|
||||
close_btn = (vim.bo[0].modified and "%" .. nr .. "@TbKillBuf@%#TbLineBufOnModified# ")
|
||||
or ("%#TbLineBufOnClose#" .. close_btn)
|
||||
name = "%#TbLineBufOn#" .. name .. close_btn
|
||||
else
|
||||
close_btn = (vim.bo[nr].modified and "%" .. nr .. "@TbKillBuf@%#TbBufLineBufOffModified# ")
|
||||
or ("%#TbLineBufOffClose#" .. close_btn)
|
||||
name = "%#TbLineBufOff#" .. name .. close_btn
|
||||
table.remove(buffers, 1)
|
||||
end
|
||||
|
||||
-- 1 buffer tab = 21 whitespaces
|
||||
buffers = (21 * index + getNvimTreeWidth() < vim.o.columns - getNvimTreeWidth()) and buffers .. name
|
||||
or buffers .. ""
|
||||
has_current = (bufnr == current_buf and true) or has_current
|
||||
table.insert(buffers, styleBufferTab(bufnr))
|
||||
end
|
||||
end
|
||||
|
||||
return buffers .. "%#TblineFill#" .. "%=" -- buffers + empty space
|
||||
return table.concat(buffers) .. "%#TblineFill#" .. "%=" -- buffers + empty space
|
||||
end
|
||||
|
||||
vim.g.TbTabsToggled = 0
|
||||
|
@ -125,10 +149,8 @@ M.tablist = function()
|
|||
local new_tabtn = "%#TblineTabNewBtn#" .. "%@TbNewTab@ %X"
|
||||
local tabstoggleBtn = "%@TbToggleTabs@ %#TBTabTitle# TABS %X"
|
||||
|
||||
result = (vim.g.TbTabsToggled == 1 and tabstoggleBtn:gsub("()", { [36] = " " }))
|
||||
return vim.g.TbTabsToggled == 1 and tabstoggleBtn:gsub("()", { [36] = " " })
|
||||
or new_tabtn .. tabstoggleBtn .. result
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -139,7 +161,7 @@ M.buttons = function()
|
|||
end
|
||||
|
||||
M.run = function()
|
||||
return M.NvimTreeOffset() .. M.bufferlist() .. (M.tablist() or "") .. M.buttons()
|
||||
return M.CoverNvimTree() .. M.bufferlist() .. (M.tablist() or "") .. M.buttons()
|
||||
end
|
||||
|
||||
M = vim.tbl_deep_extend("force", M, require("core.utils").load_config().ui.tabufline.override)
|
||||
|
|
Loading…
Reference in a new issue