Skip to content

feat: add api.tree.toggle_enable_filters #2706

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

Merged
merged 10 commits into from
Mar 16, 2024

Conversation

DeH4er
Copy link
Contributor

@DeH4er DeH4er commented Mar 13, 2024

Hi there. Thanks for the amazing project.

I often find that I need to access hidden files but I keep forgetting keybindings for particular filters. I wish to have one goto keybinding to make it easier to see all files.

I'm unsure about the naming of some vars and functions. But overall, I hope it's a good contribution to the project

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Concept and change looks good.

Let's get some consistency in user and API naming. Perhaps Toggle All Filters Disabled and api.tree.toggle_disable_all_filter()

@DeH4er DeH4er force-pushed the feat-toggle-filters branch from 8126caa to cccd62f Compare March 14, 2024 10:25
@DeH4er
Copy link
Contributor Author

DeH4er commented Mar 14, 2024

What do you think about Toggle Filters Disabled and api.tree.toggle_filters_disabled? PR is updated to reflect these names

@@ -536,6 +537,7 @@ Following is the default configuration. See |nvim-tree-opts| for details.
show_on_open_dirs = true,
},
filters = {
disabled = false,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer enabled = true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I see that the convention is enable. Will update PR

...
      hijack_directories = {
        enable = true,
        auto_open = true,
      },
      update_focused_file = {
        enable = false,
        update_root = false,
        ignore_list = {},
      },
      system_open = {
        cmd = "",
        args = {},
      },
      git = {
        enable = true,
        show_on_dirs = true,
        show_on_open_dirs = true,
        disable_for_dirs = {},
        timeout = 400,
        cygwin_support = false,
      },
...

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Works nicely except for the live filter case.

I naturally tried that case when testing and was surprised when it didn't apply. Can we please add that? I imagine users will be similarly surprised.

@@ -1242,6 +1244,11 @@ Only relevant when |modified.show_on_dirs| is `true`.

File / folder filters that may be toggled.

*nvim-tree.filters.enable*
Enable / disable filters.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Enable / disable filters.
Enable / disable all filters including live filter.

@alex-courtis
Copy link
Member

I'm not quite sure about the , mapping, I'm always nervous about overriding "core" vim keys.

@gegoune should we change it to something like T?

@gegoune
Copy link
Collaborator

gegoune commented Mar 15, 2024

I'm not quite sure about the , mapping, I'm always nervous about overriding "core" vim keys.

@gegoune should we change it to something like T?

Not overriding existing mappings is a good thing for sure. I see two options:

  1. map it to something free, I don;t really care what to be honest as there is a way to change the default
  2. don't add new mappings going forward. We could even look into removing majority of existing mappings from api.config.mappings.default_on_attach providing only bare minimum. But that's radical, maybe too radical.

BTW, T is an existing vim key :h T.

@alex-courtis
Copy link
Member

  1. don't add new mappings going forward.

I'm inclined to agree. Each default mapping added is potentially a user's mapping clobbered.

Sorry @DeH4er - please remove the default mapping.

We could even look into removing majority of existing mappings from api.config.mappings.default_on_attach providing only bare minimum. But that's radical, maybe too radical.

That would break people, however we could add a very trimmed down api.config.mappings.minimal_on_attach

@DeH4er
Copy link
Contributor Author

DeH4er commented Mar 15, 2024

I updated the PR with all your feedback.

Since you touched on a topic of keybindings, currently it's hard to get a sense of what's possible.

  1. The help panel is hidden under "g?" keybinding by default, and only when nvim-tree updated its way to change keybindings, I discovered that there's a help panel (I was smashing ? and since it did nothing, I just assumed there's no help panel).
  2. As a user, you think everything useful (or even possible) is in this panel.

So I think the ideal solution would be to:

  1. Make it clear that g? is a default help panel keybinding. Show "g? - help" somewhere in nvim-tree panel or make it visible in readme.
  2. Show every possible API command in this help panel, even if it has no keybinding + keybinding if there's one
  3. Since there are lots of commands, it would be great to group them

This way, you can have minimal keybinding config and it will be extremely easy to copy-paste api function to your on_attach without reading :h nvim-tree

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Works beautifully, many thanks!

@alex-courtis alex-courtis changed the title feat: toggle all filters feat: add api.tree.toggle_enable_filters Mar 16, 2024
@alex-courtis alex-courtis merged commit f7c09bd into nvim-tree:master Mar 16, 2024
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.

3 participants