From dab9e1edcc9e91a0123eb2986dd892fad37d1afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Mon, 7 Oct 2024 22:56:37 +0200 Subject: [PATCH] fix(pinned-tabs): Always update pinned tab data with latest information This commit ensures that pinned tab data is always updated with the latest information, and previous tab entries are cleaned up. --- src/ZenPinnedTabManager.mjs | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/ZenPinnedTabManager.mjs b/src/ZenPinnedTabManager.mjs index 42e52b8..c8f04c4 100644 --- a/src/ZenPinnedTabManager.mjs +++ b/src/ZenPinnedTabManager.mjs @@ -71,18 +71,9 @@ class ZenPinnedTabManager { const tabState = SessionStore.getTabState(tab); const state = JSON.parse(tabState); - if(!!state.entries.length) { - let activeIndex = (state.index || state.entries.length) - 1; - activeIndex = Math.min(activeIndex, state.entries.length - 1); - activeIndex = Math.max(activeIndex, 0); - - state.entries[activeIndex].url = url; - state.entries[activeIndex].title = title; - state.image = icon; - } else { - state.entries.push({ url, title, image: icon }); - } - + state.entries = [{url, title}]; + state.image = icon; + state.index = 0; SessionStore.setTabState(tab, state); } @@ -147,17 +138,9 @@ class ZenPinnedTabManager { const tabState = SessionStore.getTabState(selectedTab); const state = JSON.parse(tabState); - if(!!state.entries.length) { - let activeIndex = (state.index || state.entries.length) - 1; - activeIndex = Math.min(activeIndex, state.entries.length - 1); - activeIndex = Math.max(activeIndex, 0); - - state.entries[activeIndex].url = url; - state.entries[activeIndex].title = title; - state.image = icon; - } else { - state.entries.push({ url, title, image: icon }); - } + state.entries = [{url, title}]; + state.image = icon; + state.index = 0; SessionStore.setTabState(selectedTab, state); }