Skip to content

Commit

Permalink
feat(tabs): sort by tab number instead of tab id (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwblokzijl committed Oct 24, 2022
1 parent e70be62 commit d358641
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 1 addition & 4 deletions lua/bufferline/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,7 @@ function Config:resolve(defaults)

if self:is_tabline() then
local opts = defaults.options
-- If the sort by mechanism is "tabs" but the user is in tabline mode
-- then the id will be that of the tabs so sort by should be id i.e. "tabs" sort
-- is redundant in tabs mode
if opts.sort_by == "tabs" then opts.sort_by = "id" end
opts.sort_by = "tabs"
if opts.show_tab_indicators then opts.show_tab_indicators = false end
opts.close_command = utils.close_tab
opts.right_mouse_command = "tabclose %d"
Expand Down
8 changes: 7 additions & 1 deletion lua/bufferline/sorters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ end

--- @param buf_a NvimBuffer
--- @param buf_b NvimBuffer
local function sort_by_tabpage_number(buf_a, buf_b)
local a = vim.api.nvim_tabpage_get_number(buf_a.id)
local b = vim.api.nvim_tabpage_get_number(buf_b.id)
return a < b
end

local function sort_by_tabs(buf_a, buf_b)
local buf_a_tabnr = init_buffer_tabnr(buf_a)
local buf_b_tabnr = init_buffer_tabnr(buf_b)
Expand Down Expand Up @@ -139,7 +145,7 @@ function M.sort(elements, sort_by, state)
elseif sort_by == "id" then
table.sort(elements, sort_by_id)
elseif sort_by == "tabs" then
table.sort(elements, config:is_tabline() and sort_by_id or sort_by_tabs)
table.sort(elements, config:is_tabline() and sort_by_tabpage_number or sort_by_tabs)
elseif type(sort_by) == "function" then
table.sort(elements, sort_by)
end
Expand Down

0 comments on commit d358641

Please sign in to comment.