Skip to content

Commit

Permalink
feat(layout): method 'show' mounts if not already mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Nov 26, 2023
1 parent 43f7605 commit c1627d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lua/nui/layout/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,14 @@ function Layout:hide()
end

function Layout:show()
if self._.loading or not self._.mounted then
if self._.loading then
return
end

if not self._.mounted then
return self:mount()
end

self._.loading = true

autocmd.create_group(self._.augroup.hide, { clear = true })
Expand Down
8 changes: 6 additions & 2 deletions tests/nui/layout/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,10 @@ describe("nui.layout", function()
end)

describe("method :show", function()
it("does nothing if not mounted", function()
it("mounts if not mounted", function()
local p1 = unpack(create_popups({}))

local p1_mount = spy.on(p1, "mount")
local p1_show = spy.on(p1, "show")

layout = Layout(
Expand All @@ -678,6 +679,7 @@ describe("nui.layout", function()
layout:hide()
layout:show()

assert.spy(p1_mount).was_called()
assert.spy(p1_show).was_not_called()
end)

Expand Down Expand Up @@ -1647,9 +1649,10 @@ describe("nui.layout", function()
end)

describe("method :show", function()
it("does nothing if not mounted", function()
it("mounts if not mounted", function()
local s1 = unpack(create_splits({}))

local s1_mount = spy.on(s1, "mount")
local s1_show = spy.on(s1, "show")

layout = Layout(
Expand All @@ -1665,6 +1668,7 @@ describe("nui.layout", function()
layout:hide()
layout:show()

assert.spy(s1_mount).was_called()
assert.spy(s1_show).was_not_called()
end)

Expand Down

0 comments on commit c1627d0

Please sign in to comment.