Skip to content

fix: Implicit current buf on centralize selection #1792

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 1 commit into from
Dec 12, 2022

Conversation

thedaviddelta
Copy link
Contributor

The recent implementation change to center the selected file produces a very odd error on my setup.
If I have nvim-tree open (for example, when opening an empty project) and then open a file using any other mean (e.g. Telescope) a Invalid buffer id: 1 error pops into my neovim.
Tweaking the code I've discovered the cause: the centralize_selection autocmd that runs when closing the tree tries to reads the bufnr of Telescope and then schedules the zz call, running after some milliseconds when the Telescope buffer is already killed.
By implicitly using the current buffer (by using 0 as a param) instead of explicitly retrieving it solves this problem. It'd probably also work if the retrieving is moved inside the schedule function, but haven't tried as I don't think it's better to do so.

@gegoune
Copy link
Collaborator

gegoune commented Dec 1, 2022

0 is probably good here but maybe using buffer number from event object will be more robust?

@thedaviddelta
Copy link
Contributor Author

Changed. I think it's also working correctly this way.

@gegoune
Copy link
Collaborator

gegoune commented Dec 1, 2022

Thanks, that's not exactly what I had in mind. Apologies for not being clear. I have requested changes with more detail.

@thedaviddelta
Copy link
Contributor Author

imagen
This produces the same problem, as the event is populated before the schedule starts.
We should just use 0, or simply query the id inside the schedule callback.

@gegoune
Copy link
Collaborator

gegoune commented Dec 1, 2022

Didn't test it properly then. Schedule it then. Maybe Alex will have better solution.

@thedaviddelta
Copy link
Contributor Author

Should I revert to the explicit or the implicit implementation?

@gegoune
Copy link
Collaborator

gegoune commented Dec 1, 2022

If 0 in scheduled context works then it seems like the easiest solution avoiding extra call to api.

@alex-courtis
Copy link
Member

Gentle nudge for re-review @gegoune

@gegoune gegoune changed the title Implicit current buf on centralize selection fix: Implicit current buf on centralize selection Dec 12, 2022
@gegoune gegoune merged commit 0cd8ac4 into nvim-tree:master Dec 12, 2022
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