fix: focus address bar for new browser tabs (#1119)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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<AppState, [], [], BrowserSlice> =
|
||||
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: {
|
||||
|
||||
Reference in New Issue
Block a user