From 73a5f8f37971cc133bbab978eac825968e90bb9c Mon Sep 17 00:00:00 2001 From: Rick Yao <59443488+rick-yao@users.noreply.github.com> Date: Sat, 29 Jun 2024 15:11:30 +0800 Subject: [PATCH] fix: open file results in one empty buffer (#138) * fix: open file results in one empty buffer * fix: showing an unnamed buffer after opening a file Co-authored-by: Rick Yao --------- Co-authored-by: Mika Vilpas --- lua/yazi.lua | 3 ++- lua/yazi/utils.lua | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/yazi.lua b/lua/yazi.lua index 8c5fb739..58f82bae 100644 --- a/lua/yazi.lua +++ b/lua/yazi.lua @@ -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() @@ -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, diff --git a/lua/yazi/utils.lua b/lua/yazi/utils.lua index f6ca7e93..b20cf728 100644 --- a/lua/yazi/utils.lua +++ b/lua/yazi/utils.lua @@ -195,10 +195,11 @@ 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 @@ -206,6 +207,10 @@ function M.on_yazi_exited(prev_win, window, config, state) 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)