Skip to content

Commit

Permalink
refactor: clarify the logic in on_yazi_exited a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas committed Jan 6, 2025
1 parent 4647043 commit 41ede7f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
44 changes: 24 additions & 20 deletions lua/yazi/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -388,31 +388,35 @@ function M.on_yazi_exited(
)
vim.cmd("silent! :checktime")

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

if vim.api.nvim_buf_is_valid(prev_buf) then
vim.api.nvim_set_current_buf(prev_buf)
end
do
-- sanity check: make sure the previous window and buffer are still valid
if not vim.api.nvim_win_is_valid(prev_win) then
return
end

window:close()
if vim.api.nvim_buf_is_valid(prev_buf) then
vim.api.nvim_set_current_buf(prev_buf)
end
end

vim.api.nvim_set_current_win(prev_win)
-- if M.file_exists(config.chosen_file_path) == true then
if #selected_files > 0 then
if #selected_files > 1 then
config.hooks.yazi_opened_multiple_files(selected_files, config, state)
else
local chosen_file = selected_files[1]
config.hooks.yazi_closed_successfully(chosen_file, config, state)
if chosen_file then
config.open_file_function(chosen_file, config, state)
end
end
else
if #selected_files <= 0 then
config.hooks.yazi_closed_successfully(nil, config, state)
return
end

if #selected_files > 1 then
config.hooks.yazi_opened_multiple_files(selected_files, config, state)
return
end

assert(#selected_files == 1)
local chosen_file = selected_files[1]
config.hooks.yazi_closed_successfully(chosen_file, config, state)
if chosen_file then
config.open_file_function(chosen_file, config, state)
end
end

Expand Down
3 changes: 3 additions & 0 deletions vim.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type = "function"
[[after_each.args]]
type = "function"

[assert]
any = true

[assert.is_not]
any = true

Expand Down

0 comments on commit 41ede7f

Please sign in to comment.