diff --git a/src/renderer/src/components/Terminal.tsx b/src/renderer/src/components/Terminal.tsx index 427e9005b..8d052a41d 100644 --- a/src/renderer/src/components/Terminal.tsx +++ b/src/renderer/src/components/Terminal.tsx @@ -393,7 +393,10 @@ function Terminal(): React.JSX.Element | null { return } const defaultUrl = useAppStore.getState().browserDefaultUrl ?? 'about:blank' - createBrowserTab(activeWorktreeId, defaultUrl, { title: 'New Browser Tab' }) + createBrowserTab(activeWorktreeId, defaultUrl, { + title: 'New Browser Tab', + focusAddressBar: true + }) }, [activeWorktreeId, createBrowserTab]) const handleDuplicateBrowserTab = useCallback( diff --git a/src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts b/src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts index 7f93c32b2..4bc926b8a 100644 --- a/src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts +++ b/src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.ts @@ -399,7 +399,10 @@ export function useTabGroupWorkspaceModel({ createSplitGroup, newBrowserTab: () => { const defaultUrl = useAppStore.getState().browserDefaultUrl ?? 'about:blank' - createBrowserTab(worktreeId, defaultUrl, { title: 'New Browser Tab' }) + createBrowserTab(worktreeId, defaultUrl, { + title: 'New Browser Tab', + focusAddressBar: true + }) }, duplicateBrowserTab: (browserTabId: string) => { const state = useAppStore.getState() diff --git a/src/renderer/src/hooks/useIpcEvents.ts b/src/renderer/src/hooks/useIpcEvents.ts index 237b04e55..517361bc2 100644 --- a/src/renderer/src/hooks/useIpcEvents.ts +++ b/src/renderer/src/hooks/useIpcEvents.ts @@ -337,7 +337,8 @@ export function useIpcEvents(): void { const worktreeId = store.activeWorktreeId if (worktreeId) { store.createBrowserTab(worktreeId, store.browserDefaultUrl ?? 'about:blank', { - title: 'New Browser Tab' + title: 'New Browser Tab', + focusAddressBar: true }) } }) diff --git a/src/renderer/src/store/slices/browser.test.ts b/src/renderer/src/store/slices/browser.test.ts index ca90d0c30..6a5b9b0d9 100644 --- a/src/renderer/src/store/slices/browser.test.ts +++ b/src/renderer/src/store/slices/browser.test.ts @@ -173,4 +173,58 @@ describe('browser slice', () => { 'https://example.com/b' ) }) + + it('sets pending address-bar focus when focusAddressBar is true even for non-blank URLs', () => { + const store = createTestStore() + const worktreeId = 'repo1::/tmp/wt-1' + seedStore(store, { + activeRepoId: 'repo1', + activeWorktreeId: worktreeId, + activeTabType: 'terminal', + worktreesByRepo: { + repo1: [makeWorktree({ id: worktreeId, repoId: 'repo1', path: '/tmp/wt-1' })] + }, + groupsByWorktree: { + [worktreeId]: [makeTabGroup({ id: 'group-1', worktreeId, activeTabId: null, tabOrder: [] })] + }, + activeGroupIdByWorktree: { [worktreeId]: 'group-1' }, + browserTabsByWorktree: {}, + unifiedTabsByWorktree: {} + }) + + const created = store.getState().createBrowserTab(worktreeId, 'https://example.com/home', { + title: 'Home', + focusAddressBar: true + }) + + const pageId = store.getState().browserPagesByWorkspace[created.id]?.[0]?.id + expect(pageId).toBeDefined() + expect(store.getState().pendingAddressBarFocusByTabId[created.id]).toBe(true) + expect(store.getState().pendingAddressBarFocusByPageId[pageId!]).toBe(true) + }) + + it('does not set pending address-bar focus for non-blank URLs when focusAddressBar is not set', () => { + const store = createTestStore() + const worktreeId = 'repo1::/tmp/wt-1' + seedStore(store, { + activeRepoId: 'repo1', + activeWorktreeId: worktreeId, + activeTabType: 'terminal', + worktreesByRepo: { + repo1: [makeWorktree({ id: worktreeId, repoId: 'repo1', path: '/tmp/wt-1' })] + }, + groupsByWorktree: { + [worktreeId]: [makeTabGroup({ id: 'group-1', worktreeId, activeTabId: null, tabOrder: [] })] + }, + activeGroupIdByWorktree: { [worktreeId]: 'group-1' }, + browserTabsByWorktree: {}, + unifiedTabsByWorktree: {} + }) + + const created = store.getState().createBrowserTab(worktreeId, 'https://example.com/home', { + title: 'Home' + }) + + expect(store.getState().pendingAddressBarFocusByTabId[created.id]).toBeUndefined() + }) }) diff --git a/src/renderer/src/store/slices/browser.ts b/src/renderer/src/store/slices/browser.ts index a4f593d48..60466c413 100644 --- a/src/renderer/src/store/slices/browser.ts +++ b/src/renderer/src/store/slices/browser.ts @@ -22,6 +22,12 @@ type CreateBrowserTabOptions = { // tab in a specific (sibling or newly-split) group rather than the ambient // active group. Defaults to the worktree's current active group. targetGroupId?: string + // Why: the explicit "New Tab" action (keyboard shortcut, + button) should + // land the user in the address bar even when their configured home page is a + // real URL, so they can type a destination immediately. Link-opened tabs + // (context menu, window.open, http link routing) leave this unset so focus + // stays on the webview. When omitted, we fall back to the blank-URL check. + focusAddressBar?: boolean } type CreateBrowserPageOptions = { @@ -350,7 +356,8 @@ export const createBrowserSlice: StateCreator = const shouldUpdateGlobalActiveSurface = shouldActivate && s.activeWorktreeId === worktreeId const shouldFocusAddressBar = shouldUpdateGlobalActiveSurface && - (page.url === 'about:blank' || page.url === ORCA_BROWSER_BLANK_URL) + (options?.focusAddressBar ?? + (page.url === 'about:blank' || page.url === ORCA_BROWSER_BLANK_URL)) return { browserTabsByWorktree: {