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:
@@ -264,7 +264,8 @@ var Command = Class("Command", {
|
|||||||
},
|
},
|
||||||
argsPrototype: Class.memoize(function () update([],
|
argsPrototype: Class.memoize(function () update([],
|
||||||
array(this.options).filter(function (opt) opt.default !== undefined)
|
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),
|
__iterator__: function () array.iterItems(this),
|
||||||
command: this,
|
command: this,
|
||||||
|
|||||||
@@ -498,10 +498,7 @@ var Mappings = Module("mappings", {
|
|||||||
description: "Mapping group to which to add this mapping",
|
description: "Mapping group to which to add this mapping",
|
||||||
type: CommandOption.STRING,
|
type: CommandOption.STRING,
|
||||||
get default() io.sourcing && io.sourcing.mapHive || mappings.userHive,
|
get default() io.sourcing && io.sourcing.mapHive || mappings.userHive,
|
||||||
completer: function (context) {
|
completer: function (context) completion.mapGroup(context),
|
||||||
context.keys = { text: "name", description: function (h) h.description || h.filter };
|
|
||||||
context.completions = mappings.allHives.filter(function (h) h.name != "builtin");
|
|
||||||
},
|
|
||||||
validator: Option.validateCompleter
|
validator: Option.validateCompleter
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -608,10 +605,8 @@ var Mappings = Module("mappings", {
|
|||||||
function (args) {
|
function (args) {
|
||||||
dactyl.assert(args.length <= 2, "Trailing characters");
|
dactyl.assert(args.length <= 2, "Trailing characters");
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0)
|
||||||
throw FailedAssertion("Not implemented");
|
return void completion.listCompleter("mapGroup", "");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let name = Option.dequote(args[0]);
|
let name = Option.dequote(args[0]);
|
||||||
let hive = mappings.getHive(name);
|
let hive = mappings.getHive(name);
|
||||||
@@ -645,6 +640,20 @@ var Mappings = Module("mappings", {
|
|||||||
{
|
{
|
||||||
argCount: "*",
|
argCount: "*",
|
||||||
bang: true,
|
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,
|
keepQuotes: true,
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
@@ -748,6 +757,11 @@ var Mappings = Module("mappings", {
|
|||||||
[mode.name.toLowerCase()]);
|
[mode.name.toLowerCase()]);
|
||||||
},
|
},
|
||||||
completion: function () {
|
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) {
|
completion.userMapping = function userMapping(context, modes) {
|
||||||
// FIXME: have we decided on a 'standard' way to handle this clash? --djk
|
// FIXME: have we decided on a 'standard' way to handle this clash? --djk
|
||||||
modes = modes || [modules.modes.NORMAL];
|
modes = modes || [modules.modes.NORMAL];
|
||||||
|
|||||||
@@ -1250,11 +1250,14 @@ var Options = Module("options", {
|
|||||||
case "regexpmap":
|
case "regexpmap":
|
||||||
let vals = Option.splitList(context.filter);
|
let vals = Option.splitList(context.filter);
|
||||||
let target = vals.pop() || "";
|
let target = vals.pop() || "";
|
||||||
|
|
||||||
let [count, key, quote] = Commands.parseArg(target, /:/, true);
|
let [count, key, quote] = Commands.parseArg(target, /:/, true);
|
||||||
let split = Option._splitAt;
|
let split = Option._splitAt;
|
||||||
|
|
||||||
extra.key = Option.dequote(key);
|
extra.key = Option.dequote(key);
|
||||||
extra.value = count < target.length ? Option.dequote(target.substr(count + 1)) : null;
|
extra.value = count < target.length ? Option.dequote(target.substr(count + 1)) : null;
|
||||||
extra.values = opt.parse(vals.join(","));
|
extra.values = opt.parse(vals.join(","));
|
||||||
|
|
||||||
Option._splitAt = split + (extra.value == null ? 0 : count + 1);
|
Option._splitAt = split + (extra.value == null ? 0 : count + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -708,7 +708,7 @@ else
|
|||||||
* @param {Object} desc The property descriptor.
|
* @param {Object} desc The property descriptor.
|
||||||
*/
|
*/
|
||||||
Class.Property = function Property(desc) update(
|
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 () {};
|
Class.Property.prototype.init = function () {};
|
||||||
/**
|
/**
|
||||||
* Extends a subclass with a superclass. The subclass's
|
* Extends a subclass with a superclass. The subclass's
|
||||||
@@ -1152,7 +1152,10 @@ update(iter, {
|
|||||||
toObject: function toObject(iter) {
|
toObject: function toObject(iter) {
|
||||||
let obj = {};
|
let obj = {};
|
||||||
for (let [k, v] in iter)
|
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;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1283,7 +1286,12 @@ var array = Class("array", Array, {
|
|||||||
*/
|
*/
|
||||||
toObject: function toObject(assoc) {
|
toObject: function toObject(assoc) {
|
||||||
let obj = {};
|
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;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user