Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lua/bufferline/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function M.fold(callback, list, accum)
return accum
end

---Strip whitespace from a string
---@param str string
function M.stripString(str)
return str:gsub("^%s*(.-)%s*$", "%1")
end

---Variant of some that sums up the display size of characters
---@vararg string
---@return integer
Expand Down
38 changes: 38 additions & 0 deletions lua/resession/extensions/bufferline.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
local tabPages = require('bufferline.tabpages')
local util = require('bufferline.utils')

local M = {}

function M.on_save()
local tabs = tabPages.get()
local tabNames = {}
for tabIndex, componentData in ipairs(tabs) do
local components = componentData.component

-- a little gross, but this will work - see tabPages.lua:render()
local titleComponent = vim.tbl_filter(
function(comp) return comp.attr ~= nil end,
components
)[1]
tabNames[#tabNames+1] = titleComponent.text
end
return tabNames
end


function M.on_post_load(tabNames)

-- Start from the *current* tab index, and wraparound
local tabId = vim.api.nvim_win_get_tabpage(0)
local tabIndex = vim.api.nvim_tabpage_get_number(tabId)
for _, _ in ipairs(tabNames) do
local tabName = tabNames[tabIndex]
tabPages.rename_tab(tabIndex, util.stripString(tabName))
tabIndex = tabIndex+1
if tabIndex > #tabNames then tabIndex = 1 end
vim.cmd('tabnext')
end
end

return M