1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 18:47:58 +01:00

Provide completion and some bug fixes for :mapg.

This commit is contained in:
Kris Maglione
2011-01-19 05:00:35 -05:00
parent 3c240d29ed
commit ff34528f15
4 changed files with 38 additions and 12 deletions

View File

@@ -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,

View File

@@ -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];

View File

@@ -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;
}

View File

@@ -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;
},