Merge Request: Fix new tab append to child
When double clicked on an existing tab and the option opt.dbclick_tab
is set to new_tab
the created tab did not become a child of the parent tab on which were double clicked on.
This issue appeared in version 1.8.7.
This merge request fixes this by passing the child node of the new created tab which has the css class children
to the function Tabs_OpenNewTab(...)
as the third parameter instead as the second and therefore causing a DOM_AppendToNode(...)
to be invoked rather than DOM_InsterAfterNode(...)
.
Current behavior / call stack:
Tabs_ActionClickTab(TabNode = existingTabClicked, bgOption = "new_tab");
Tabs_OpenNewTab(pin = TabNode.classList.contains("pin") = false, InsertAfterNode = existingTabClicked, AppendToNode = undefined);
DOM_InsterAfterNode(Node = newCreatedTab.Node, AfterNode = existingTabClicked);
New behavior / call stack:
Tabs_ActionClickTab(TabNode = existingTabClicked, bgOption = "new_tab");
Tabs_OpenNewTab(pin = isPinnedTab = false, InsertAfterNode = undefined, AppendToNode = existingTabClicked.childNodeWithCssClassChildren);
DOM_AppendToNode(Node = newCreatedTab.Node, AppendNode = existingTabClicked);
This new behavior takes into account that you might double clicked on a pinned tab or that for some reason the existing tab node object does not have a child node with the css class children
.
In either of those cases Tabs_OpenNewTab(...)
will be called as before, creating the tab using DOM_InsterAfterNode(...)
.
Greetings
Compilenix
Following is a complete patch:
diff --git a/scripts/tabs.js b/scripts/tabs.js
index c574b5d..d6f65e5 100644
--- a/scripts/tabs.js
+++ b/scripts/tabs.js
@@ -732,7 +732,17 @@ function Tabs_GetTabDepthInTree(Node) {
}
function Tabs_ActionClickTab(TabNode, bgOption) {
- if (bgOption == "new_tab") Tabs_OpenNewTab(TabNode.classList.contains("pin"), TabNode);
+ if (bgOption == "new_tab") {
+ let isPinnedTab = TabNode.classList.contains("pin");
+ let childArray = [];
+ for (const child of TabNode.childNodes) childArray.push(child);
+ let childs = childArray.filter(x => { for (const classItem of x.classList) if (classItem === "children") return true; });
+ if (childs && childs.length === 1 && !isPinnedTab) {
+ Tabs_OpenNewTab(isPinnedTab, undefined, childs[0]);
+ } else {
+ Tabs_OpenNewTab(isPinnedTab, TabNode);
+ }
+ }
if (bgOption == "expand_collapse") DOM_EventExpandBox(TabNode);
if (bgOption == "close_tab") {
if ((TabNode.classList.contains("pin") && opt.allow_pin_close) || TabNode.classList.contains("tab")) Tabs_CloseTabs([parseInt(TabNode.id)]);