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:
parent
9420fed0b1
commit
98dc2dd3a2
|
@ -57,8 +57,8 @@ end
|
||||||
function M:update_status()
|
function M:update_status()
|
||||||
local data = {}
|
local data = {}
|
||||||
local tabs = {}
|
local tabs = {}
|
||||||
for t = 1, vim.fn.tabpagenr('$') do
|
for nr, id in ipairs(vim.api.nvim_list_tabpages()) do
|
||||||
tabs[#tabs + 1] = Tab { tabnr = t, options = self.options, highlights = self.highlights }
|
tabs[#tabs + 1] = Tab { tabId = id, tabnr = nr, options = self.options, highlights = self.highlights }
|
||||||
end
|
end
|
||||||
-- mark the first, last, current, before current, after current tabpages
|
-- mark the first, last, current, before current, after current tabpages
|
||||||
-- for rendering
|
-- for rendering
|
||||||
|
@ -93,7 +93,12 @@ function M:update_status()
|
||||||
-- start drawing from current tab and draw left and right of it until
|
-- start drawing from current tab and draw left and right of it until
|
||||||
-- all tabpages are drawn or max_length has been reached.
|
-- all tabpages are drawn or max_length has been reached.
|
||||||
if current_tab == nil then -- maybe redundent code
|
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.current = true
|
||||||
t.last = true
|
t.last = true
|
||||||
data[#data + 1] = t:render()
|
data[#data + 1] = t:render()
|
||||||
|
|
|
@ -6,6 +6,7 @@ local Tab = require('lualine.utils.class'):extend()
|
||||||
function Tab:init(opts)
|
function Tab:init(opts)
|
||||||
assert(opts.tabnr, 'Cannot create Tab without tabnr')
|
assert(opts.tabnr, 'Cannot create Tab without tabnr')
|
||||||
self.tabnr = opts.tabnr
|
self.tabnr = opts.tabnr
|
||||||
|
self.tabId = opts.tabId
|
||||||
self.options = opts.options
|
self.options = opts.options
|
||||||
self.highlights = opts.highlights
|
self.highlights = opts.highlights
|
||||||
end
|
end
|
||||||
|
@ -14,7 +15,7 @@ end
|
||||||
--- of the tab.
|
--- of the tab.
|
||||||
---@return string
|
---@return string
|
||||||
function Tab:label()
|
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
|
if custom_tabname and custom_tabname ~= '' then
|
||||||
return custom_tabname
|
return custom_tabname
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue