@@ -19,20 +19,15 @@ local mode = utils.mode
1919
2020M .statusline_ft = {}
2121
22- local is_width_valid = function (width , winnr )
23- if width == nil then return true end
24- return api .nvim_win_is_valid (winnr )
25- and width < api .nvim_win_get_width (winnr )
26- end
27-
2822local render = function (bufnr , winnr , items , cache )
2923 M .state .comp = {} -- reset component data
3024 M .state .mode = mode ()
3125 Comp .reset ()
3226 local status = ' '
27+ local win_width = api .nvim_win_is_valid (winnr ) and api .nvim_win_get_width (winnr )
3328 for _ , comp in pairs (items ) do
34- if is_width_valid (comp .width , winnr ) then
35- status = status .. comp :render (bufnr , winnr )
29+ if win_width and (comp .width == nil or comp . width < win_width ) then
30+ status = status .. comp :render (bufnr , winnr , win_width )
3631 end
3732 end
3833 if cache then
@@ -268,8 +263,8 @@ M.benchmark = function()
268263 local bench = require (' plenary.profile' ).benchmark
269264 local statusline = ' '
270265 local time = bench (num , function ()
271- vim .g .statusline_winid = vim . api .nvim_get_current_win ()
272- statusline = WindLine .show (vim . api .nvim_get_current_buf (), vim .g .statusline_winid )
266+ vim .g .statusline_winid = api .nvim_get_current_win ()
267+ statusline = WindLine .show (api .nvim_get_current_buf (), vim .g .statusline_winid )
273268 end )
274269 local popup = require (' plenary.popup' )
275270 local result = {}
@@ -279,18 +274,19 @@ M.benchmark = function()
279274 table.insert (result , string.format (' render %s time : *%s*' , num , time ))
280275 table.insert (result , ' Comp:' )
281276 local line = M .get_statusline_ft (vim .bo .filetype ) or M .default_line
282- local bufnr = vim .api .nvim_get_current_buf ()
283- local winnr = vim .api .nvim_get_current_win ()
277+ local bufnr = api .nvim_get_current_buf ()
278+ local winnr = api .nvim_get_current_win ()
279+ local width = api .nvim_win_get_width (0 )
284280 table.insert (result , string.format (' %s %12s %12s %s %s' , ' ' , ' time' , ' name' , ' num ' , ' text' ))
285281 for index , comp in ipairs (line .active ) do
286282 local item = ' '
287283 time = bench (num , function ()
288- item = comp :render (bufnr , winnr )
284+ item = comp :render (bufnr , winnr , width )
289285 end )
290286 table.insert (result , string.format (' %02d *%10s* %12s %s - %s' , index , time , comp .name or ' ' , num , item ))
291287 end
292- local width = math.floor (vim .o .columns / 1.5 )
293- local col = math.floor ((vim .o .columns - width ) / 2 )
288+ local vim_width = math.floor (vim .o .columns / 1.5 )
289+ local col = math.floor ((vim .o .columns - vim_width ) / 2 )
294290 popup .create (result , {
295291 border = {},
296292 minheight = 30 ,
0 commit comments