From 1d1e9ed9ce34895c7dfb80d44aa5b7a90863ef06 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Thu, 10 Nov 2022 22:23:13 +0100 Subject: [PATCH] fix: re-use existing views with same backend and opts --- .neoconf.json | 3 ++- lua/noice/view/init.lua | 3 ++- tests/view/init_spec.lua | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/view/init_spec.lua diff --git a/.neoconf.json b/.neoconf.json index 0032d47..e719d51 100644 --- a/.neoconf.json +++ b/.neoconf.json @@ -5,7 +5,8 @@ "nui.nvim", "nvim-cmp", "nvim-notify", - "telescope.nvim" + "telescope.nvim", + "plenary.nvim" ] } }, diff --git a/lua/noice/view/init.lua b/lua/noice/view/init.lua index 3795a5f..cb15c8e 100644 --- a/lua/noice/view/init.lua +++ b/lua/noice/view/init.lua @@ -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 diff --git a/tests/view/init_spec.lua b/tests/view/init_spec.lua new file mode 100644 index 0000000..2231153 --- /dev/null +++ b/tests/view/init_spec.lua @@ -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)