Skip to content

Commit

Permalink
ref(render): scroll to fill tabline when closing a buffer (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iron-E authored May 12, 2023
1 parent cdb43e6 commit 875ae20
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lua/barbar/ui/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
--

local max = math.max
local min = math.min
local table_insert = table.insert

local buf_get_option = vim.api.nvim_buf_get_option --- @type function
Expand Down Expand Up @@ -407,17 +406,15 @@ local function get_bufferline_containers(data, bufnrs, refocus)
end
end

local scroll_current = min(scroll.current, data.buffers.scroll_max)

if pinned then
accumulated_pinned_width = accumulated_pinned_width + container_width
else
accumulated_unpinned_width = accumulated_unpinned_width + container_width

if accumulated_unpinned_width < scroll_current then
if accumulated_unpinned_width < scroll.current then
goto continue -- HACK: there is no `continue` keyword
elseif (refocus == false or (refocus ~= false and current_buffer ~= nil)) and
accumulated_unpinned_width - scroll_current > data.buffers.unpinned_allocated_width
accumulated_unpinned_width - scroll.current > data.buffers.unpinned_allocated_width
then
done = true
end
Expand Down Expand Up @@ -564,6 +561,10 @@ local HL = {
--- @return nil|string syntax
local function generate_tabline(bufnrs, refocus)
local data = layout.calculate()
if refocus ~= false and scroll.current > data.buffers.scroll_max then
render.set_scroll(data.buffers.scroll_max)
end

local pinned, unpinned, current_buffer = get_bufferline_containers(data, bufnrs, refocus)

-- Create actual tabline string
Expand Down

0 comments on commit 875ae20

Please sign in to comment.