1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 12:07:57 +01:00

Toggle between values in a list for string/number options with invert.

This commit is contained in:
Kris Maglione
2010-12-17 14:48:46 -05:00
parent 87c2e5624d
commit 754d490a56
4 changed files with 26 additions and 22 deletions

View File

@@ -342,7 +342,7 @@ lookup:
this.withSavedValues(["sourcing"], function () { this.withSavedValues(["sourcing"], function () {
this.sourcing = null; this.sourcing = null;
try { try {
var file = io.File(util.getFile(filename) || filename); var file = util.getFile(filename) || io.File(filename);
if (!file.exists() || !file.isReadable() || file.isDirectory()) { if (!file.exists() || !file.isReadable() || file.isDirectory()) {
if (!silent) if (!silent)

View File

@@ -223,11 +223,11 @@ const Option = Class("Option", {
*/ */
op: function (operator, values, scope, invert, str) { op: function (operator, values, scope, invert, str) {
let newValues = this._op(operator, values, scope, invert);
if (newValues == null)
return "Operator " + operator + " not supported for option type " + this.type;
try { try {
var newValues = this._op(operator, values, scope, invert);
if (newValues == null)
return "Operator " + operator + " not supported for option type " + this.type;
if (!this.isValidValue(newValues)) if (!this.isValidValue(newValues))
return this.invalidArgument(str || this.stringify(values), operator); return this.invalidArgument(str || this.stringify(values), operator);
} }
@@ -489,9 +489,11 @@ const Option = Class("Option", {
}, },
number: function (operator, values, scope, invert) { number: function (operator, values, scope, invert) {
// TODO: support floats? Validators need updating. if (invert)
if (!/^[+-]?(?:0x[0-9a-f]+|0[0-7]*|[1-9][0-9]*)$/i.test(values)) values = values[(values.indexOf(String(this.value)) + 1) % values.length]
return "E521: Number required after := " + this.name + "=" + values;
dactyl.assert(!isNaN(values) && Number(values) == parseInt(values),
"E521: Number required after := " + this.name + "=" + values);
let value = parseInt(values); let value = parseInt(values);
@@ -561,6 +563,8 @@ const Option = Class("Option", {
get regexpmap() this.stringlist, get regexpmap() this.stringlist,
string: function (operator, values, scope, invert) { string: function (operator, values, scope, invert) {
if (invert)
return values[(values.indexOf(this.value) + 1) % values.length]
switch (operator) { switch (operator) {
case "+": case "+":
return this.value + values; return this.value + values;
@@ -907,10 +911,12 @@ const Options = Module("options", {
} }
// write access // write access
else { else {
if (opt.option.type == "boolean") { if (opt.option.type === "boolean") {
dactyl.assert(!opt.valueGiven, "E474: Invalid argument: " + arg); dactyl.assert(!opt.valueGiven, "E474: Invalid argument: " + arg);
opt.values = !opt.unsetBoolean; opt.values = !opt.unsetBoolean;
} }
else if (/^(string|number)$/.test(opt.option.type) && opt.invert)
opt.values = Option.splitList(opt.value);
try { try {
var res = opt.option.op(opt.operator || "=", opt.values, opt.scope, opt.invert, var res = opt.option.op(opt.operator || "=", opt.values, opt.scope, opt.invert,
opt.value); opt.value);

View File

@@ -404,19 +404,17 @@
</note> </note>
<example> <example>
<p> To enable auto-completion 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|history),.?</str>
<str delim="">!/ex/(bmarks|history),.?</str>
</p>
<p>
To go in the other direction, i.e. <em>only</em> enable
auto-completion for those commands, you have to jump through
some hoops, due to the way contexts work (see the note above):
<str delim="">/ex/(bmarks|history),^(/|/ex/?)$</str>
</p>
</example> </example>
<p>
To go in the other direction, i.e. <em>only</em> enable
auto-completion for those commands, you have to jump through
some hoops, due to the way contexts work (see the note above):
<str delim="">/ex/(bmarks|history),^(/|/ex/?)$</str>
</p>
</description> </description>
</item> </item>

View File

@@ -426,7 +426,7 @@ const Styles = Module("Styles", {
for (let item in Iterator({ Active: true, Inactive: false })) { for (let item in Iterator({ Active: true, Inactive: false })) {
let [name, active] = item; let [name, active] = item;
context.fork(name, 0, null, function (context) { context.fork(name, 0, null, function (context) {
context.title[0] = name + " " + context.title[0]; context.title[0] = name + " Sheets";
context.generate = generate || function () styles.userSheets; context.generate = generate || function () styles.userSheets;
context.filters.push(function (item) item.active == active); context.filters.push(function (item) item.active == active);
}); });