Skip to content

Commit

Permalink
v3.1.0
Browse files Browse the repository at this point in the history
* feat(tabs): sort by tab number instead of tab id (#592)
  • Loading branch information
akinsho committed Oct 28, 2022
2 parents e70be62 + 5d60a35 commit 028a879
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ it has a lot of the same features/styling but not all.

A few things to note are

- Diagnostics only show if the buffer with issues is the current window selected in that tab page
- Sorting doesn't work yet as that needs to be thought through.
- Grouping doesn't work yet as that also needs to be thought through.

Expand Down
4 changes: 1 addition & 3 deletions doc/bufferline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ This plugin can also be set to show only tabpages. This can be done by setting
the `mode` option to `tabs`. This will change the bufferline to a tabline it
has a lot of the same features/styling but not all. A few things to note are

* Diagnostics only show if the buffer with issues is the current window selected
in that tab page.
* Sorting doesn't work yet as that needs to be thought through.
* Grouping doesn't work yet as that also needs to be thought through.

Expand Down Expand Up @@ -1073,7 +1071,7 @@ WORKING WITH ELEMENTS *bufferline-working-with-elements*

Bufferline exposes some information about the buffers it shows will allow you
to implement your own custom functionality. Note that this will not include any
buffers that are filtered out of bufferline, making it handy for writing
buffers that are filtered out of bufferline, making it handy for writing
functions that need to ignore special buffers.

The output has the following structure:
Expand Down
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 028a879

Please sign in to comment.