summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorKris Maglione <maglione.k@gmail.com>2011-08-07 12:27:26 -0400
committerKris Maglione <maglione.k@gmail.com>2011-08-07 12:27:26 -0400
commitf617e3a346b7159c237eca45fdbb078bc649cb85 (patch)
tree9fd24bd5c6515b9a6028121c8d6c349a9eaeac9b /common
parent85dfd5becd1d4c91ec64e260f19df6340331dcb4 (diff)
downloadpentadactyl-f617e3a346b7159c237eca45fdbb078bc649cb85.tar.gz
Add basic stringmap support to Option.validateCompleter.
Diffstat (limited to 'common')
-rw-r--r--common/modules/options.jsm27
1 files changed, 18 insertions, 9 deletions
diff --git a/common/modules/options.jsm b/common/modules/options.jsm
index 20da4a61..5754cc71 100644
--- a/common/modules/options.jsm
+++ b/common/modules/options.jsm
@@ -307,6 +307,12 @@ var Option = Class("Option", {
context.completions = this.values;
},
+ _completions: function _completions(extra) {
+ let context = CompletionContext("");
+ return context.fork("", 0, this, this.completer, extra) ||
+ context.allItems.items.map(function (item) [item.text]);
+ },
+
/**
* @property {[[string, string]]} This option's possible values.
* @see CompletionContext
@@ -689,23 +695,26 @@ var Option = Class("Option", {
* @param {value|[string]} values The value or array of values to validate.
* @returns {boolean}
*/
- validateCompleter: function validateCompleter(values) {
+ validateCompleter: function validateCompleter(vals) {
+ if (isObject(vals) && !isArray(vals)) {
+ let k = values(this._completions({ values: {} })).toObject();
+ let v = values(this._completions({ value: "" })).toObject();
+ util.dump(k, v);
+ return Object.keys(vals).every(Set.has(k)) && values(vals).every(Set.has(v));
+ }
+
if (this.values)
var acceptable = this.values.array || this.values;
- else {
- let context = CompletionContext("");
- acceptable = context.fork("", 0, this, this.completer);
- if (!acceptable)
- acceptable = context.allItems.items.map(function (item) [item.text]);
- }
+ else
+ acceptable = this._completions();
if (isArray(acceptable))
acceptable = Set(acceptable.map(function ([k]) k));
if (this.type === "regexpmap" || this.type === "sitemap")
- return Array.concat(values).every(function (re) Set.has(acceptable, re.result));
+ return Array.concat(vals).every(function (re) Set.has(acceptable, re.result));
- return Array.concat(values).every(Set.has(acceptable));
+ return Array.concat(vals).every(Set.has(acceptable));
},
types: {}