Skip to content

Commit

Permalink
fix: opening "nvim dir/" may focus wrong window
Browse files Browse the repository at this point in the history
Yazi.nvim has a feature where you can specify `open_for_directories =
true` to automatically open yazi when opening a directory in Neovim.

In some cases, opening a directory when starting Neovim from the command
line would show yazi, but the window under yazi was selected. Yazi was
supposed to have been focused instead.

This was due to the default netrw file manager not having a file name
for the buffer that was opened. I don't know why this only happened in
some cases.

Fixes #58
  • Loading branch information
mikavilpas committed Jun 21, 2024
1 parent b313793 commit 93de590
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ scripts/lazy.nvim/
/luarocks
/lua_modules
/.luarocks
/lua
5 changes: 4 additions & 1 deletion lua/yazi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ function M.setup(opts)
-- When opening neovim with "nvim ." or "nvim <directory>", the current
-- buffer is already open at this point. If we have already opened a
-- directory, display yazi instead.
open_yazi_in_directory(vim.fn.expand('%:p'), vim.api.nvim_get_current_buf())
open_yazi_in_directory(
vim.b.netrw_curdir or vim.fn.expand('%:p'),
vim.api.nvim_get_current_buf()
)
end
end

Expand Down

0 comments on commit 93de590

Please sign in to comment.