Buffer is opened up in wrong window if NnnExplorer is executed after tabnew in function
ggustafsson opened this issue · 6 comments
Hello!
It seems that NnnExplorer/NnnPicker is not always able to get the correct id of the last window. I've encountered a scenario where it works if each command is performed manually but consistently broken if executed through a function.
I want to use the following function to set things up in a new tab view:
function! DocsMode()
tabnew
tcd ~/Documents/Text
NnnExplorer
endfunction
The result is that NnnExplorer opens up the new buffer in the last window in the previous tab. In other words the new window from tabnew is not registered as the previous window.
See problem in action here: https://asciinema.org/a/bzT1IKDQ5Bh69PkaapXT5noxT
Same thing but manually executed: https://asciinema.org/a/KSCRHMivzr3fnMDAdm1xf7wjz
Best regards,
Göran Gustafsson
Have you checked the auto_open
-> tabpage
config? Setting that to explorer
would get you where you want with
function! DocsMode()
tabnew
tcd ~/Documents/Text
endfunction
and does open the selected file on the current tapbage.
Would that work for you? Unless you don't actually want to auto_open on each tab.
I think we could hardcode in the functionality you want but we assume the targetwin to be the previously active window and technically that would be the one on previous tabpage when executing that function. (Because WinEnter
doesn't fire during that function apparently? Not sure if that's expected behavior.)
Ah no the issue is that we schedule the WinEnter
callback, causing it to fire when the nnnexplorer window is active when executed in a function.
Knowing that, another option would be to schedule your NnnExplorer
call in your DocsMode()
function, i.e.:
function! DocsMode()
tabnew
tcd ~/Documents/Text
lua vim.schedule(function() require("nnn").toggle("explorer") end)
endfunction
This should update the targetwin correctly. Not sure if we want to account for this usecase in the plugin or through the mentioned workarounds.
I would prefer to not use auto_open
but the workaround works just fine so thanks for that! If possible it would be nice if it could be handled automatically since it is a bit unexpected and confusing at the moment.
Should be fixed without workaround, please confirm.
Works great! Thanks!