fix: LualineRenameTab crashing lualine

fixes https://github.com/nvim-lualine/lualine.nvim/pull/574#pullrequestreview-874872853

Issue was neovim's tabpage handle used by rpc-api isn't same as tab no
in viml.
Now the tabpage handle is stores in self.tabId and tab no is stored in
self.tabnr in `Tab` so any can be used when necessary.
This commit is contained in:
shadmansaleh 2022-02-07 22:13:42 +06:00
parent 9420fed0b1
commit 98dc2dd3a2
2 changed files with 10 additions and 4 deletions

View File

@ -57,8 +57,8 @@ end
function M:update_status()
local data = {}
local tabs = {}
for t = 1, vim.fn.tabpagenr('$') do
tabs[#tabs + 1] = Tab { tabnr = t, options = self.options, highlights = self.highlights }
for nr, id in ipairs(vim.api.nvim_list_tabpages()) do
tabs[#tabs + 1] = Tab { tabId = id, tabnr = nr, options = self.options, highlights = self.highlights }
end
-- mark the first, last, current, before current, after current tabpages
-- for rendering
@ -93,7 +93,12 @@ function M:update_status()
-- start drawing from current tab and draw left and right of it until
-- all tabpages are drawn or max_length has been reached.
if current_tab == nil then -- maybe redundent code
local t = Tab { tabnr = vim.fn.tabpagenr(), options = self.options, highlights = self.highlights }
local t = Tab {
tabId = vim.api.nvim_get_current_tabpage(),
tabnr = vim.fn.tabpagenr(),
options = self.options,
highlights = self.highlights,
}
t.current = true
t.last = true
data[#data + 1] = t:render()

View File

@ -6,6 +6,7 @@ local Tab = require('lualine.utils.class'):extend()
function Tab:init(opts)
assert(opts.tabnr, 'Cannot create Tab without tabnr')
self.tabnr = opts.tabnr
self.tabId = opts.tabId
self.options = opts.options
self.highlights = opts.highlights
end
@ -14,7 +15,7 @@ end
--- of the tab.
---@return string
function Tab:label()
local custom_tabname = vim.t[self.tabnr].tabname
local custom_tabname = vim.t[self.tabId].tabname
if custom_tabname and custom_tabname ~= '' then
return custom_tabname
end