From 34fa2b212d67d30113fa53ea4b0e3e414002248d Mon Sep 17 00:00:00 2001 From: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com> Date: Tue, 26 May 2026 02:19:02 -0400 Subject: [PATCH] Fix floating workspace link routing (#2825) Co-authored-by: Orca --- src/renderer/src/lib/http-link-routing.test.ts | 15 +++++++++++++++ src/renderer/src/lib/http-link-routing.ts | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/lib/http-link-routing.test.ts b/src/renderer/src/lib/http-link-routing.test.ts index bdafd7e99..8345e899b 100644 --- a/src/renderer/src/lib/http-link-routing.test.ts +++ b/src/renderer/src/lib/http-link-routing.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { FLOATING_TERMINAL_WORKTREE_ID } from '../../../shared/constants' import { openHttpLink, registerHttpLinkStoreAccessor } from './http-link-routing' const openUrlMock = vi.fn() @@ -52,6 +53,20 @@ describe('openHttpLink', () => { expect(openUrlMock).not.toHaveBeenCalled() }) + it('routes floating workspace links into Orca without changing the active repo worktree', () => { + storeState.settings = { openLinksInApp: true } + + openHttpLink('https://example.com/', { worktreeId: FLOATING_TERMINAL_WORKTREE_ID }) + + expect(setActiveWorktreeMock).not.toHaveBeenCalled() + expect(createBrowserTabMock).toHaveBeenCalledWith( + FLOATING_TERMINAL_WORKTREE_ID, + 'https://example.com/', + { activate: true } + ) + expect(openUrlMock).not.toHaveBeenCalled() + }) + it('routes to the system browser when openLinksInApp is off', () => { storeState.settings = { openLinksInApp: false } diff --git a/src/renderer/src/lib/http-link-routing.ts b/src/renderer/src/lib/http-link-routing.ts index 5204be0da..d67d96c8e 100644 --- a/src/renderer/src/lib/http-link-routing.ts +++ b/src/renderer/src/lib/http-link-routing.ts @@ -1,3 +1,5 @@ +import { FLOATING_TERMINAL_WORKTREE_ID } from '../../../shared/constants' + export type OpenHttpLinkOptions = { worktreeId?: string | null forceSystemBrowser?: boolean @@ -40,7 +42,11 @@ export function openHttpLink(url: string, opts: OpenHttpLinkOptions = {}): void // history entry — the user isn't changing worktrees, they're opening a tab // in the one they're already in. activateAndRevealWorktree is reserved for // file-link jumps that genuinely switch worktrees. - state.setActiveWorktree(worktreeId) + if (worktreeId !== FLOATING_TERMINAL_WORKTREE_ID) { + // Why: the floating workspace uses a synthetic worktree id. Promoting it + // to the global activeWorktreeId deselects the real repo workspace. + state.setActiveWorktree(worktreeId) + } state.createBrowserTab(worktreeId, url, { activate: true }) return }