Skip to content

Commit

Permalink
fix: open file results in one empty buffer (#138)
Browse files Browse the repository at this point in the history
* fix: open file results in one empty buffer

* fix: showing an unnamed buffer after opening a file

Co-authored-by: Rick Yao <[email protected]>

---------

Co-authored-by: Mika Vilpas <[email protected]>
  • Loading branch information
rick-yao and mikavilpas authored Jun 29, 2024
1 parent bd5a334 commit 73a5f8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lua/yazi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function M.yazi(config, input_path)
local path = utils.selected_file_path(input_path)

local prev_win = vim.api.nvim_get_current_win()
local prev_buf = vim.api.nvim_get_current_buf()

config.chosen_file_path = config.chosen_file_path or vim.fn.tempname()
config.events_file_path = config.events_file_path or vim.fn.tempname()
Expand Down Expand Up @@ -67,7 +68,7 @@ function M.yazi(config, input_path)
last_directory = path
end
end
utils.on_yazi_exited(prev_win, win, config, {
utils.on_yazi_exited(prev_win, prev_buf, win, config, {
last_directory = event_info.last_directory or path:parent(),
})
end,
Expand Down
7 changes: 6 additions & 1 deletion lua/yazi/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,22 @@ function M.rename_or_close_buffer(instruction)
end

---@param prev_win integer
---@param prev_buf integer
---@param window YaziFloatingWindow
---@param config YaziConfig
---@param state YaziClosedState
function M.on_yazi_exited(prev_win, window, config, state)
function M.on_yazi_exited(prev_win, prev_buf, window, config, state)
vim.cmd('silent! :checktime')

-- open the file that was chosen
if not vim.api.nvim_win_is_valid(prev_win) then
return
end

if vim.api.nvim_buf_is_valid(prev_buf) then
vim.api.nvim_set_current_buf(prev_buf)
end

window:close()

vim.api.nvim_set_current_win(prev_win)
Expand Down

0 comments on commit 73a5f8f

Please sign in to comment.