Autocomplete UI

This commit is contained in:
James Magahern
2020-09-21 17:56:22 -07:00
parent 7f2cd23889
commit e2d5dbee59
5 changed files with 155 additions and 5 deletions

View File

@@ -62,11 +62,15 @@ class BrowserHistory
let topLevelURL = item.url.topLevelURL()
var topLevelItem = topLevelItems[topLevelURL] ?? (item, 0)
topLevelItem.0.url = topLevelURL
if item.url.path == "/" || item.url.path == "" {
topLevelItem.0.title = item.title
}
topLevelItem.1 += 1
topLevelItems[topLevelURL] = topLevelItem
}
return topLevelItems.values.map { return $0.0 }.sorted { (item1, item2) -> Bool in
return topLevelItems[item1.url]!.1 < topLevelItems[item2.url]!.1
return topLevelItems[item1.url]!.1 > topLevelItems[item2.url]!.1
}
}
}
@@ -76,8 +80,9 @@ extension URL
public func topLevelURL() -> URL {
if var components = URLComponents(url: self, resolvingAgainstBaseURL: false) {
components.path = ""
components.query = ""
components.queryItems = []
components.query = nil
components.queryItems = nil
components.fragment = nil
if let url = components.url {
return url
}