1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-13 00:25:47 +01:00

Import (and augment) my cookies plugin per Doug's suggestion, and improve dactyl.generateHelp (and :yank).

This commit is contained in:
Kris Maglione
2010-10-15 00:30:03 -04:00
parent bea1c20858
commit a3799d3d05
10 changed files with 348 additions and 62 deletions

View File

@@ -1571,8 +1571,6 @@ const CommandLine = Module("commandline", {
if (typeof arg === "object")
arg = util.objectToString(arg, useColor);
else if (typeof arg === "string" && /\n/.test(arg))
arg = <span highlight="CmdOutput">{arg}</span>;
else
arg = String(arg);
@@ -1983,7 +1981,8 @@ const ItemList = Class("ItemList", {
this._fill(newOffset);
if (index >= 0) {
this._getCompletion(index).setAttribute("selected", "true");
util.scrollIntoView(this._getCompletion(index));
if (this._container.height != 0)
util.scrollIntoView(this._getCompletion(index));
}
//if (index == 0)

View File

@@ -733,8 +733,11 @@ const Completion = Module("completion", {
let context = CompletionContext(filter);
context.maxItems = maxItems;
let res = context.fork.apply(context, ["run", 0, this, name].concat(Array.slice(arguments, 3)));
if (res) // FIXME
return { items: res.map(function (i) ({ item: i })) };
if (res) {
if (Components.stack.caller.name === "runCompleter") // FIXME
return { items: res.map(function (i) ({ item: i })) };
context.contexts["/run"].completions = res;
}
context.wait(true);
return context.allItems;
},

View File

@@ -603,16 +603,27 @@ const Dactyl = Module("dactyl", {
* @param {XMLList} extraHelp Extra help text beyond the description.
* @returns {string}
*/
generateHelp: function generateHelp(obj, extraHelp) {
generateHelp: function generateHelp(obj, extraHelp, str) {
default xml namespace = "";
let spec = util.identity;
let tag = util.identity;
if (obj instanceof Command)
let link, tag, spec;
link = tag = spec = util.identity;
let args = null;
if (obj instanceof Command) {
tag = spec = function (cmd) <>:{cmd}</>;
else if (obj instanceof Map && obj.count)
link = function (cmd) <ex>:{cmd}</ex>
args = obj.parseArgs("", CompletionContext(str || ""));
}
else if (obj instanceof Map && obj.count) {
spec = function (map) <><oa>count</oa>{map}</>;
else if (obj instanceof Option)
link = function (map) let (res = /^<(.*?)>(.*?)/.exec(map))
res ? <k name={res[1]}>{res[2]}</k> : <k>{map}</k>;
}
else if (obj instanceof Option) {
tag = spec = function (opt) <>'{opt}'</>;
link = function (opt) <o>{opt}</o>;
}
XML.prettyPrinting = false;
XML.ignoreWhitespace = false;
@@ -621,7 +632,17 @@ const Dactyl = Module("dactyl", {
let br = <>
</>;
if (obj.completer)
var completions = let (br = br + <> </>) <>
<dl>{ br +
template.map(
completion._runCompleter(obj.completer, "", null, args).items,
function (i) <><dt>{i.text}</dt> <dd>{i.description}</dd></>,
br) }
</dl></>;
return <>
<dt>{link(obj.name)}</dt> <dd>{obj.description ? obj.description.replace(/\.$/, "") : ""}</dd>
<item>
<tags>{template.map(obj.names, tag, " ")}</tags>
<spec>{spec((obj.specs || obj.names)[0])}</spec>{
@@ -631,7 +652,8 @@ const Dactyl = Module("dactyl", {
<description>{
obj.description ? br+<p>{obj.description.replace(/\.?$/, ".")}</p> : "" }{
extraHelp ? br+extraHelp : "" }{
!(extraHelp || obj.description) ? br+<p>Sorry, no help available.</p> : "" }
!(extraHelp || obj.description) ? br+<p>Sorry, no help available.</p> : "" }{
completions ? br + completions : "" }
</description>
</item></>.toXMLString().replace(/^ {12}/gm, "");
},