Skip to content

Commit 1f51bff

Browse files
nisargkolheclaude
andcommitted
fix: promote temp tabs to pinned when URL matches space bookmark
When a new tab navigates to a URL that matches an existing bookmark in the active space, the tab is now promoted from temporary to pinned instead of staying in the temporary section. This matches the behavior that already works correctly on sidebar re-initialization. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a886140 commit 1f51bff

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

sidebar.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,6 +3279,75 @@ function handleTabUpdate(tabId, changeInfo, tab) {
32793279
}
32803280
Logger.log('Tab updated:', tabId, changeInfo, spaces);
32813281

3282+
// Check if a temporary tab's new URL matches a pinned bookmark in the space
3283+
if (changeInfo.url) {
3284+
const space = spaces.find(s => s.temporaryTabs.includes(tabId));
3285+
if (space) {
3286+
try {
3287+
const arcifyFolder = await LocalStorage.getOrCreateArcifyFolder();
3288+
const spaceFolders = await chrome.bookmarks.getChildren(arcifyFolder.id);
3289+
const spaceFolder = spaceFolders.find(f => f.title === space.name);
3290+
if (spaceFolder) {
3291+
// Try exact URL match first, then base URL match (same as loadTabs init logic)
3292+
let bookmarkResult = await BookmarkUtils.findBookmarkInFolderRecursive(spaceFolder.id, { url: changeInfo.url });
3293+
if (!bookmarkResult) {
3294+
// Base URL match: check all bookmarks ignoring query params/hash
3295+
const allBookmarks = await BookmarkUtils.getBookmarksFromFolderRecursive(spaceFolder.id);
3296+
const newUrlKey = Utils.getPinnedUrlKey(changeInfo.url);
3297+
const baseMatch = allBookmarks.find(b => Utils.getPinnedUrlKey(b.url) === newUrlKey);
3298+
if (baseMatch) {
3299+
bookmarkResult = { bookmark: baseMatch };
3300+
}
3301+
}
3302+
if (bookmarkResult) {
3303+
Logger.log('[PinnedMatch] Temp tab URL matches bookmark, promoting to pinned:', tabId, changeInfo.url);
3304+
// Move tab from temporaryTabs to spaceBookmarks
3305+
space.temporaryTabs = space.temporaryTabs.filter(id => id !== tabId);
3306+
space.spaceBookmarks.push(tabId);
3307+
saveSpaces();
3308+
3309+
// Remove the temporary tab element
3310+
const tempTabEl = document.querySelector(`[data-tab-id="${tabId}"]`);
3311+
if (tempTabEl) tempTabEl.remove();
3312+
3313+
// Find and replace the bookmark-only element with an active pinned tab
3314+
const bookmarkOnlyEl = document.querySelector(`.bookmark-only[data-bookmark-id="${bookmarkResult.bookmark.id}"]`)
3315+
|| document.querySelector(`.bookmark-only[data-url="${bookmarkResult.bookmark.url}"]`);
3316+
3317+
const chromeTab = await chrome.tabs.get(tabId);
3318+
chromeTab.pinnedUrl = bookmarkResult.bookmark.url;
3319+
chromeTab.bookmarkId = bookmarkResult.bookmark.id;
3320+
const newTabElement = await createTabElement(chromeTab, true);
3321+
3322+
if (bookmarkOnlyEl) {
3323+
bookmarkOnlyEl.replaceWith(newTabElement);
3324+
} else {
3325+
// No bookmark-only element found — append to pinned container
3326+
const spaceElement = document.querySelector(`[data-space-id="${space.id}"]`);
3327+
const pinnedContainer = spaceElement?.querySelector('[data-tab-type="pinned"]');
3328+
if (pinnedContainer) pinnedContainer.appendChild(newTabElement);
3329+
}
3330+
3331+
// Set pinned tab state
3332+
await Utils.setPinnedTabState(tabId, {
3333+
pinnedUrl: bookmarkResult.bookmark.url,
3334+
bookmarkId: bookmarkResult.bookmark.id
3335+
});
3336+
3337+
// Activate in DOM if this tab is the active Chrome tab
3338+
if (chromeTab.active) {
3339+
activateTabInDOM(tabId);
3340+
}
3341+
3342+
return; // Skip normal update handling — tab has been promoted
3343+
}
3344+
}
3345+
} catch (err) {
3346+
Logger.error('[PinnedMatch] Error checking bookmark match:', err);
3347+
}
3348+
}
3349+
}
3350+
32823351
// Update tab element if it exists
32833352
const tabElement = document.querySelector(`[data-tab-id="${tabId}"]`);
32843353
if (tabElement) {

0 commit comments

Comments
 (0)