Skip to content

feat: add actions.open_file.eject #2341

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 3 commits into from
Jul 29, 2023
Merged

Conversation

usachev63
Copy link
Contributor

@usachev63 usachev63 commented Jul 28, 2023

Hello!

In issue #1628 and PR #1637 the following expected behavior was introduced. When opening a file using :edit (or Telescope) while being focused on nvim-tree window, the new file opens in another window (and, depending on quit_on_open option, the nvim-tree window either stays or closes). This is useful when using nvim-tree in "expected" way, i.e. as a narrow column window on the side, which can be toggled on and off.

However, I'd like to use nvim-tree as a replacement of netrw: I would mostly want to open files from the tree in-place, overriding the tree window. While there already exists an API function api.node.open.replace_tree_buffer which performs an in-place open, issuing :e or using Telescope does not make the desired in-place open.

This PR adds an option nvim-tree.actions.open_file.eject, which is true by default (current behavior). When it's false, it disables nvim-tree hijacking of such in-place opens: the new file will be opened in the same window, replacing nvim-tree.

Please provide feedback, whether this option would be useful (or whether there is already another way to achieve the desired effect). Thank you

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.

Tested ok, works as advertised.

quit_on_open behaviour is now correctly documented.

end
end,
})
if opts.actions.open_file.prevent_buffer_override then
Copy link
Member

Choose a reason for hiding this comment

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

Please move this inside the callback, to allow users to change this option with a subsequent setup call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -494,6 +494,7 @@ applying configuration.
},
open_file = {
quit_on_open = false,
prevent_buffer_override = true,
Copy link
Member

Choose a reason for hiding this comment

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

buffer_override is used internally, however it's not a very clear description.

Perhaps we could call this eject_buffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's a better name. Maybe also eject_tree to highlight the nvim-tree buffer is ejected?

Copy link
Member

Choose a reason for hiding this comment

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

false indicates "do nothing" i.e. don't interfere with normal vim behaviour. We never really do anything with the tree itself.

Since this is under open_file we could just call it open_file.eject. Your description is quite accurate, describing what happens to the new buffer.

I do get quite critical when it comes to option names / places. It's easy to get right when adding but very hard to refactor later...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree naming things that you cannot change later should be discussed vigorously :) I will rename to open_file.eject

@usachev63
Copy link
Contributor Author

Rebased with nvim-tree master

@usachev63 usachev63 changed the title feat: added prevent_buffer_override option to allow in-place opens by :edit feat: added open_file.eject option to allow in-place opens by :edit Jul 29, 2023
@alex-courtis alex-courtis changed the title feat: added open_file.eject option to allow in-place opens by :edit feat: add actions.open_file.eject Jul 29, 2023
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.

Many thanks for your changes!

There have been many discussions in the past around such behaviour and this should have a wide impact.

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.

2 participants