bufferline.nvim icon indicating copy to clipboard operation
bufferline.nvim copied to clipboard

feat(ui): pass formatter opts to icon fetcher as well

Open ofseed opened this issue 1 year ago • 7 comments

When a user customized the name by name_formatter, they would customize the icon too. I think it should be better to make them have the same arguments, but considering changing the arguments would be a breaking change, I recommend adding all the name_formatter properties to get_element_icon.

In my usage, I use the tab mode of bufferline, I don't want bufferline to show the name of buffers which has a special buftype when there is a normal buffer that exists in the tabpage.

ofseed avatar Jul 18 '24 11:07 ofseed

Hi @ofseed,

I'm not sure what you mean? they customize the icon too? as in they should be able to or they have to as well?

akinsho avatar Jul 18 '24 11:07 akinsho

When using tab mode, there's buffers in name_formatter, but there's no equivalent for get_element_icon. We can only get information about the currently active buffer

ofseed avatar Jul 18 '24 12:07 ofseed

My usage:

mode = "tabs",
name_formatter = function(args)
  if vim.bo[args.bufnr].buftype ~= "" then
    for _, bufnr in ipairs(args.buffers) do
      if vim.bo[bufnr].buftype == "" then
        return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t")
      end
    end
  end
end,
get_element_icon = function(args)
  local loaded, devicons = pcall(require, "nvim-web-devicons")
  if not loaded then
    return ""
  end
  if vim.bo[args.bufnr].buftype ~= "" then
    for _, bufnr in ipairs(args.buffers) do
      if vim.bo[bufnr].buftype == "" then
        return devicons.get_icon(
          vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":t"),
          nil,
          { default = true }
        )
      end
    end
  end
end,

ofseed avatar Jul 18 '24 12:07 ofseed

I'm not sure what you mean? they customize the icon too? as in they should be able to or they have to as well?

@akinsho I mean they should be able to, because there's no extra information like buffers opened in the tab in current API, we chan only get current active file's filetype for path, even cannot get it's bufnr

ofseed avatar Jul 20 '24 07:07 ofseed

@akinsho I have already provided explanations for your questions. Could you please review them again?

ofseed avatar Jul 29 '24 09:07 ofseed

@ofseed this will have to wait till I have free time

akinsho avatar Jul 29 '24 09:07 akinsho

I just wanted to avoid the message getting lost in the notifications. Thank you.

ofseed avatar Jul 29 '24 10:07 ofseed