From 2f5efd95608ddce4364c941badbfa4395b786718 Mon Sep 17 00:00:00 2001 From: Kristina Date: Fri, 4 Oct 2024 22:17:53 +0400 Subject: [PATCH] Update last tab instead of create new (#6817) Signed-off-by: Kristina Fefelova --- .../src/components/Workbench.svelte | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index e8ebdf6cd5..d9b25b52c4 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -184,27 +184,24 @@ ) async function initCurrentTab (tabs: WorkbenchTab[]): Promise { - if (tabs.length === 0) { - const loc = getCurrentLocation() - - const _id = await client.createDoc(workbench.class.WorkbenchTab, core.space.Workspace, { - attachedTo: account._id, - location: locationToUrl(loc), - isPinned: false - }) - prevTab = _id - selectTab(_id) - } else { - const tab = tabs.find((t) => t._id === $tabIdStore) - const loc = getCurrentLocation() - const tabLoc = tab ? getTabLocation(tab) : undefined - const isLocEqual = tabLoc ? areLocationsEqual(loc, tabLoc) : false - if (!isLocEqual) { - const url = locationToUrl(loc) - const tabByUrl = tabs.find((t) => t.location === url) - if (tabByUrl !== undefined) { - prevTab = tabByUrl._id - selectTab(tabByUrl._id) + const tab = tabs.find((t) => t._id === $tabIdStore) + const loc = getCurrentLocation() + const tabLoc = tab ? getTabLocation(tab) : undefined + const isLocEqual = tabLoc ? areLocationsEqual(loc, tabLoc) : false + if (!isLocEqual) { + const url = locationToUrl(loc) + const tabByUrl = tabs.find((t) => t.location === url) + if (tabByUrl !== undefined) { + prevTab = tabByUrl._id + selectTab(tabByUrl._id) + } else { + const tabToReplace = tabs.findLast((t) => !t.isPinned) + if (tabToReplace !== undefined) { + await client.update(tabToReplace, { + location: url + }) + prevTab = tabToReplace._id + selectTab(tabToReplace._id) } else { const _id = await client.createDoc(workbench.class.WorkbenchTab, core.space.Workspace, { attachedTo: account._id,