diff options
| -rw-r--r-- | background_page.html | 17 | ||||
| -rw-r--r-- | content_scripts/vomnibar.js | 29 | ||||
| -rw-r--r-- | lib/utils.js | 15 | ||||
| -rw-r--r-- | test_harnesses/automated.html | 26 | 
4 files changed, 45 insertions, 42 deletions
| diff --git a/background_page.html b/background_page.html index ccd06044..bae23acb 100644 --- a/background_page.html +++ b/background_page.html @@ -222,32 +222,27 @@             };    } -  /** +  /*      * Opens the url in the current tab.      */     function openUrlInCurrentTab(request) {       chrome.tabs.getSelected(null, function(tab) { -       chrome.tabs.update(tab.id, {url: request.url}); +       chrome.tabs.update(tab.id, { url: utils.convertToUrl(request.url) });       });     } -  /** +  /*     * Opens request.url in new tab and switches to it if request.selected is true. -   *     */    function openUrlInNewTab(request) {      chrome.tabs.getSelected(null, function(tab) { -      chrome.tabs.create({ url: request.url, index: tab.index + 1, selected: true }); +      chrome.tabs.create({ url: utils.convertToUrl(request.url), index: tab.index + 1, selected: true });      });    } -  function openCopiedUrlInCurrentTab(request) { -    openUrlInCurrentTab({ url: utils.ensureUrl(Clipboard.paste()) }); -  } +  function openCopiedUrlInCurrentTab(request) { openUrlInCurrentTab({ url: Clipboard.paste() }); } -  function openCopiedUrlInNewTab(request) { -    openUrlInNewTab({ url: utils.ensureUrl(Clipboard.paste()) }); -  } +  function openCopiedUrlInNewTab(request) { openUrlInNewTab({ url: Clipboard.paste() }); }    /*     * Returns the user-provided CSS overrides. diff --git a/content_scripts/vomnibar.js b/content_scripts/vomnibar.js index f0460ffa..e9d345f4 100644 --- a/content_scripts/vomnibar.js +++ b/content_scripts/vomnibar.js @@ -28,7 +28,6 @@ var vomnibar = (function() {    /** User interface for fuzzy completion */    var VomnibarUI = Class.extend({      init: function() { -      this.prompt = '>';        this.refreshInterval = 0;        this.initDom();      }, @@ -59,7 +58,7 @@ var vomnibar = (function() {        this.input.value = "";        this.updateTimer = null;        this.completions = []; -      this.selection = 0; +      this.selection = -1;        this.update(true);      }, @@ -94,11 +93,12 @@ var vomnibar = (function() {        var action = this.actionFromKeyEvent(event);        if (!action) return true; // pass through +      var openInNewTab = (event.shiftKey || isPrimaryModifierKey(event));        if (action == "dismiss") {          this.hide();        }        else if (action == "up") { -        if (this.selection > 0) +        if (this.selection >= 0)            this.selection -= 1;          this.updateSelection();        } @@ -108,12 +108,21 @@ var vomnibar = (function() {          this.updateSelection();        }        else if (action == "enter") { -        this.update(true, function() { -          // Shift+Enter will open the result in a new tab instead of the current tab. -          var openInNewTab = (event.shiftKey || isPrimaryModifierKey(event)); -          this.completions[this.selection].performAction(openInNewTab); -          this.hide(); -        }.proxy(this)); +        // If they type something and hit enter without selecting a completion from our list of suggestions, +        // try to open their query as a URL directly. If it doesn't look like a URL, we will search using +        // google. +        if (this.selection == -1) { +          var query = this.input.value.trim(); +          chrome.extension.sendRequest({ +            handler: openInNewTab ? "openUrlInNewTab" : "openUrlInCurrentTab", +            url: query }); +        } else { +          this.update(true, function() { +            // Shift+Enter will open the result in a new tab instead of the current tab. +            this.completions[this.selection].performAction(openInNewTab); +            this.hide(); +          }.proxy(this)); +        }        }        // It seems like we have to manually supress the event here and still return true. @@ -123,7 +132,7 @@ var vomnibar = (function() {      },      updateCompletions: function(callback) { -      query = this.input.value.replace(/^\s*/, "").trim(); +      query = this.input.value.trim();        this.completer.filter(query, function(completions) {          this.completions = completions; diff --git a/lib/utils.js b/lib/utils.js index 1babb2ec..5bb3a6cc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -143,16 +143,15 @@ root.utils = {    },    /** -   * Tries to convert :str into a valid URL. -   * We don't bother with escaping characters, however, as Chrome will do that for us. +   * Converts :string into a google search if it's not already a URL. +   * We don't bother with escaping characters as Chrome will do that for us.     */ -  ensureUrl: function(str) { -    // trim str -    str = str.replace(/^\s+|\s+$/g, ''); -    if (utils.isUrl(str)) -      return utils.createFullUrl(str); +  convertToUrl: function(string) { +    string = string.trim(); +    if (utils.isUrl(string)) +      return utils.createFullUrl(string);      else -      return utils.createSearchUrl(str); +      return utils.createSearchUrl(string);    }  }; diff --git a/test_harnesses/automated.html b/test_harnesses/automated.html index 789b744d..5e55c368 100644 --- a/test_harnesses/automated.html +++ b/test_harnesses/automated.html @@ -278,20 +278,20 @@        context("Web query parsing",          should("Convert query string to valid URL", function() { -          assert.equal("http://www.google.com/", utils.ensureUrl("http://www.google.com/")); -          assert.equal("http://www.google.com/", utils.ensureUrl("    http://www.google.com/     ")); -          assert.equal("http://www.google.com", utils.ensureUrl("www.google.com")); -          assert.equal("http://google.com", utils.ensureUrl("google.com")); -          assert.equal("http://www.google.com/search?q=google", utils.ensureUrl("google")); -          assert.equal("http://www.google.com/search?q=go ogle.com", utils.ensureUrl("go ogle.com")); -          assert.equal("http://localhost", utils.ensureUrl("localhost")); -          assert.equal("http://xyz.museum", utils.ensureUrl("xyz.museum")); -          assert.equal("chrome://extensions", utils.ensureUrl("chrome://extensions")); +          assert.equal("http://www.google.com/", utils.convertToUrl("http://www.google.com/")); +          assert.equal("http://www.google.com/", utils.convertToUrl("    http://www.google.com/     ")); +          assert.equal("http://www.google.com", utils.convertToUrl("www.google.com")); +          assert.equal("http://google.com", utils.convertToUrl("google.com")); +          assert.equal("http://www.google.com/search?q=google", utils.convertToUrl("google")); +          assert.equal("http://www.google.com/search?q=go ogle.com", utils.convertToUrl("go ogle.com")); +          assert.equal("http://localhost", utils.convertToUrl("localhost")); +          assert.equal("http://xyz.museum", utils.convertToUrl("xyz.museum")); +          assert.equal("chrome://extensions", utils.convertToUrl("chrome://extensions"));            assert.equal("http://user:pass@ftp.xyz.com/test", -                       utils.ensureUrl("user:pass@ftp.xyz.com/test")); -          assert.equal("http://127.0.0.1", utils.ensureUrl("127.0.0.1")); -          assert.equal("http://127.0.0.1:8080", utils.ensureUrl("127.0.0.1:8080")); -          assert.equal("http://[::]:8080", utils.ensureUrl("[::]:8080")); +                       utils.convertToUrl("user:pass@ftp.xyz.com/test")); +          assert.equal("http://127.0.0.1", utils.convertToUrl("127.0.0.1")); +          assert.equal("http://127.0.0.1:8080", utils.convertToUrl("127.0.0.1:8080")); +          assert.equal("http://[::]:8080", utils.convertToUrl("[::]:8080"));          })        ); | 
