aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2012-06-02 20:21:23 -0700
committerPhil Crosby2012-06-03 16:52:32 -0700
commit2cbb4961ce60d75c1535ad65ede5ca74db254cb3 (patch)
treebe54f31c4d1dd4841bfeb462cb0b0e6d7c51fe27
parente7f75e2c6add8048beb1f4dd2703766f016497bd (diff)
downloadvimium-2cbb4961ce60d75c1535ad65ede5ca74db254cb3.tar.bz2
Remove "action" from Suggestion. That level of genercism isn't needed atm.
-rw-r--r--background_scripts/completion.coffee9
-rw-r--r--content_scripts/vomnibar.js14
-rw-r--r--tests/completion_test.coffee6
3 files changed, 13 insertions, 16 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index 15725b62..5cc36227 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -1,8 +1,6 @@
class Suggestion
# - type: one of [bookmark, history, tab].
- # - action: one of [navigateToUrl, switchToTab].
- # TODO(philc): remove action. I don't think we need it here.
- constructor: (@queryTerms, @type, @url, @title, @action) ->
+ constructor: (@queryTerms, @type, @url, @title) ->
generateHtml: ->
@html ||=
@@ -51,7 +49,7 @@ class BookmarkCompleter
results = @bookmarks.filter (bookmark) =>
RankingUtils.matches(@currentSearch.queryTerms, bookmark.url, bookmark.title)
suggestions = results.map (bookmark) =>
- new Suggestion(@currentSearch.queryTerms, "bookmark", bookmark.url, bookmark.title, "navigateToUrl")
+ new Suggestion(@currentSearch.queryTerms, "bookmark", bookmark.url, bookmark.title)
onComplete = @currentSearch.onComplete
@currentSearch = null
onComplete(suggestions)
@@ -79,8 +77,7 @@ class HistoryCompleter
results = []
HistoryCache.use (history) ->
results = history.filter (entry) -> RankingUtils.matches(queryTerms, entry.url, entry.title)
- suggestions = results.map (entry) =>
- new Suggestion(queryTerms, "history", entry.url, entry.title, "navigateToUrl")
+ suggestions = results.map (entry) => new Suggestion(queryTerms, "history", entry.url, entry.title)
onComplete(suggestions)
refresh: ->
diff --git a/content_scripts/vomnibar.js b/content_scripts/vomnibar.js
index 3fedc8c4..b3bc00f4 100644
--- a/content_scripts/vomnibar.js
+++ b/content_scripts/vomnibar.js
@@ -195,14 +195,14 @@ var vomnibar = (function() {
this.filterPort.onMessage.addListener(function(msg) {
if (msg.id != id) return;
// The result objects coming from the background page will be of the form:
- // { html: "", action: "", url: "" }
- // action will be either "navigateToUrl" or "switchToTab".
+ // { html: "", type: "", url: "" }
+ // type will be one of [tab, bookmark, history].
var results = msg.results.map(function(result) {
- var functionToCall = completionActions[result.action];
- if (result.action == "navigateToUrl")
- functionToCall = functionToCall.curry(result.url);
- else if (result.action == "switchToTab")
- functionToCall = functionToCall.curry(result.tabId);
+ var functionToCall;
+ if (result.type == "tab")
+ functionToCall = completionActions.switchToTab.curry(result.tabId);
+ else
+ functionToCall = completionActions.navigateToUrl.curry(result.url);
result.performAction = functionToCall;
return result;
});
diff --git a/tests/completion_test.coffee b/tests/completion_test.coffee
index eb833ecf..b79eae98 100644
--- a/tests/completion_test.coffee
+++ b/tests/completion_test.coffee
@@ -39,15 +39,15 @@ context "history completer",
context "suggestions",
should "escape html in page titles", ->
- suggestion = new Suggestion(["queryterm"], "tab", "url", "title <span>", "action")
+ suggestion = new Suggestion(["queryterm"], "tab", "url", "title <span>")
assert.isTrue suggestion.generateHtml().indexOf("title &lt;span&gt;") >= 0
should "highlight query words", ->
- suggestion = new Suggestion(["ninja"], "tab", "url", "ninjawords", "action")
+ suggestion = new Suggestion(["ninja"], "tab", "url", "ninjawords")
assert.isTrue suggestion.generateHtml().indexOf("<span class='match'>ninja</span>words") >= 0
should "shorten urls", ->
- suggestion = new Suggestion(["queryterm"], "tab", "http://ninjawords.com", "ninjawords", "action")
+ suggestion = new Suggestion(["queryterm"], "tab", "http://ninjawords.com", "ninjawords")
assert.equal -1, suggestion.generateHtml().indexOf("http://ninjawords.com")
Tests.run() \ No newline at end of file