Fix matching algorithm in AutoFill
This commit is contained in:
parent
9e8994f576
commit
571281b655
3 changed files with 6 additions and 22 deletions
|
|
@ -38,8 +38,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
|
||||||
credentialProvider.identifier = serviceIdentifiers.first
|
credentialProvider.identifier = serviceIdentifiers.first
|
||||||
let url = serviceIdentifiers.first.flatMap { URL(string: $0.identifier) }
|
let url = serviceIdentifiers.first.flatMap { URL(string: $0.identifier) }
|
||||||
passwordsViewController.navigationItem.prompt = url?.host
|
passwordsViewController.navigationItem.prompt = url?.host
|
||||||
let keywords = url?.host?.sanitizedDomain?.components(separatedBy: ".") ?? []
|
passwordsViewController.showPasswordsWithSuggstion(matching: url?.host ?? "")
|
||||||
passwordsViewController.showPasswordsWithSuggstion(keywords)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
|
override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
|
||||||
|
|
@ -57,7 +56,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
|
||||||
}
|
}
|
||||||
credentialProvider.identifier = credentialIdentity.serviceIdentifier
|
credentialProvider.identifier = credentialIdentity.serviceIdentifier
|
||||||
passwordsViewController.navigationItem.prompt = identifier
|
passwordsViewController.navigationItem.prompt = identifier
|
||||||
passwordsViewController.showPasswordsWithSuggstion([identifier])
|
passwordsViewController.showPasswordsWithSuggstion(matching: identifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,14 +67,3 @@ extension CredentialProviderViewController: PasswordSelectionDelegate {
|
||||||
credentialProvider.persistAndProvideCredentials(with: passwordEntity.getPath())
|
credentialProvider.persistAndProvideCredentials(with: passwordEntity.getPath())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension String {
|
|
||||||
var sanitizedDomain: String? {
|
|
||||||
replacingOccurrences(of: ".com", with: "")
|
|
||||||
.replacingOccurrences(of: ".org", with: "")
|
|
||||||
.replacingOccurrences(of: ".edu", with: "")
|
|
||||||
.replacingOccurrences(of: ".net", with: "")
|
|
||||||
.replacingOccurrences(of: ".gov", with: "")
|
|
||||||
.replacingOccurrences(of: "www.", with: "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ class PasswordsViewController: UIViewController {
|
||||||
tableView.dataSource = dataSource
|
tableView.dataSource = dataSource
|
||||||
}
|
}
|
||||||
|
|
||||||
func showPasswordsWithSuggstion(_ keywords: [String]) {
|
func showPasswordsWithSuggstion(matching text: String) {
|
||||||
dataSource.showTableEntriesWithSuggestion(matching: keywords)
|
dataSource.showTableEntriesWithSuggestion(matching: text)
|
||||||
tableView.reloadData()
|
tableView.reloadData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,13 +91,9 @@ class PasswordsTableDataSource: NSObject, UITableViewDataSource {
|
||||||
showSuggestion = false
|
showSuggestion = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func showTableEntriesWithSuggestion(matching keywords: [String]) {
|
func showTableEntriesWithSuggestion(matching text: String) {
|
||||||
for entry in passwordTableEntries {
|
for entry in passwordTableEntries {
|
||||||
var match = false
|
if entry.match(text) {
|
||||||
for keyword in keywords {
|
|
||||||
match = match || entry.match(keyword)
|
|
||||||
}
|
|
||||||
if match {
|
|
||||||
suggestedPasswordsTableEntries.append(entry)
|
suggestedPasswordsTableEntries.append(entry)
|
||||||
} else {
|
} else {
|
||||||
otherPasswordsTableEntries.append(entry)
|
otherPasswordsTableEntries.append(entry)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue