nanozuki / tabby.nvim

A declarative, highly configurable, and neovim style tabline plugin. Use your nvim tabs as a workspace multiplexer!
MIT License
563 stars 21 forks source link

It seems that the `line.spacer()` doesn't work correctly #97

Closed nyngwang closed 1 year ago

nyngwang commented 1 year ago

DEMO

https://user-images.githubusercontent.com/24765272/204909458-341235b7-e6af-4207-9f38-ff0684aa918c.mov

Description

Notice that when I toggled between tabs 1 and 2, the position of 1 and 2 changed. I think the culprit is that when the length of the current buffername changed, the spacer seems to still add the same number of spaces. In the demo, since the buffername plugins.lua is longer than [No Name], both 1 and 2 were pushed more to the right.

nanozuki commented 1 year ago

Can you show me your config?

nyngwang commented 1 year ago

@nanozuki

use {
  'nanozuki/tabby.nvim',
  config = function ()
    local theme = {
      fill = 'TabLine',
      head = 'TabLine',
      current_tab = 'TabLineSel',
      tab = 'TabLine',
      win = 'TabLineSel',
      tail = 'TabLine',
    }
    require('tabby.tabline').set(function(line)
      return {
        {
          { '    ', hl = theme.head },
        },
        line.wins_in_tab(line.api.get_current_tab()).foreach(function(win)
          if not vim.api.nvim_buf_get_option(win.buf().id, 'buflisted') then return {} end
          local hl = win.is_current() and theme.win or theme.fill
          local rhl = win.is_current() and theme.fill or theme.win
          return {
            line.sep(win.is_current() and '' or '', hl, rhl),
            win.is_current() and ' ' or '',
            win.buf_name(),
            line.sep(win.is_current() and '' or '', hl, rhl),
            line.sep(' ', theme.fill, theme.fill),
            hl = hl,
            margin = '',
          }
        end),
        line.spacer(),
        line.tabs().foreach(function(tab)
          local hl = tab.is_current() and theme.current_tab or theme.tab
          local rhl = tab.is_current() and theme.tab or theme.current_tab
          return {
            line.sep(tab.is_current() and ' ' or '', hl, rhl),
            tab.number(),
            line.sep(tab.is_current() and ' ' or '', hl, rhl),
            line.sep(' ', theme.fill, theme.fill),
            hl = hl, margin = '',
          }
        end),
        {
          line.sep(' ', theme.tail, theme.tail),
          line.sep(' ', theme.tail, theme.tail),
        },
        hl = theme.fill,
      }
    end)
  end
}
nanozuki commented 1 year ago

Sorry for late, I've been a little busy in my daily life lately. the problem is, the label's width of current win and non-current win is not equal. One is 1, another one is 2. So, then the current window changed, the label's position is changed. Maybe you can change config to:

line.sep(win.is_current() and '' or ' ', hl, rhl),