Replies: 4 comments
-
For reference, I asked a similar question here. Hope we find a way, or can work on PR to implement such feature. |
Beta Was this translation helpful? Give feedback.
-
@utilyre to clarify quick, is the idea that when you press the button, that you may not know what the latest source is and still want to preserve that source? If you know what source you want to toggle, you can specify that after the If however you want to be able to find the current source before executing toggle (and then using that source on re-toggle), You can checkout the code I provided in #872 local is_neotree_focused = function()
-- Get our current buffer number
local bufnr = vim.api.nvim_get_current_buf and vim.api.nvim_get_current_buf() or vim.fn.bufnr()
-- Get all the available sources in neo-tree
for _, source in ipairs(require("neo-tree").config.sources) do
-- Get each sources state
local state = require("neo-tree.sources.manager").get_state(source)
-- Check if the source has a state, if the state has a buffer and if the buffer is our current buffer
if state and state.bufnr and state.bufnr == bufnr then
print("Neotree is focused!")
return true
end
end
print("Neotree is not focused!")
return false
end This is not exactly what you are looking for but may get you moving in the right direction. The biggest issue that will be faced here is that there is nothing stopping a user from having multiple neo-tree windows open at the same time. Example So we can't exactly say "This source is the current source" as there may be multiple. Your best bet is to analyze the provided state for each source (as I do above) and see if the state has a All that said, I really like the idea of Toggle actually toggling the state and not Neo-tree itself. @cseickel got any ideas or should this be an enhancement request? |
Beta Was this translation helpful? Give feedback.
-
@miversen33 is correct in that it really just wasn't designed to be used in this way. Conceptually, each source is a distinct window that should be toggled independently. You don't open "neo-tree", you open a specific source. That being said, the source selector component really muddied that concept and naturally leads to thinking about neo-tree as a singular window that just has different views, even though that goes against the grain of how it's actually coded. One way to patch in the kind of behavior that would fit OK with what we have is to accept a special keyword called
I'm not going to do that, but if someone else is interested enough to do the work, that's a solution I'll accept. |
Beta Was this translation helpful? Give feedback.
-
Implemented in #1081 . |
Beta Was this translation helpful? Give feedback.
-
So when you run
:Neotree toggle
it'll only toggle the default source (filesystem
in my case) and nothing else. However, I'd like to have a keymap to both close the current source when neo-tree is open, and when closed open the source I just closed (or the default source if it's running for the first time).Beta Was this translation helpful? Give feedback.
All reactions