Skip to content

Commit

Permalink
fix: re-use existing views with same backend and opts
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 11, 2022
1 parent 3dff936 commit 1d1e9ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .neoconf.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"nui.nvim",
"nvim-cmp",
"nvim-notify",
"telescope.nvim"
"telescope.nvim",
"plenary.nvim"
]
}
},
Expand Down
3 changes: 2 additions & 1 deletion lua/noice/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ function View.get_view(view, opts)
end

local mod = require("noice.view.backend." .. opts.backend)
local init_opts = vim.deepcopy(opts)
---@type NoiceView
local ret = mod(opts)
if not ret:is_available() and opts.fallback then
return View.get_view(opts.fallback, opts_orig)
end
table.insert(View._views, { view = ret, opts = vim.deepcopy(opts) })
table.insert(View._views, { view = ret, opts = init_opts })
return ret
end

Expand Down
12 changes: 12 additions & 0 deletions tests/view/init_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local View = require("noice.view")
local Config = require("noice.config")
Config.setup()

describe("checking views", function()
it("view is loaded only once", function()
local opts = { enter = true, format = "details" }
local view1 = View.get_view("split", opts)
local view2 = View.get_view("split", opts)
assert.equal(view1, view2)
end)
end)

0 comments on commit 1d1e9ed

Please sign in to comment.