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

Some fixes for stringmap option completion.

This commit is contained in:
Kris Maglione
2010-09-29 20:30:57 -04:00
parent d9200ebfa8
commit 631abed98d
3 changed files with 35 additions and 28 deletions

View File

@@ -170,14 +170,9 @@ const Command = Class("Command", {
* @see Commands#parseArgs * @see Commands#parseArgs
*/ */
parseArgs: function (args, complete, extra) commands.parseArgs(args, { parseArgs: function (args, complete, extra) commands.parseArgs(args, {
allowUnknownOptions: !!this.allowUnknownOptions, __proto__: this,
argCount: this.argCount,
complete: complete, complete: complete,
extra: extra, extra: extra
hereDoc: this.hereDoc,
keepQuotes: !!this.keepQuotes,
literal: this.literal,
options: this.options
}), }),
/** /**

View File

@@ -453,12 +453,14 @@ const Option = Class("Option", {
let res = []; let res = [];
Option._splitAt = 0; Option._splitAt = 0;
do { do {
if (count !== undefined)
value = value.slice(1);
var [count, arg, quote] = Commands.parseArg(value, /,/, keepQuotes); var [count, arg, quote] = Commands.parseArg(value, /,/, keepQuotes);
Option._quote = quote; // FIXME Option._quote = quote; // FIXME
res.push(arg); res.push(arg);
if (value.length > count) if (value.length > count)
Option._splitAt += count + 1; Option._splitAt += count + 1;
value = value.slice(count + 1); value = value.slice(count);
} while (value.length); } while (value.length);
return res; return res;
}, },
@@ -494,22 +496,26 @@ const Option = Class("Option", {
}, },
stringmap: function (operator, values, scope, invert) { stringmap: function (operator, values, scope, invert) {
values = Array.concat(values); let res = update({}, this.values);
orig = [k + ":" + v for ([k, v] in Iterator(this.values))];
switch (operator) { switch (operator) {
// The result is the same.
case "+": case "+":
return array.uniq(Array.concat(orig, values), true);
case "^": case "^":
// NOTE: Vim doesn't prepend if there's a match in the current value return update(res, values);
return array.uniq(Array.concat(values, orig), true);
case "-": case "-":
return orig.filter(function (item) values.indexOf(item) == -1); for (let [k, v] in Iterator(values))
if (v === res[k])
delete res[k];
return res;
case "=": case "=":
if (invert) { if (invert) {
let keepValues = orig.filter(function (item) values.indexOf(item) == -1); for (let [k, v] in Iterator(values))
let addValues = values.filter(function (item) self.values.indexOf(item) == -1); if (v === res[k])
return addValues.concat(keepValues); delete res[k];
else
res[k] = v;
return res;
} }
return values; return values;
} }
@@ -1412,6 +1418,7 @@ const Options = Module("options", {
return; return;
} }
let extra = {};
switch (opt.type) { switch (opt.type) {
case "boolean": case "boolean":
if (!completer) if (!completer)
@@ -1425,8 +1432,13 @@ const Options = Module("options", {
case "stringmap": case "stringmap":
case "regexmap": case "regexmap":
let vals = Option.splitList(context.filter); let vals = Option.splitList(context.filter);
target = vals.pop() || ""; let target = vals.pop() || "";
Option._splitAt += target.indexOf(":") ? target.indexOf(":") + 1 : 0; 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.parseValues(vals.join(","));
Option._splitAt = split + (extra.value == null ? 0 : count + 1);
break; break;
} }
// TODO: Highlight when invalid // TODO: Highlight when invalid
@@ -1445,7 +1457,7 @@ const Options = Module("options", {
context.filters.push(function (i) curValues.indexOf(i.text) > -1); context.filters.push(function (i) curValues.indexOf(i.text) > -1);
} }
let res = completer.call(opt, context); let res = completer.call(opt, context, extra);
if (res) if (res)
context.completions = res; context.completions = res;
}; };

View File

@@ -51,7 +51,7 @@
<dd> <dd>
A comma-separated list of regular expressions. Expressions may be A comma-separated list of regular expressions. Expressions may be
prefixed with a <em>!</em>, in which case the match will be negated. A prefixed with a <em>!</em>, in which case the match will be negated. A
literal <em>!</em> at the begining of the expression may be matched literal <em>!</em> at the beginning of the expression may be matched
with <em>[!]</em> or by placing the regular expression in quotes. with <em>[!]</em> or by placing the regular expression in quotes.
Generally, the first matching regular expression is used. Any comma Generally, the first matching regular expression is used. Any comma
appearing within single or double quotes, or prefixed with a appearing within single or double quotes, or prefixed with a
@@ -376,7 +376,7 @@
</p> </p>
<example> <example>
To enable autocompletion for everything but <ex>:history</ex> or To enable auto-completion for everything but <ex>:history</ex> or
<ex>:bmarks</ex>, you would choose a value such as <ex>:bmarks</ex>, you would choose a value such as
<str delim="'">!/ex/bmarks,.?</str> <str delim="'">!/ex/bmarks,.?</str>
</example> </example>
@@ -401,7 +401,7 @@
<default>on</default> <default>on</default>
<description> <description>
<p> <p>
Replace occurences of ! with the previous command when Replace occurrences of ! with the previous command when
executing external commands. executing external commands.
</p> </p>
</description> </description>
@@ -641,7 +641,7 @@
<dt>T</dt> <dd>Toolbar</dd> <dt>T</dt> <dd>Toolbar</dd>
<dt>b</dt> <dd>Bottom scrollbar</dd> <dt>b</dt> <dd>Bottom scrollbar</dd>
<dt>l</dt> <dd>Left scrollbar (<em>l</em> and <em>r</em> are mutually exclusive)</dd> <dt>l</dt> <dd>Left scrollbar (<em>l</em> and <em>r</em> are mutually exclusive)</dd>
<dt>m</dt> <dd>Menubar</dd> <dt>m</dt> <dd>Menu bar</dd>
<dt>n</dt> <dd>Tab number</dd> <dt>n</dt> <dd>Tab number</dd>
<dt>r</dt> <dd>Right scrollbar</dd> <dt>r</dt> <dd>Right scrollbar</dd>
</dl> </dl>
@@ -682,7 +682,7 @@
</p> </p>
<dl> <dl>
<dt>value</dt> <dd>The hint is the value displayed in a text input, or the selected option for a dropdown.</dd> <dt>value</dt> <dd>The hint is the value displayed in a text input, or the selected option for a drop-down.</dd>
<dt>label</dt> <dd>The value of an explicit label for the input; this will not match most manually added labels that are found on sites.</dd> <dt>label</dt> <dd>The value of an explicit label for the input; this will not match most manually added labels that are found on sites.</dd>
<dt>name </dt> <dd>The name of the input will be used; although the name is not designed for user consumption, it is frequently very similar to the label.</dd> <dt>name </dt> <dd>The name of the input will be used; although the name is not designed for user consumption, it is frequently very similar to the label.</dd>
</dl> </dl>
@@ -742,7 +742,7 @@
<dt>firstletters</dt> <dt>firstletters</dt>
<dd> <dd>
Behaves like wordstartswith, but non-matching words Behaves like wordstartswith, but non-matching words
aren't overleaped. aren't skipped.
</dd> </dd>
<dt>custom</dt> <dt>custom</dt>
<dd> <dd>
@@ -1113,7 +1113,7 @@
<tags>'previouspattern'</tags> <tags>'previouspattern'</tags>
<spec>'previouspattern'</spec> <spec>'previouspattern'</spec>
<type>stringlist</type> <type>stringlist</type>
<default><![CDATA[\bprev|previous\b,^<$,^(<<|«)$,^(<|«),(<|«)$]]></default> <default><![CDATA['\bprev|previous\b',^<$,'^(<<|«)$','^(<|«)','(<|«)$']]></default>
<description> <description>
<p> <p>
Patterns to use when guessing the previous page in a document Patterns to use when guessing the previous page in a document
@@ -1552,7 +1552,7 @@
<default><![CDATA[[.,!?:;\\/"^$%&?()[\]{}<>#*+|=~ _-]]]></default> <default><![CDATA[[.,!?:;\\/"^$%&?()[\]{}<>#*+|=~ _-]]]></default>
<description> <description>
<p> <p>
A regular expression which defines how words are split for the A regular expression which defines how words are split for
the <o>hintmatching</o> types <str>wordstartswith</str> and the <o>hintmatching</o> types <str>wordstartswith</str> and
<str>firstletters</str>. Words are split on each occurrence of the <str>firstletters</str>. Words are split on each occurrence of the
given pattern. given pattern.