aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-05-17 06:11:45 +0100
committerStephen Blott2015-05-17 06:27:49 +0100
commit69cd8c08375cdf5df8636748f6f479552d780b8f (patch)
treefb6fdb1af39f77d27dbed9bbae8c8f0366175e83
parentc09e70364118264804510ee4b06f3ff8d38933b1 (diff)
downloadvimium-69cd8c08375cdf5df8636748f6f479552d780b8f.tar.bz2
TabToOpen: tab to open vomnibar.
`o` then `Tab` opens the vomnibar completionlist with history completions (the only completions) ranked by recently only. Hence, the most recent requests are at the top. This is a (far) simpler approach than #1662 which catches the most important use case (repeat a search with an edited query).
-rw-r--r--background_scripts/completion.coffee7
-rw-r--r--pages/vomnibar.coffee19
2 files changed, 20 insertions, 6 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index eb80f3cd..80b47055 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -225,7 +225,7 @@ class BookmarkCompleter
RankingUtils.wordRelevancy(suggestion.queryTerms, suggestion.url, suggestion.title)
class HistoryCompleter
- filter: ({ queryTerms }, onComplete) ->
+ filter: ({ queryTerms, tabToOpen }, onComplete) ->
@currentSearch = { queryTerms: @queryTerms, onComplete: @onComplete }
results = []
HistoryCache.use (history) =>
@@ -233,6 +233,9 @@ class HistoryCompleter
results =
if queryTerms.length > 0
history.filter (entry) -> RankingUtils.matches(queryTerms, entry.url, entry.title)
+ else if tabToOpen
+ # <Tab> opens the completion list, even without a query.
+ history
else
[]
onComplete results.map (entry) =>
@@ -256,6 +259,8 @@ class HistoryCompleter
computeRelevancy: (suggestion) ->
historyEntry = suggestion.relevancyData
recencyScore = RankingUtils.recencyScore(historyEntry.lastVisitTime)
+ # If there are no query terms, then relevancy is based on recency alone.
+ return recencyScore if suggestion.queryTerms.length == 0
wordRelevancy = RankingUtils.wordRelevancy(suggestion.queryTerms, suggestion.url, suggestion.title)
if suggestion.insertText?
# If this suggestion matches a previous search with the default search engine, then we also score the
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index 07eb39bb..731ebed2 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -71,6 +71,7 @@ class VomnibarUI
@customSearchMode = null
@selection = @initialSelectionValue
@keywords = []
+ @tabToOpen = false
updateSelection: ->
# For custom search engines, we suppress the leading term (e.g. the "w" of "w query terms") within the
@@ -125,9 +126,13 @@ class VomnibarUI
if (action == "dismiss")
@hide()
else if action in [ "tab", "down" ]
- @selection += 1
- @selection = @initialSelectionValue if @selection == @completions.length
- @updateSelection()
+ if @input.value.trim().length == 0 and action == "tab" and not @tabToOpen
+ @tabToOpen = true
+ @update true
+ else
+ @selection += 1
+ @selection = @initialSelectionValue if @selection == @completions.length
+ @updateSelection()
else if (action == "up")
@selection -= 1
@selection = @completions.length - 1 if @selection < @initialSelectionValue
@@ -150,12 +155,16 @@ class VomnibarUI
completion = @completions[@selection]
@hide -> completion.performAction openInNewTab
else if action == "delete"
- if @customSearchMode? and @input.value.length == 0
+ inputIsEmpty = @input.value.length == 0
+ if inputIsEmpty and @customSearchMode?
# Normally, with custom search engines, the keyword (e,g, the "w" of "w query terms") is suppressed.
# If the input is empty, then reinstate the keyword (the "w").
@input.value = @customSearchMode
@customSearchMode = null
@updateCompletions()
+ else if inputIsEmpty and @tabToOpen
+ @tabToOpen = false
+ @update true
else
return true # Do not suppress event.
@@ -172,6 +181,7 @@ class VomnibarUI
updateCompletions: (callback = null) ->
@completer.filter
query: @getInputValueAsQuery()
+ tabToOpen: @tabToOpen
callback: (@lastReponse) =>
{ results } = @lastReponse
@completions = results
@@ -275,7 +285,6 @@ class BackgroundCompleter
queryTerms: query.trim().split(/\s+/).filter (s) -> 0 < s.length
# We don't send these keys.
callback: null
- mayUseVomnibarCache: null
reset: ->
@keywords = []