Prefer navigate row over switch-to-tab for identical URL
This commit is contained in:
parent
3ffceb7e8e
commit
6133da0b20
2 changed files with 46 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue