From bcc263cc5e80d034c238edf64acf30edf6f4e814 Mon Sep 17 00:00:00 2001 From: Alexander Minges Date: Sat, 12 Jul 2025 21:00:46 +0200 Subject: [PATCH] feat: add persistent active tab tracking to actor sheet --- src/apps/actor/base-sheet.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/apps/actor/base-sheet.js b/src/apps/actor/base-sheet.js index 0cecd84e..27783b25 100644 --- a/src/apps/actor/base-sheet.js +++ b/src/apps/actor/base-sheet.js @@ -48,6 +48,11 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 { static TABS = {}; + constructor(options = {}) { + super(options); + this.activeTab = "values"; // Default active tab + } + get title() { return `${this.document.name} [${game.i18n.localize("DS4.ActorSheet")}]`; } @@ -502,6 +507,9 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 { const tab = target.dataset.tab; if (!tab) return; + // Store the active tab + this.activeTab = tab; + // Find tab navigation elements const nav = target.closest(".ds4-sheet-tab-nav"); const sheet = this.element.querySelector(".ds4-sheet-body"); @@ -552,18 +560,24 @@ export class DS4ActorSheet extends foundry.applications.api.DocumentSheetV2 { navItems.forEach(item => item.classList.remove("active")); tabContents.forEach(content => content.classList.remove("active")); - // Set first tab navigation as active - const firstNavItem = navItems[0]; - if (firstNavItem) { - firstNavItem.classList.add("active"); + // Find the currently active tab or default to first + let targetTab = this.activeTab; + let targetNavItem = nav.querySelector(`[data-tab="${targetTab}"]`); + + // If stored tab doesn't exist, fall back to first tab + if (!targetNavItem) { + targetNavItem = navItems[0]; + targetTab = targetNavItem?.dataset.tab; + } + + // Set target tab navigation as active + if (targetNavItem && targetTab) { + targetNavItem.classList.add("active"); // Set corresponding tab content as active - const firstTab = firstNavItem.dataset.tab; - if (firstTab) { - const activeTabContent = sheet.querySelector(`.ds4-sheet-tab[data-tab="${firstTab}"]`); - if (activeTabContent) { - activeTabContent.classList.add("active"); - } + const activeTabContent = sheet.querySelector(`.ds4-sheet-tab[data-tab="${targetTab}"]`); + if (activeTabContent) { + activeTabContent.classList.add("active"); } } }