Skip to content

Commit

Permalink
fix: showing an unnamed buffer after opening a file
Browse files Browse the repository at this point in the history
Co-authored-by: Rick Yao <[email protected]>
  • Loading branch information
mikavilpas and rick-yao committed Jun 29, 2024
1 parent e04e604 commit a961df0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 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
13 changes: 0 additions & 13 deletions lua/yazi/openers.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
local M = {}

local function delete_empty_path_buffers()
local buffers = vim.api.nvim_list_bufs()
if #buffers == 2 then
for _, buf in ipairs(buffers) do
local file_path = vim.api.nvim_buf_get_name(buf)
if file_path == '' then
vim.api.nvim_buf_delete(buf, { force = true })
end
end
end
end

---@param chosen_file string
function M.open_file(chosen_file)
delete_empty_path_buffers()
vim.cmd(string.format('edit %s', vim.fn.fnameescape(chosen_file)))
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 a961df0

Please sign in to comment.