diff options
| -rw-r--r-- | background_scripts/completion.coffee | 10 | ||||
| -rw-r--r-- | lib/utils.coffee | 11 |
2 files changed, 12 insertions, 9 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index 0a936459..b75ebb87 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -238,8 +238,8 @@ class DomainCompleter onComplete() onPageVisited: (newPage) -> - domain = @parseDomain(newPage.url) - if domain and not Utils.hasChromePrefix newPage.url + domain = @parseDomainAndScheme newPage.url + if domain slot = @domains[domain] ||= { entry: newPage, referenceCount: 0 } # We want each entry in our domains hash to point to the most recent History entry for that domain. slot.entry = newPage if slot.entry.lastVisitTime < newPage.lastVisitTime @@ -250,11 +250,13 @@ class DomainCompleter @domains = {} else toRemove.urls.forEach (url) => - domain = @parseDomain(url) + domain = @parseDomainAndScheme url if domain and @domains[domain] and ( @domains[domain].referenceCount -= 1 ) == 0 delete @domains[domain] - parseDomain: (url) -> url.split("/")[2] || "" + # Return something like "http://www.example.com" or false. + parseDomainAndScheme: (url) -> + Utils.hasFullUrlPrefix(url) and not Utils.hasChromePrefix(url) and url.split("/",3).join "/" # Suggestions from the Domain completer have the maximum relevancy. They should be shown first in the list. computeRelevancy: -> 1 diff --git a/lib/utils.coffee b/lib/utils.coffee index e2ed8d98..62749496 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -33,17 +33,18 @@ Utils = return true if url.startsWith prefix false + hasFullUrlPrefix: do -> + urlPrefix = new RegExp "^[a-z]{3,}://." + (url) -> urlPrefix.test url + # Completes a partial URL (without scheme) createFullUrl: (partialUrl) -> - unless /^[a-z]{3,}:\/\//.test partialUrl - "http://" + partialUrl - else - partialUrl + if @hasFullUrlPrefix(partialUrl) then partialUrl else ("http://" + partialUrl) # Tries to detect if :str is a valid URL. isUrl: (str) -> # Starts with a scheme: URL - return true if /^[a-z]{3,}:\/\//.test str + return true if @hasFullUrlPrefix str # Must not contain spaces return false if ' ' in str |
