fix #1276
This commit is contained in:
parent
519a2df1a0
commit
ae77406a64
2 changed files with 37 additions and 33 deletions
|
@ -5,25 +5,15 @@ local merge_tb = vim.tbl_deep_extend
|
||||||
|
|
||||||
M.close_buffer = function(bufnr)
|
M.close_buffer = function(bufnr)
|
||||||
if vim.bo.buftype == "terminal" then
|
if vim.bo.buftype == "terminal" then
|
||||||
if vim.bo.buflisted then
|
vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide")
|
||||||
vim.bo.buflisted = false
|
elseif vim.bo.modified then
|
||||||
vim.cmd "enew"
|
print "save the file bruh"
|
||||||
else
|
else
|
||||||
vim.cmd "hide"
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- if file doesnt exist & its modified
|
|
||||||
if vim.bo.modified then
|
|
||||||
print "save the file!"
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
bufnr = bufnr or api.nvim_get_current_buf()
|
bufnr = bufnr or api.nvim_get_current_buf()
|
||||||
require("core.utils").tabuflinePrev()
|
require("core.utils").tabuflinePrev()
|
||||||
vim.cmd("bd" .. bufnr)
|
vim.cmd("bd" .. bufnr)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.load_config = function()
|
M.load_config = function()
|
||||||
local config = require "core.default_config"
|
local config = require "core.default_config"
|
||||||
|
@ -144,7 +134,6 @@ M.merge_plugins = function(default_plugins)
|
||||||
return final_table
|
return final_table
|
||||||
end
|
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()
|
||||||
|
@ -225,13 +214,19 @@ end
|
||||||
|
|
||||||
-- closes tab + all of its buffers
|
-- closes tab + all of its buffers
|
||||||
M.closeAllBufs = function(action)
|
M.closeAllBufs = function(action)
|
||||||
local bufs = vim.t.bufs or {}
|
local bufs = vim.t.bufs
|
||||||
|
|
||||||
|
if action == "closeTab" then
|
||||||
|
vim.cmd "tabclose"
|
||||||
|
end
|
||||||
|
|
||||||
for _, buf in ipairs(bufs) do
|
for _, buf in ipairs(bufs) do
|
||||||
M.close_buffer(buf)
|
M.close_buffer(buf)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.cmd(action == "closeTab" and "tabclose" or "enew")
|
if action ~= "closeTab" then
|
||||||
|
vim.cmd "enew"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -39,15 +39,20 @@ local function new_hl(group1, group2)
|
||||||
return "%#" .. "Tbline" .. group1 .. group2 .. "#"
|
return "%#" .. "Tbline" .. group1 .. group2 .. "#"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function getNvimTreeWidth()
|
||||||
|
for _, win in pairs(api.nvim_tabpage_list_wins(0)) do
|
||||||
|
if vim.bo[api.nvim_win_get_buf(win)].ft == "NvimTree" then
|
||||||
|
return api.nvim_win_get_width(win) + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- covers area of nvimtree on tabufline
|
-- covers area of nvimtree on tabufline
|
||||||
M.Offset = function()
|
M.NvimTreeOffset = function()
|
||||||
for _, win in pairs(api.nvim_tabpage_list_wins(0)) do
|
return "%#NvimTreeNormal#" .. string.rep(" ", getNvimTreeWidth())
|
||||||
if vim.bo[api.nvim_win_get_buf(win)].ft == "NvimTree" then
|
|
||||||
return "%#NvimTreeNormal#" .. string.rep(" ", api.nvim_win_get_width(win) + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add_fileInfo(name, bufnr)
|
local function add_fileInfo(name, bufnr)
|
||||||
|
@ -66,7 +71,7 @@ local function add_fileInfo(name, bufnr)
|
||||||
or new_hl(icon_hl, "TbLineBufOff") .. " " .. icon
|
or new_hl(icon_hl, "TbLineBufOff") .. " " .. icon
|
||||||
)
|
)
|
||||||
|
|
||||||
name = (#name > 20 and string.sub(name, 1, 15) .. "...") or name
|
name = (#name > 15 and string.sub(name, 1, 13) .. "..") or name
|
||||||
name = (api.nvim_get_current_buf() == bufnr and "%#TbLineBufOn# " .. name .. " ")
|
name = (api.nvim_get_current_buf() == bufnr and "%#TbLineBufOn# " .. name .. " ")
|
||||||
or ("%#TbLineBufOff# " .. name .. " ")
|
or ("%#TbLineBufOff# " .. name .. " ")
|
||||||
|
|
||||||
|
@ -77,24 +82,28 @@ end
|
||||||
M.bufferlist = function()
|
M.bufferlist = function()
|
||||||
local buffers = ""
|
local buffers = ""
|
||||||
|
|
||||||
for _, nr in ipairs(vim.t.bufs or {}) do -- buf = bufnr
|
for index, nr in ipairs(vim.t.bufs or {}) do -- buf = bufnr
|
||||||
if api.nvim_buf_is_valid(nr) then
|
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")
|
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 "
|
||||||
local close_btn = "%" .. nr .. "@TbKillBuf@ %X"
|
|
||||||
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
|
||||||
if nr == api.nvim_get_current_buf() then
|
if nr == api.nvim_get_current_buf() then
|
||||||
close_btn = (vim.bo[0].modified and "%#TbLineBufOnModified# ") or ("%#TbLineBufOnClose#" .. close_btn)
|
close_btn = (vim.bo[0].modified and "%" .. nr .. "@TbKillBuf@%#TbLineBufOnModified# ")
|
||||||
|
or ("%#TbLineBufOnClose#" .. close_btn)
|
||||||
name = "%#TbLineBufOn#" .. name .. close_btn
|
name = "%#TbLineBufOn#" .. name .. close_btn
|
||||||
else
|
else
|
||||||
close_btn = (vim.bo[nr].modified and "%#TbBufLineBufOffModified# ")
|
close_btn = (vim.bo[nr].modified and "%" .. nr .. "@TbKillBuf@%#TbBufLineBufOffModified# ")
|
||||||
or ("%#TbLineBufOffClose#" .. close_btn)
|
or ("%#TbLineBufOffClose#" .. close_btn)
|
||||||
name = "%#TbLineBufOff#" .. name .. close_btn
|
name = "%#TbLineBufOff#" .. name .. close_btn
|
||||||
end
|
end
|
||||||
|
|
||||||
buffers = buffers .. name
|
-- 1 buffer tab = 21 whitespaces
|
||||||
|
buffers = (21 * index + getNvimTreeWidth() < vim.o.columns - getNvimTreeWidth()) and buffers .. name
|
||||||
|
or buffers .. ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -130,7 +139,7 @@ M.buttons = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.run = function()
|
M.run = function()
|
||||||
return (M.Offset() or "") .. M.bufferlist() .. (M.tablist() or "") .. M.buttons()
|
return M.NvimTreeOffset() .. 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 a new issue