Skip to content

Commit

Permalink
refactor: return early when toggling to close
Browse files Browse the repository at this point in the history
  • Loading branch information
luukvbaal committed Aug 9, 2023
1 parent 4ea44f9 commit 662034c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lua/nnn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,18 @@ end

-- Toggle explorer/picker windows, keeping buffers
function M.toggle(mode, fargs, auto)
local tab = a.nvim_get_current_tabpage()
local win = state[mode][tab] and state[mode][tab].win

if win and a.nvim_win_is_valid(win) then
close(mode, tab)
return
end

local dir
local bufname = a.nvim_buf_get_name(0)
local is_dir = stat(bufname, "directory")
local empty = (is_dir and f.bufname("#") or bufname) == ""
local tab = a.nvim_get_current_tabpage()

if fargs then
for _, arg in ipairs(fargs) do
Expand All @@ -380,13 +387,7 @@ function M.toggle(mode, fargs, auto)
end

startdir = dir and f.expand(dir) or is_dir and bufname
local win = state[mode][tab] and state[mode][tab].win

if win and a.nvim_win_is_valid(win) then
close(mode, tab)
else
open(mode, tab, is_dir, empty)
end
open(mode, tab, is_dir, empty)
end

-- Handle user defined mappings
Expand Down

0 comments on commit 662034c

Please sign in to comment.