8000 fix: use correct maximum width for global statusline by famiu · Pull Request #237 · famiu/feline.nvim · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

fix: use correct maximum width for global statusline #237

Merged
merged 1 commit into from
Mar 18, 2022
Merged
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
21 changes: 15 additions & 6 deletions lua/feline/generator.lua
8000
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local bo = vim.bo
local api = vim.api
local opt = vim.opt

local feline = require('feline')
local utils = require('feline.utils')
Expand Down Expand Up @@ -545,10 +546,18 @@ function M.generate_statusline(is_active)
end
end

local window_width = api.nvim_win_get_width(0)
local maxwidth

-- If statusline width is greater than the window width, begin the truncation process
if statusline_width > window_width then
-- If statusline is global, use entire Neovim window width for maxwidth
-- Otherwise just use width of current window
if opt.laststatus:get() == 3 then
maxwidth = opt.columns:get()
else
maxwidth = api.nvim_win_get_width(0)
end

-- If statusline width is greater than maxwidth, begin the truncation process
if statusline_width > maxwidth then
-- First, sort the component indices in ascending order of the priority of the components
-- that the indices refer to
table.sort(component_indices, function(first, second)
Expand Down Expand Up @@ -594,15 +603,15 @@ function M.generate_statusline(is_active)
end
end

if statusline_width <= window_width then
if statusline_width <= maxwidth then
break
end
end
end

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

if statusline_width <= window_width then
if statusline_width <= maxwidth then
break
end
end
Expand Down
0