mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 10:07:59 +01:00
Toggle between values in a list for string/number options with invert.
This commit is contained in:
@@ -342,7 +342,7 @@ lookup:
|
||||
this.withSavedValues(["sourcing"], function () {
|
||||
this.sourcing = null;
|
||||
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 (!silent)
|
||||
|
||||
@@ -223,11 +223,11 @@ const Option = Class("Option", {
|
||||
*/
|
||||
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 {
|
||||
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))
|
||||
return this.invalidArgument(str || this.stringify(values), operator);
|
||||
}
|
||||
@@ -489,9 +489,11 @@ const Option = Class("Option", {
|
||||
},
|
||||
|
||||
number: function (operator, values, scope, invert) {
|
||||
// TODO: support floats? Validators need updating.
|
||||
if (!/^[+-]?(?:0x[0-9a-f]+|0[0-7]*|[1-9][0-9]*)$/i.test(values))
|
||||
return "E521: Number required after := " + this.name + "=" + values;
|
||||
if (invert)
|
||||
values = values[(values.indexOf(String(this.value)) + 1) % values.length]
|
||||
|
||||
dactyl.assert(!isNaN(values) && Number(values) == parseInt(values),
|
||||
"E521: Number required after := " + this.name + "=" + values);
|
||||
|
||||
let value = parseInt(values);
|
||||
|
||||
@@ -561,6 +563,8 @@ const Option = Class("Option", {
|
||||
get regexpmap() this.stringlist,
|
||||
|
||||
string: function (operator, values, scope, invert) {
|
||||
if (invert)
|
||||
return values[(values.indexOf(this.value) + 1) % values.length]
|
||||
switch (operator) {
|
||||
case "+":
|
||||
return this.value + values;
|
||||
@@ -907,10 +911,12 @@ const Options = Module("options", {
|
||||
}
|
||||
// write access
|
||||
else {
|
||||
if (opt.option.type == "boolean") {
|
||||
if (opt.option.type === "boolean") {
|
||||
dactyl.assert(!opt.valueGiven, "E474: Invalid argument: " + arg);
|
||||
opt.values = !opt.unsetBoolean;
|
||||
}
|
||||
else if (/^(string|number)$/.test(opt.option.type) && opt.invert)
|
||||
opt.values = Option.splitList(opt.value);
|
||||
try {
|
||||
var res = opt.option.op(opt.operator || "=", opt.values, opt.scope, opt.invert,
|
||||
opt.value);
|
||||
|
||||
@@ -404,19 +404,17 @@
|
||||
</note>
|
||||
|
||||
<example>
|
||||
<p>
|
||||
To enable auto-completion for everything but <ex>:history</ex> or
|
||||
<ex>:bmarks</ex>, you would choose a value such as
|
||||
<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>
|
||||
To enable auto-completion for everything but <ex>:history</ex> or
|
||||
<ex>:bmarks</ex>, you would choose a value such as
|
||||
<str delim="">!/ex/(bmarks|history),.?</str>
|
||||
</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>
|
||||
</item>
|
||||
|
||||
|
||||
@@ -426,7 +426,7 @@ const Styles = Module("Styles", {
|
||||
for (let item in Iterator({ Active: true, Inactive: false })) {
|
||||
let [name, active] = item;
|
||||
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.filters.push(function (item) item.active == active);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user