From 05fbc48e03ef6461da63845bb978f37436bab914 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Mon, 23 Oct 2023 23:58:02 +0200 Subject: [PATCH] Sanitize tab index in `Node:add_view` (#1651) * Fix `Node:add_view` not adjusting tab index after removing `EmptyView` * Clamp tab index in `Node:add_view` --- data/core/node.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/data/core/node.lua b/data/core/node.lua index 3ae9b256..86d4e4e0 100644 --- a/data/core/node.lua +++ b/data/core/node.lua @@ -177,8 +177,12 @@ function Node:add_view(view, idx) assert(not self.locked, "Tried to add view to locked node") if self.views[1] and self.views[1]:is(EmptyView) then table.remove(self.views) + if idx and idx > 1 then + idx = idx - 1 + end end - table.insert(self.views, idx or (#self.views + 1), view) + idx = common.clamp(idx or (#self.views + 1), 1, (#self.views + 1)) + table.insert(self.views, idx, view) self:set_active_view(view) end