Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tabs): only show close icon if multiple tabse #646

Conversation

dwijesinghe
Copy link
Contributor

The tab close icon can look a little odd (and won't do anything) if there's only one tab in use. See this reddit post

Since I would guess many people who use this plugin would be less inclined to use standard vim tabs - I thought it would make sense and improve aesthetics to remove it if there's only one tab in use (it will reappear if the user opens another tab). For those who want to always see the tab close icon, the always_show_tab_close_icon option can be set to true in setup (default is false).

Please let me know your thought and btw I love this plugin :)

@akinsho
Copy link
Owner

akinsho commented Jan 2, 2023

@dwijesinghe this is a good idea, thanks for the PR. I had been considering something similar, but hadn't gotten round to implementing it. The only suggestion I have would be to make this behaviour the default also I'd go as far as to remove the option tbh since frankly it's useless to have a button that does nothing and I get issues from users who are confused that the button "does not work" when there is only one tab open. I'd say just change this to be the only behaviour, i.e. only show the button if there is a tab.

)
if (vim.api.nvim_eval('tabpagenr("$")') > 1 or options.always_show_tab_close_icon)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to use this sort of api e.g. nvim_eval.

You can do

if #vim.api.nvim_list_tabpages() > 1 or ... then
  ...

Tbh I think this would be better to add this to the tab close button function so that it returns an empty component if there is only a single tab

@@ -150,6 +150,7 @@ The available configuration are:
sort_by = 'insert_after_current' |'insert_at_end' | 'id' | 'extension' | 'relative_directory' | 'directory' | 'tabs' | function(buffer_a, buffer_b)
-- add custom logic
return buffer_a.modified > buffer_b.modified
always_show_tab_close_icon = true | false, -- if false the tab close icon will only appear if there is more than one tab
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say don't make this optional at all, I made a mistake by offering too many things as options. I'd say to just be decisive and make this the only behaviour since the alternative is useless

Copy link
Owner

@akinsho akinsho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a couple of comments re. the implementation but definitely like this idea

…se icon an empty component instead of omitting it entirely
@dwijesinghe
Copy link
Contributor Author

@akinsho Thanks! Just made those changes, its def a lot more succinct now. Let me know if there's anything else you want modified etc.

Copy link
Owner

@akinsho akinsho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@akinsho akinsho changed the base branch from main to dev January 3, 2023 14:07
@akinsho akinsho changed the title Added always_show_tab_close_icon option refactor(tabs): only show close icon if multiple tabse Jan 3, 2023
@akinsho akinsho merged commit 0c0c9ae into akinsho:dev Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants