diff --git a/common/content/commands.js b/common/content/commands.js index 99daaf8b..14a1df86 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -264,7 +264,8 @@ var Command = Class("Command", { }, argsPrototype: Class.memoize(function () update([], array(this.options).filter(function (opt) opt.default !== undefined) - .map(function (opt) [opt.names[0], opt.default]).toObject(), + .map(function (opt) [opt.names[0], Class.Property(Object.getOwnPropertyDescriptor(opt, "default"))]) + .toObject(), { __iterator__: function () array.iterItems(this), command: this, diff --git a/common/content/mappings.js b/common/content/mappings.js index ce224ca4..48533dbc 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -498,10 +498,7 @@ var Mappings = Module("mappings", { description: "Mapping group to which to add this mapping", type: CommandOption.STRING, get default() io.sourcing && io.sourcing.mapHive || mappings.userHive, - completer: function (context) { - context.keys = { text: "name", description: function (h) h.description || h.filter }; - context.completions = mappings.allHives.filter(function (h) h.name != "builtin"); - }, + completer: function (context) completion.mapGroup(context), validator: Option.validateCompleter }, { @@ -608,10 +605,8 @@ var Mappings = Module("mappings", { function (args) { dactyl.assert(args.length <= 2, "Trailing characters"); - if (args.length == 0) { - throw FailedAssertion("Not implemented"); - return; - } + if (args.length == 0) + return void completion.listCompleter("mapGroup", ""); let name = Option.dequote(args[0]); let hive = mappings.getHive(name); @@ -645,6 +640,20 @@ var Mappings = Module("mappings", { { argCount: "*", bang: true, + completer: function (context, args) { + if (args.length == 1) + completion.mapGroup(context); + else { + Option.splitList(context.filter); + context.advance(Option._splitAt); + + context.compare = CompletionContext.Sort.unsorted + context.completions = [ + [buffer.uri.host, "Current Host"], + [buffer.uri.spec, "Current Page"] + ]; + } + }, keepQuotes: true, options: [ { @@ -748,6 +757,11 @@ var Mappings = Module("mappings", { [mode.name.toLowerCase()]); }, completion: function () { + completion.mapGroup = function mapGroup(context, modes) { + context.title = ["Map group"]; + context.keys = { text: "name", description: function (h) h.description || h.filter }; + context.completions = mappings.allHives.filter(function (h) h.name != "builtin"); + }; completion.userMapping = function userMapping(context, modes) { // FIXME: have we decided on a 'standard' way to handle this clash? --djk modes = modes || [modules.modes.NORMAL]; diff --git a/common/content/options.js b/common/content/options.js index 4211af66..d1780c11 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -1250,11 +1250,14 @@ var Options = Module("options", { case "regexpmap": let vals = Option.splitList(context.filter); let target = vals.pop() || ""; + let [count, key, quote] = Commands.parseArg(target, /:/, true); let split = Option._splitAt; + extra.key = Option.dequote(key); extra.value = count < target.length ? Option.dequote(target.substr(count + 1)) : null; extra.values = opt.parse(vals.join(",")); + Option._splitAt = split + (extra.value == null ? 0 : count + 1); break; } diff --git a/common/modules/base.jsm b/common/modules/base.jsm index d8801c9e..13c13471 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -708,7 +708,7 @@ else * @param {Object} desc The property descriptor. */ Class.Property = function Property(desc) update( - Object.create(Property.prototype), desc); + Object.create(Property.prototype), desc || { configurable: true, writable: true }); Class.Property.prototype.init = function () {}; /** * Extends a subclass with a superclass. The subclass's @@ -1152,7 +1152,10 @@ update(iter, { toObject: function toObject(iter) { let obj = {}; for (let [k, v] in iter) - obj[k] = v; + if (v instanceof Class.Property) + Object.defineProperty(obj, k, v.init(k) || v); + else + obj[k] = v; return obj; }, @@ -1283,7 +1286,12 @@ var array = Class("array", Array, { */ toObject: function toObject(assoc) { let obj = {}; - assoc.forEach(function ([k, v]) { obj[k] = v; }); + assoc.forEach(function ([k, v]) { + if (v instanceof Class.Property) + Object.defineProperty(obj, k, v.init(k) || v); + else + obj[k] = v; + }); return obj; },