-
-
Notifications
You must be signed in to change notification settings - Fork 626
Feat - Add open and close tree events #1151
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
Feat - Add open and close tree events #1151
Conversation
…nvim-tree.lua into feat-add-hooks-to-config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document in help and readme.
See CONTRIBUTING.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be nvim-tree.events e.g. nvim-tree.events.on_nvim_tree_open
Hey @alex-courtis, I'll implement the suggested changes. With regard to your previous comment an additional section in the config would be a good idea if 'hooks' are to be added elsewhere. Something like: hooks = {
tree_open = nil,
tree_close = nil,
}, Would it be possible to explain how the event system works? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to setup the hooks yourself, the user will call the the event registration himself, no need to set it during setup :)
Ok got it. Can I still add the ability to register and to fire open and close events? |
i'm not even sure you placed the event at the right location to be honest 😄 i think i would place them in view.lua. There are multiple ways the tree can be opened, it won't just work by setting it in toggle :) |
@kyazdani42 thanks for your feedback. I have moved the event dispatches to |
That was a mistake on my part... before I realised that we should use events ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to document this in the help: nvim-tree.events
I've added the documentation |
Another useful event would be |
what do you mean no longer active ? when the tree buffer is replaced by a file buffer ? |
Apologies for not being clear. I mean event when cursor leaves nvim-tree window. Wither because file was opened or by any window movement, such as |
well...
? |
Absolutely, that's what I have at the moment, and with on open event I can replace one of autocmds, but only one. Leaving tree remains as autocmd rather than event, which feels bit odd. |
Well i'm not sure how it would be different inside the plugin ^^' |
That's absolutely alright, just thought that it could make events more complete. I am fine sticking to auto commands. |
😄 now you can define autocmd in lua with callbacks so i think it doesn't matter too much :) |
And this is exactly what I have. Thanks though and apologies for the noise. :) |
Add 'open' and 'close' callbacks or 'hooks' which can be set during setup and which fire when toggling the sidebar.
This can be used to interact with other plugins. For example, the position of a tab bar can be changed according to the width of the file tree when it is opened or closed.