Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 1bd5158

Browse files
authored
Merge pull request #240 from feline-nvim/develop
v1.1.1
2 parents d8093d2 + b13f25e commit 1bd5158

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ Two components inside the `active` or `inactive` table cannot share the same nam
204204

205205
#### Truncation
206206

207-
Feline has an automatic smart truncation system where components can be automatically truncated if the statusline doesn't fit within the window. It can be useful if you want to make better use of screen space. It also allows you to better manage which providers are truncated, how they are truncated and in which order they are truncated.
207+
Feline has an automatic smart truncation system where components can be automatically truncated if the statusline doesn't fit within the available space. It can be useful if you want to make better use of screen space. It also allows you to better manage which providers are truncated, how they are truncated and in which order they are truncated.
208208

209-
**NOTE:** Truncation currently only works with the master branch of Neovim. If you're using a stable release, truncation will not work and all configurations related to it will be silently ignored.
209+
**NOTE:** Truncation only works on Neovim 0.6 and above. If you're using an earlier release, truncation will not work and all configurations related to it will be silently ignored.
210210

211211
There are a few component values associated with truncation which are described below.
212212

doc/feline.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,17 @@ Truncation Feline has an automatic smart truncation
301301
system where components can be
302302
automatically truncated if the
303303
statusline doesn’t fit within the
304-
window. It can be useful if you want to
305-
make better use of screen space. It also
306-
allows you to better manage which
307-
providers are truncated, how they are
308-
truncated and in which order they are
309-
truncated.
304+
available space. It can be useful if you
305+
want to make better use of screen space.
306+
It also allows you to better manage
307+
which providers are truncated, how they
308+
are truncated and in which order they
309+
are truncated.
310310

311311

312-
**NOTE:** Truncation currently only works with the master branch of Neovim. If
313-
you’re using a stable release, truncation will not work and all
314-
configurations related to it will be silently ignored.
312+
**NOTE:** Truncation only works on Neovim 0.6 and above. If you’re using an
313+
earlier release, truncation will not work and all configurations related to it
314+
will be silently ignored.
315315

316316
There are a few component values associated with truncation which are described
317317
below.

lua/feline/generator.lua

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local bo = vim.bo
22
local api = vim.api
3+
local opt = vim.opt
34

45
local feline = require('feline')
56
local utils = require('feline.utils')
@@ -345,7 +346,7 @@ local function parse_provider(provider, component, is_short, winid, section_nr,
345346
component_nr
346347
),
347348
},
348-
}, 'feline', true)
349+
}, 'felineProviders', true)
349350
end
350351
end
351352

@@ -545,10 +546,18 @@ function M.generate_statusline(is_active)
545546
end
546547
end
547548

548-
local window_width = api.nvim_win_get_width(0)
549+
local maxwidth
549550

550-
-- If statusline width is greater than the window width, begin the truncation process
551-
if statusline_width > window_width then
551+
-- If statusline is global, use entire Neovim window width for maxwidth
552+
-- Otherwise just use width of current window
553+
if opt.laststatus:get() == 3 then
554+
maxwidth = opt.columns:get()
555+
else
556+
maxwidth = api.nvim_win_get_width(0)
557+
end
558+
559+
-- If statusline width is greater than maxwidth, begin the truncation process
560+
if statusline_width > maxwidth then
552561
-- First, sort the component indices in ascending order of the priority of the components
553562
-- that the indices refer to
554563
table.sort(component_indices, function(first, second)
@@ -594,15 +603,15 @@ function M.generate_statusline(is_active)
594603
end
595604
end
596605

597-
if statusline_width <= window_width then
606+
if statusline_width <= maxwidth then
598607
break
599608
end
600609
end
601610
end
602611

603612
-- If statusline still doesn't fit within window, remove components with truncate_hide set to
604613
-- true until it does
605-
if statusline_width > window_width then
614+
if statusline_width > maxwidth then
606615
for _, indices in ipairs(component_indices) do
607616
local section, number = indices[1], indices[2]
608617
local component = sections[section][number]
@@ -618,7 +627,7 @@ function M.generate_statusline(is_active)
618627
end
619628
end
620629

621-
if statusline_width <= window_width then
630+
if statusline_width <= maxwidth then
622631
break
623632
end
624633
end
@@ -643,6 +652,11 @@ function M.clear_state()
643652
provider_cache = {}
644653
short_provider_cache = {}
645654
provider_autocmd = {}
655+
-- Clear provider update autocmds
656+
if vim.fn.exists('#felineProviders') ~= 0 then
657+
api.nvim_command('autocmd! felineProviders')
658+
api.nvim_command('augroup! felineProviders')
659+
end
646660
end
647661

648662
return M

0 commit comments

Comments
 (0)