Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tabs to suggestions/autocomplete on iOS #998

Merged
merged 14 commits into from
Sep 22, 2024
Merged

Conversation

brindy
Copy link
Contributor

@brindy brindy commented Sep 19, 2024

Required:

Task/Issue URL: https://app.asana.com/0/392891325557410/1208036752520497/f
iOS PR: duckduckgo/iOS#3371
macOS PR: duckduckgo/macos-browser#3309
What kind of version bump will this require?: Major

Optional:

Tech Design URL: https://app.asana.com/0/481882893211075/1208270496320813/f
CC:

Description:
Adds support for tabs to suggestions.

Steps to test this PR:

  1. See platform specific PRs

@brindy brindy self-assigned this Sep 19, 2024
@@ -39,7 +40,9 @@ extension Score {
score += 300
// Prioritize root URLs most
if url.isRoot { score += 2000 }
} else if lowercasedTitle.starts(with: query) {
} else if lowercasedTitle
.trimmingCharacters(in: .alphanumerics.inverted)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug where if a title was like "Cats and Dogs" Cats would not get matched at all because of the quote.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that matching these characters won't work from now on?
What if I want to find a title starting with a special character?

I checked in the currently released version and I can match a title with quotes which might be a valid use case.

Screenshot 2024-09-20 at 09 45 54

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that example won't work now because:

  • It won't match the first character any more
  • The second character wouldn't match anyway

But honestly, I think that's gonna be rare? I assume people are more likely to search for HBO than " or "HBO

I can make it an OR condition though if you feel strongly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new solution looks better to me 👍 Thank you, Brindy!

@@ -26,6 +26,7 @@ extension Score {
// swiftlint:disable:next cyclomatic_complexity
init(title: String?, url: URL, visitCount: Int, query: Query, queryTokens: [Query]? = nil) {
// To optimize, query tokens can be precomputed
let query = query.lowercased()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not strictly required because usually input will be lowercase, but while testing caused some confusion.

@@ -104,12 +111,9 @@ extension Score {
}

static func tokens(from query: Query) -> [Query] {
return query
.split(whereSeparator: {
$0.unicodeScalars.contains(where: { CharacterSet.whitespacesAndNewlines.contains($0) })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed superfluous and appeared to result in some strings not tokenising as expected, so this is aligned with the similar code for Bookmarks on iOS.

Comment on lines 60 to 71
let mergedSuggestions = merge(navigationalSuggestions, maximum: maximumOfNavigationalSuggestions)
let expandedSuggestions = replaceHistoryWithBookmarksAndTabs(navigationalSuggestions)

let dedupedNavigationalSuggestions = Array(dedupSuggestions(expandedSuggestions).prefix(maximumOfNavigationalSuggestions))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should behave the same as before but split out to make reasoning a bit easier. Effectively history items are replaced by the first matching bookmark and/or tab that is found, but otherwise the list is not changed. Then we run a deduplication across the whole list.

@brindy brindy marked this pull request as ready for review September 19, 2024 11:45
Copy link
Contributor

@tomasstrba tomasstrba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT! 👏 Just couple of comments below, but no blockers

for (i, suggestion) in suggestions.enumerated() {
guard i <= Self.maximumNumberOfTopHits else { break }
for suggestion in suggestions {
guard topHits.count < Self.maximumNumberOfTopHits else { break }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@@ -39,7 +40,9 @@ extension Score {
score += 300
// Prioritize root URLs most
if url.isRoot { score += 2000 }
} else if lowercasedTitle.starts(with: query) {
} else if lowercasedTitle
.trimmingCharacters(in: .alphanumerics.inverted)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that matching these characters won't work from now on?
What if I want to find a title starting with a special character?

I checked in the currently released version and I can match a title with quotes which might be a valid use case.

Screenshot 2024-09-20 at 09 45 54

@brindy brindy merged commit 6e1520b into main Sep 22, 2024
7 checks passed
@brindy brindy deleted the brindy/tabs-in-suggestions branch September 22, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants