1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-27 04:23:31 +01:00

Add :se invfoo=bar,baz to toggle bar and baz in a list option

This commit is contained in:
Kris Maglione
2008-10-10 05:05:13 +00:00
parent ec68f69b4b
commit f7fed1172c
2 changed files with 25 additions and 13 deletions

View File

@@ -431,6 +431,9 @@ liberator.Options = function () //{{{
ret.onlyNonDefault = true; ret.onlyNonDefault = true;
} }
if (matches)
ret.option = liberator.options.get(ret.name, ret.scope);
ret.prefix = prefix; ret.prefix = prefix;
ret.postfix = postfix; ret.postfix = postfix;
@@ -442,9 +445,6 @@ liberator.Options = function () //{{{
ret.scope = modifiers && modifiers.scope; ret.scope = modifiers && modifiers.scope;
if (matches)
ret.option = liberator.options.get(ret.name, ret.scope);
if (!ret.option) if (!ret.option)
return ret; return ret;
@@ -460,8 +460,8 @@ liberator.Options = function () //{{{
ret.valueHas = ret.value.split(","); ret.valueHas = ret.value.split(",");
break; break;
case "charlist": case "charlist":
ret.optionHas = ret.optionValue.split(""); ret.optionHas = Array.slice(ret.optionValue);
ret.valueHas = ret.value.split(""); ret.valueHas = Array.slice(ret.value);
break; break;
} }
@@ -630,9 +630,15 @@ liberator.Options = function () //{{{
break; break;
default: default:
newValue = opt.valueHas; newValue = opt.valueHas;
if (opt.invert)
{
let keepValues = Array.filter(opt.optionHas, function (item) opt.valueHas.indexOf(item) == -1);
let addValues = Array.filter(opt.valueHas, function (item) opt.optionHas.indexOf(item) == -1);
newValue = addValues.concat(keepValues);
}
break; break;
} }
newValue = newValue.join(option.type == "charlist" ? "" : ","); newValue = newValue.filter(function (x) x != "").join(option.type == "charlist" ? "" : ",");
break; break;
@@ -673,10 +679,9 @@ liberator.Options = function () //{{{
completer: function (filter, special, count, modifiers) completer: function (filter, special, count, modifiers)
{ {
var optionCompletions = []; var optionCompletions = [];
var prefix = filter.match(/^no|inv/) || "";
if (prefix) if (prefix)
filter = filter.replace(prefix, ""); filter = filter.replace(ret.prefix, "");
if (special) // list completions for about:config entries if (special) // list completions for about:config entries
{ {
@@ -704,12 +709,14 @@ liberator.Options = function () //{{{
return [0, liberator.completion.filter(optionCompletions, filter)]; return [0, liberator.completion.filter(optionCompletions, filter)];
} }
var scope = liberator.options.OPTION_SCOPE_BOTH; let prefix = filter.match(/^(no|inv)/)[0] || "";
if (modifiers && modifiers.scope) if (prefix)
scope = modifiers.scope; filter = filter.substr(prefix.length);
let scope = modifiers && modifiers.scope || liberator.options.OPTION_SCOPE_BOTH;
let options = (opt for (opt in liberator.options) let options = (opt for (opt in liberator.options)
if ((opt.scope & scope) && (!prefix || opt.type == "boolean"))); if ((opt.scope & scope) && (!prefix || opt.type == "boolean" || prefix == "inv" && /list$/.test(opt.type))));
if (!filter) if (!filter)
{ {
@@ -728,7 +735,7 @@ liberator.Options = function () //{{{
return [0, liberator.completion.filter(optionCompletions, prefix + filter, true)]; return [0, liberator.completion.filter(optionCompletions, prefix + filter, true)];
} }
else if (prefix) else if (prefix == "no")
return; return;
let [name, value] = filter.split("=", 2); let [name, value] = filter.split("=", 2);

View File

@@ -49,6 +49,11 @@ ____
Toggle option: Invert value. Toggle option: Invert value.
____ ____
||:se[t] inv((option))={value}|| +
____
For list options, toggle the specified values.
____
|:set-default| |:set-default|
||:se[t] {option}&|| ||:se[t] {option}&||
____ ____