diff --git a/Sources/Panels/BrowserPanelView.swift b/Sources/Panels/BrowserPanelView.swift index 89a64487..65cf42ce 100644 --- a/Sources/Panels/BrowserPanelView.swift +++ b/Sources/Panels/BrowserPanelView.swift @@ -1071,7 +1071,19 @@ func buildOmnibarSuggestions( ) order += 1 if let existing = bestByCompletion[key] { - if ranked.score > existing.score { + let shouldReplaceExisting: Bool = { + // For identical completions, keep "go to URL" over "switch to tab" so + // pressing Enter performs navigation unless the user explicitly picks a tab row. + switch (existing.suggestion.kind, ranked.suggestion.kind) { + case (.navigate, .switchToTab): + return false + case (.switchToTab, .navigate): + return true + default: + return ranked.score > existing.score + } + }() + if shouldReplaceExisting { bestByCompletion[key] = ranked } } else { diff --git a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift index dc99383f..8bcaac46 100644 --- a/cmuxTests/CmuxWebViewKeyEquivalentTests.swift +++ b/cmuxTests/CmuxWebViewKeyEquivalentTests.swift @@ -1332,6 +1332,39 @@ final class OmnibarSuggestionRankingTests: XCTestCase { XCTAssertEqual(results.first?.completion, "https://gmail.com/") } + func testNavigateSuggestionRanksAheadOfSwitchToTabForSameResolvedURL() throws { + let targetURL = try XCTUnwrap(URL(string: "http://http.badssl.com/")) + + let results = buildOmnibarSuggestions( + query: targetURL.absoluteString, + engineName: "Google", + historyEntries: [], + openTabMatches: [ + .init( + tabId: UUID(), + panelId: UUID(), + url: targetURL.absoluteString, + title: "http.badssl.com", + isKnownOpenTab: true + ), + ], + remoteQueries: [], + resolvedURL: targetURL, + limit: 8, + now: fixedNow + ) + + guard let first = results.first else { + XCTFail("Expected at least one suggestion") + return + } + guard case .navigate(let navigateURL) = first.kind else { + XCTFail("Expected first suggestion to be navigate, got \(first.kind)") + return + } + XCTAssertEqual(navigateURL, targetURL.absoluteString) + } + func testSuggestionSelectionPrefersAutocompletionCandidateAfterSuggestionsUpdate() { let entries: [BrowserHistoryStore.Entry] = [ .init(