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
@ -137,8 +137,7 @@ end
|
|||||||
M.load_override = function(default_table, plugin_name)
|
M.load_override = function(default_table, plugin_name)
|
||||||
local user_table = M.load_config().plugins.override[plugin_name] or {}
|
local user_table = M.load_config().plugins.override[plugin_name] or {}
|
||||||
user_table = type(user_table) == "table" and user_table or user_table()
|
user_table = type(user_table) == "table" and user_table or user_table()
|
||||||
|
return merge_tb("force", default_table, user_table)
|
||||||
return user_table and merge_tb("force", default_table, user_table)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
M.packer_sync = function(...)
|
M.packer_sync = function(...)
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
require("base46").load_highlight "tbline"
|
|
||||||
local api = vim.api
|
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 "function! TbGoToBuf(bufnr,b,c,d) \n execute 'b'..a:bufnr \n endfunction"
|
||||||
|
|
||||||
vim.cmd [[
|
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! 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"
|
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")
|
---------------------------------------------------------- commands ------------------------------------------------------------
|
||||||
local fn = vim.fn
|
|
||||||
local new_cmd = api.nvim_create_user_command
|
|
||||||
|
|
||||||
new_cmd("Tbufnext", function()
|
new_cmd("Tbufnext", function()
|
||||||
require("core.utils").tabuflineNext()
|
require("core.utils").tabuflineNext()
|
||||||
end, {})
|
end, {})
|
||||||
@ -32,6 +34,7 @@ new_cmd("Tbufclose", function()
|
|||||||
require("core.utils").close_buffer()
|
require("core.utils").close_buffer()
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
|
-------------------------------------------------------- functions ------------------------------------------------------------
|
||||||
local function new_hl(group1, group2)
|
local function new_hl(group1, group2)
|
||||||
local fg = fn.synIDattr(fn.synIDtrans(fn.hlID(group1)), "fg#")
|
local fg = fn.synIDattr(fn.synIDtrans(fn.hlID(group1)), "fg#")
|
||||||
local bg = fn.synIDattr(fn.synIDtrans(fn.hlID(group2)), "bg#")
|
local bg = fn.synIDattr(fn.synIDtrans(fn.hlID(group2)), "bg#")
|
||||||
@ -48,11 +51,13 @@ local function getNvimTreeWidth()
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local M = {}
|
local function getBtnsWidth()
|
||||||
|
local width = 6
|
||||||
-- covers area of nvimtree on tabufline
|
if fn.tabpagenr "$" ~= 1 then
|
||||||
M.NvimTreeOffset = function()
|
width = width + ((3 * fn.tabpagenr "$") + 2) + 10
|
||||||
return "%#NvimTreeNormal#" .. string.rep(" ", getNvimTreeWidth())
|
width = not vim.g.TbTabsToggled and 8 or width
|
||||||
|
end
|
||||||
|
return width
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_fileInfo(name, bufnr)
|
local function add_fileInfo(name, bufnr)
|
||||||
@ -79,15 +84,9 @@ local function add_fileInfo(name, bufnr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.bufferlist = function()
|
local function styleBufferTab(nr)
|
||||||
local buffers = ""
|
|
||||||
|
|
||||||
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 close_btn = "%" .. nr .. "@TbKillBuf@ %X"
|
||||||
local name = (#api.nvim_buf_get_name(nr) ~= 0) and fn.fnamemodify(api.nvim_buf_get_name(nr), ":t")
|
local name = (#api.nvim_buf_get_name(nr) ~= 0) and fn.fnamemodify(api.nvim_buf_get_name(nr), ":t") or " No Name "
|
||||||
or " No Name "
|
|
||||||
|
|
||||||
name = "%" .. nr .. "@TbGoToBuf@" .. add_fileInfo(name, nr) .. "%X"
|
name = "%" .. nr .. "@TbGoToBuf@" .. add_fileInfo(name, nr) .. "%X"
|
||||||
|
|
||||||
-- color close btn for focused / hidden buffers
|
-- color close btn for focused / hidden buffers
|
||||||
@ -101,13 +100,38 @@ M.bufferlist = function()
|
|||||||
name = "%#TbLineBufOff#" .. name .. close_btn
|
name = "%#TbLineBufOff#" .. name .. close_btn
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 1 buffer tab = 21 whitespaces
|
return name
|
||||||
buffers = (21 * index + getNvimTreeWidth() < vim.o.columns - getNvimTreeWidth()) and buffers .. name
|
end
|
||||||
or buffers .. ""
|
|
||||||
|
---------------------------------------------------------- components ------------------------------------------------------------
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.CoverNvimTree = function()
|
||||||
|
return "%#NvimTreeNormal#" .. string.rep(" ", getNvimTreeWidth())
|
||||||
|
end
|
||||||
|
|
||||||
|
M.bufferlist = function()
|
||||||
|
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 _, 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
|
||||||
|
|
||||||
|
table.remove(buffers, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
has_current = (bufnr == current_buf and true) or has_current
|
||||||
|
table.insert(buffers, styleBufferTab(bufnr))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return buffers .. "%#TblineFill#" .. "%=" -- buffers + empty space
|
return table.concat(buffers) .. "%#TblineFill#" .. "%=" -- buffers + empty space
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.g.TbTabsToggled = 0
|
vim.g.TbTabsToggled = 0
|
||||||
@ -125,10 +149,8 @@ M.tablist = function()
|
|||||||
local new_tabtn = "%#TblineTabNewBtn#" .. "%@TbNewTab@ %X"
|
local new_tabtn = "%#TblineTabNewBtn#" .. "%@TbNewTab@ %X"
|
||||||
local tabstoggleBtn = "%@TbToggleTabs@ %#TBTabTitle# TABS %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
|
or new_tabtn .. tabstoggleBtn .. result
|
||||||
|
|
||||||
return result
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -139,7 +161,7 @@ M.buttons = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.run = function()
|
M.run = function()
|
||||||
return M.NvimTreeOffset() .. M.bufferlist() .. (M.tablist() or "") .. M.buttons()
|
return M.CoverNvimTree() .. M.bufferlist() .. (M.tablist() or "") .. M.buttons()
|
||||||
end
|
end
|
||||||
|
|
||||||
M = vim.tbl_deep_extend("force", M, require("core.utils").load_config().ui.tabufline.override)
|
M = vim.tbl_deep_extend("force", M, require("core.utils").load_config().ui.tabufline.override)
|
||||||
|
Loading…
Reference in New Issue
Block a user