From 445560e029229fd65843cca9665c16a44f6fc1a3 Mon Sep 17 00:00:00 2001 From: Jesse Hines Date: Mon, 30 Mar 2026 19:56:13 -0400 Subject: [PATCH] Fix deduplication changing current tab Fixes #56 --- src/main.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main.ts b/src/main.ts index 7358519..fb76d24 100644 --- a/src/main.ts +++ b/src/main.ts @@ -268,7 +268,15 @@ export default class OpenTabSettingsPlugin extends Plugin { // If the leaf is still empty, close it. This can happen if the file was de-duplicated while // "openInNewTab" is enabled, or if you open a file "in default app" in a new tab. if (isEmptyLeaf(this) && this.parent.children.length > 1) { + const tabGroup = this.parent; + const wasCurrentTab = tabGroup.children[tabGroup.currentTab] === this; + const lastActiveTab = tabGroup.children + .filter(l => l !== this) + .reduce((max, l) => l.activeTime > max.activeTime ? l : max); this.detach(); + if (wasCurrentTab) { + tabGroup.selectTabIndex(tabGroup.children.findIndex(c => c === lastActiveTab)); + } } delete this.openTabSettings;