diff options
| author | Niklas Baumstark | 2012-01-24 00:08:04 +0100 | 
|---|---|---|
| committer | Niklas Baumstark | 2012-04-10 23:54:38 +0200 | 
| commit | 2eae98f3b4b6cccaa49f91b282854c39145f12a4 (patch) | |
| tree | ae316be291bad0433393dbae537c501117e2d46b /lib/completion.js | |
| parent | 14cb3e4f8e552c082cae799f8dca511c6c267891 (diff) | |
| download | vimium-2eae98f3b4b6cccaa49f91b282854c39145f12a4.tar.bz2 | |
improve comments and fix some naming style inconsistencies
Diffstat (limited to 'lib/completion.js')
| -rw-r--r-- | lib/completion.js | 38 | 
1 files changed, 16 insertions, 22 deletions
| diff --git a/lib/completion.js b/lib/completion.js index 04899ca8..f06c6708 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -16,7 +16,7 @@ var completion = (function() {      self.filterCache = {};      /** Normalizes the string specified in :query. Strips any non-word characters and converts -      * to lower case. */ +     * to lower case. */      self.normalize = function(query) {        return query.replace(self.regexNonWord, '').toLowerCase();      } @@ -61,9 +61,9 @@ var completion = (function() {      }      /** Calculates a very simple similarity value between a :query and a :string. The current -      * implementation simply returns the cumulated length of query parts that are also found -      * in the string, raised to the power of 3. -      */ +     * implementation simply returns the cumulated length of query parts that are also found +     * in the string, raised to the power of 3. +     */      self.calculateRelevancy = function(query, str) {        query = self.normalize(query);        str   = self.normalize(str); @@ -89,8 +89,8 @@ var completion = (function() {      }      /** Returns a regex that matches a string using a fuzzy :query. Example: The :query "abc" would result -      * in a regex like /^([^a])*(a)([^b])*(b)([^c])*(c)(.*)$/ -      */ +     * in a regex like /^([^a])*(a)([^b])*(b)([^c])*(c)(.*)$/ +     */      self.getMatcher = function(query) {        query = self.normalize(query);        if (!(query in self.matcherCache)) { @@ -103,24 +103,18 @@ var completion = (function() {        return self.matcherCache[query];      } -    /** Clears the filter cache with the given ID. */ -    self.clearFilterCache = function(id) { -      if (id in self.filterCache) -        delete self.filterCache[id]; -    } - -    /** Filters a list :ary using fuzzy matching against an input string :query. If a query with a less -      * specific query was issued before (e.g. if the user added a letter to the query), the cached results -      * of the last filtering are used as a starting point, instead of :ary. -      */ -    self.filter = function(query, ary, getValue, id, callback) { +    /** Filters a collection :source using fuzzy matching against an input string :query. If a query with +     * a less specific query was issued before (e.g. if the user added a letter to the query), the cached +     * results of the last filtering are used as a starting point, instead of :source. +     */ +    self.filter = function(query, source, getValue, id) {        var filtered = [];        var source = ary;        if (!(id in self.filterCache))          self.filterCache[id] = {}; -      // find the most specific list of sources in the cache +      // find the most specific list of results in the cache        var maxSpecificity = 0;        var specificity;        for (key in self.filterCache[id]) { @@ -141,7 +135,7 @@ var completion = (function() {          }        } -      // clean up every few calls +      // don't clean up the cache every iteration        if (++self.timeToClean > 20) {          self.timeToClean = 0;          self.cleanMatcherCache(); @@ -156,7 +150,7 @@ var completion = (function() {      return self;    })(); -  /** Strips HTML tags using a naive regex replacement. Optinally, saves the stripped HTML tags in a +  /** Strips HTML tags using a naive regex replacement. Optionally, saves the stripped HTML tags in a     * dictionary indexed by the position where the tag should be reinserted. */    function stripHtmlTags(str, positions) {      var result = str.replace(/<[^>]*>/g, ''); @@ -366,9 +360,9 @@ var completion = (function() {    }    /** A fuzzy history completer */ -  var FuzzyHistoryCompleter = function(maxEntries) { +  var FuzzyHistoryCompleter = function(maxResults) {      AsyncFuzzyUrlCompleter.call(this); -    this.maxEntries = maxEntries || 1000; +    this.maxResults = maxResults || 1000;    }    FuzzyHistoryCompleter.prototype = new AsyncFuzzyUrlCompleter;    FuzzyHistoryCompleter.prototype.refresh = function() { | 
