- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 616
Opening a tree in a new tab messes up local statusline settings #2768
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
Comments
Many thanks for the detailed description and reproducer. We don't have any guarantees on which window / buffer is focused on That's no issue, we can simply set the statusline (window local, not buffer local) on the nvim-tree window itself. This worked for me: local api = require("nvim-tree.api")
events.subscribe(events.Event.TreeOpen, function()
vim.api.nvim_set_option_value("statusline", "tree", { win = api.tree.winid() })
end) |
I'm guessing that It would be great if you could share a Recipe once it's working. |
This does work in the case I've outlined here, thanks. But when testing the solution, I've also found an even weirder bug. I was thinking about opening a new issue, but it also may be another facet of #2255. Please advise, if I should open a new issue or not. To reproduce the other bug, you can use the same setup as here (or, because it has nothing to do with statuslines this time, you can even use the raw
The new tree opens correctly in a new tab on :tabedit, but after pressing It might be because of the "shared global state" mentioned in #2255. But maybe it's a separate bug, so if you think it is, I would elaborate in a new issue.
I'm not sure if I have much useful stuff to add to the topic. Just like the original poster of #424, I wanted the tree window to not have a statusline, because my configuration also didn't behave well when squished into a narrow window. So I don't really have a useful custom statusline for nvim-tree ready, just the bare minimum. 😉 If I was to create a recipe, it would just be a simple combination of #424 (comment) and your solution. Something like this: Setting a separate statusline for nvim-tree windowsOften, a rich statusline does not behave well in a very narrow vertical split window, like nvim-tree normally uses. See #424 for example. A different, simpler statusline for nvim-tree windows can be configured like this: local nt_api = require'nvim-tree.api'
nt_api.events.subscribe(nt_api.events.Event.TreeOpen, function()
local tree_winid = nt_api.tree.winid()
if tree_winid ~= nil then
vim.api.nvim_set_option_value('statusline', '%t', {scope = 'local', win = tree_winid})
end
end) Statusline value of To make nvim-tree have no visible statusline at all, you can use a value of a single space If you think it's valuable, I can post it to recipes. |
That is most likely the issue; it's using the window from the other tab to make the decision. The whole lot needs to be fixed. |
That's fantastic, really helpful for a common use case. Much better than messing around with lualine profiles... Thank you for explaining all the details and answering people's questions in advance. |
Okay, I've added the recipe. Thanks for your help. |
Description
According to this comment, I'm using nvim-tree's event system to set local statusline for the tree's window.
This works fine, except for a weird case when nvim-tree is opened in a new tab, and then opening a file from the tree causes the local statusline to be removed from nvim-tree window and set in the newly opened file window.
It's a bit hard to explain, so please see the attached screenshots below.
Neovim version
Operating system and version
Fedora 39
Windows variant
No response
nvim-tree version
64f61e4
Clean room replication
Steps to reproduce
<Enter>
to open any file visible in the tree opened in the new tabExpected behavior
The same behaviour as in the first tab: statusline is set locally for the tree is in the tree's window, and global statusline is set for file opened from the tree.
Actual behavior
In the second tab, after the file is opened from the tree, the local statusline from tree is set for the opened file, and global statusline gets reset for the tree.
The text was updated successfully, but these errors were encountered: