mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 18:02:27 +01:00
Cleanup. Add 1px border to top of completion body for when MOW is also shown.
This commit is contained in:
@@ -434,60 +434,6 @@ function Options() //{{{
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// FIXME: Integrate with setter
|
|
||||||
function parseOpt(args, modifiers)
|
|
||||||
{
|
|
||||||
let ret = {};
|
|
||||||
let matches, prefix, postfix, valueGiven;
|
|
||||||
|
|
||||||
[matches, prefix, ret.name, postfix, valueGiven, ret.operator, ret.value] =
|
|
||||||
args.match(/^\s*(no|inv)?([a-z_]+)([?&!])?\s*(([-+^]?)=(.*))?\s*$/) || [];
|
|
||||||
|
|
||||||
ret.args = args;
|
|
||||||
ret.onlyNonDefault = false; // used for :set to print non-default options
|
|
||||||
if (!args)
|
|
||||||
{
|
|
||||||
ret.name = "all";
|
|
||||||
ret.onlyNonDefault = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matches)
|
|
||||||
ret.option = options.get(ret.name, ret.scope);
|
|
||||||
|
|
||||||
ret.prefix = prefix;
|
|
||||||
ret.postfix = postfix;
|
|
||||||
|
|
||||||
ret.all = (ret.name == "all");
|
|
||||||
ret.get = (ret.all || postfix == "?" || (ret.option && ret.option.type != "boolean" && !valueGiven));
|
|
||||||
ret.invert = (prefix == "inv" || postfix == "!");
|
|
||||||
ret.reset = (postfix == "&");
|
|
||||||
ret.unsetBoolean = (prefix == "no");
|
|
||||||
|
|
||||||
ret.scope = modifiers && modifiers.scope;
|
|
||||||
|
|
||||||
if (!ret.option)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (ret.value === undefined)
|
|
||||||
ret.value = "";
|
|
||||||
|
|
||||||
ret.optionValue = ret.option.get(ret.scope);
|
|
||||||
|
|
||||||
switch (ret.option.type)
|
|
||||||
{
|
|
||||||
case "stringlist":
|
|
||||||
ret.optionHas = ret.optionValue.split(",");
|
|
||||||
ret.valueHas = ret.value.split(",");
|
|
||||||
break;
|
|
||||||
case "charlist":
|
|
||||||
ret.optionHas = Array.slice(ret.optionValue);
|
|
||||||
ret.valueHas = Array.slice(ret.value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: support setting multiple options at once
|
// TODO: support setting multiple options at once
|
||||||
commands.add(["se[t]"],
|
commands.add(["se[t]"],
|
||||||
"Set an option",
|
"Set an option",
|
||||||
@@ -543,7 +489,7 @@ function Options() //{{{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let opt = parseOpt(args, modifiers);
|
let opt = options.parseOpt(args, modifiers);
|
||||||
if (!opt)
|
if (!opt)
|
||||||
{
|
{
|
||||||
liberator.echoerr("Error parsing :set command: " + args);
|
liberator.echoerr("Error parsing :set command: " + args);
|
||||||
@@ -641,21 +587,21 @@ function Options() //{{{
|
|||||||
switch (opt.operator)
|
switch (opt.operator)
|
||||||
{
|
{
|
||||||
case "+":
|
case "+":
|
||||||
newValue = util.Array.uniq(Array.concat(opt.optionHas, opt.valueHas), true);
|
newValue = util.Array.uniq(Array.concat(opt.optionValues, opt.values), true);
|
||||||
break;
|
break;
|
||||||
case "^":
|
case "^":
|
||||||
// NOTE: Vim doesn't prepend if there's a match in the current value
|
// NOTE: Vim doesn't prepend if there's a match in the current value
|
||||||
newValue = util.Array.uniq(Array.concat(opt.valueHas, opt.optionHas), true);
|
newValue = util.Array.uniq(Array.concat(opt.values, opt.optionValues), true);
|
||||||
break;
|
break;
|
||||||
case "-":
|
case "-":
|
||||||
newValue = opt.optionHas.filter(function (item) opt.valueHas.indexOf(item) == -1);
|
newValue = opt.optionValues.filter(function (item) opt.values.indexOf(item) == -1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
newValue = opt.valueHas;
|
newValue = opt.values;
|
||||||
if (opt.invert)
|
if (opt.invert)
|
||||||
{
|
{
|
||||||
let keepValues = opt.optionHas.filter(function (item) opt.valueHas.indexOf(item) == -1);
|
let keepValues = opt.optionValues.filter(function (item) opt.values.indexOf(item) == -1);
|
||||||
let addValues = opt.valueHas .filter(function (item) opt.optionHas.indexOf(item) == -1);
|
let addValues = opt.values .filter(function (item) opt.optionValues.indexOf(item) == -1);
|
||||||
newValue = addValues.concat(keepValues);
|
newValue = addValues.concat(keepValues);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -746,7 +692,7 @@ function Options() //{{{
|
|||||||
|
|
||||||
let [name, value] = filter.split("=", 2);
|
let [name, value] = filter.split("=", 2);
|
||||||
let offset = name.length + 1;
|
let offset = name.length + 1;
|
||||||
let opt = parseOpt(filter, modifiers);
|
let opt = options.parseOpt(filter, modifiers);
|
||||||
let option = opt.option;
|
let option = opt.option;
|
||||||
|
|
||||||
if (!option)
|
if (!option)
|
||||||
@@ -765,7 +711,7 @@ function Options() //{{{
|
|||||||
completer = function () [["true", ""], ["false", ""]];
|
completer = function () [["true", ""], ["false", ""]];
|
||||||
break;
|
break;
|
||||||
case "stringlist":
|
case "stringlist":
|
||||||
len = opt.valueHas.pop().length;
|
len = opt.values.pop().length;
|
||||||
break;
|
break;
|
||||||
case "charlist":
|
case "charlist":
|
||||||
len = 0;
|
len = 0;
|
||||||
@@ -785,16 +731,16 @@ function Options() //{{{
|
|||||||
if (completer)
|
if (completer)
|
||||||
{
|
{
|
||||||
completions = completions.concat(completer(filter));
|
completions = completions.concat(completer(filter));
|
||||||
if (opt.optionHas)
|
if (opt.optionValues)
|
||||||
{
|
{
|
||||||
completions = completions.filter(function (val) opt.valueHas.indexOf(val[0]) == -1);
|
completions = completions.filter(function (val) opt.values.indexOf(val[0]) == -1);
|
||||||
switch (opt.operator)
|
switch (opt.operator)
|
||||||
{
|
{
|
||||||
case "+":
|
case "+":
|
||||||
completions = completions.filter(function (val) opt.optionHas.indexOf(val[0]) == -1);
|
completions = completions.filter(function (val) opt.optionValues.indexOf(val[0]) == -1);
|
||||||
break;
|
break;
|
||||||
case "-":
|
case "-":
|
||||||
completions = completions.filter(function (val) opt.optionHas.indexOf(val[0]) > -1);
|
completions = completions.filter(function (val) opt.optionValues.indexOf(val[0]) > -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -983,6 +929,58 @@ function Options() //{{{
|
|||||||
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
parseOpt: function parseOpt(args, modifiers)
|
||||||
|
{
|
||||||
|
let ret = {};
|
||||||
|
let matches, prefix, postfix, valueGiven;
|
||||||
|
|
||||||
|
[matches, prefix, ret.name, postfix, valueGiven, ret.operator, ret.value] =
|
||||||
|
args.match(/^\s*(no|inv)?([a-z_]+)([?&!])?\s*(([-+^]?)=(.*))?\s*$/) || [];
|
||||||
|
|
||||||
|
ret.args = args;
|
||||||
|
ret.onlyNonDefault = false; // used for :set to print non-default options
|
||||||
|
if (!args)
|
||||||
|
{
|
||||||
|
ret.name = "all";
|
||||||
|
ret.onlyNonDefault = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matches)
|
||||||
|
ret.option = options.get(ret.name, ret.scope);
|
||||||
|
|
||||||
|
ret.prefix = prefix;
|
||||||
|
ret.postfix = postfix;
|
||||||
|
|
||||||
|
ret.all = (ret.name == "all");
|
||||||
|
ret.get = (ret.all || postfix == "?" || (ret.option && ret.option.type != "boolean" && !valueGiven));
|
||||||
|
ret.invert = (prefix == "inv" || postfix == "!");
|
||||||
|
ret.reset = (postfix == "&");
|
||||||
|
ret.unsetBoolean = (prefix == "no");
|
||||||
|
|
||||||
|
ret.scope = modifiers && modifiers.scope;
|
||||||
|
|
||||||
|
if (!ret.option)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (ret.value === undefined)
|
||||||
|
ret.value = "";
|
||||||
|
|
||||||
|
ret.optionValue = ret.option.get(ret.scope);
|
||||||
|
ret.optionValues = ret.option.getValues(ret.scope);
|
||||||
|
|
||||||
|
switch (ret.option.type)
|
||||||
|
{
|
||||||
|
case "stringlist":
|
||||||
|
ret.values = ret.value.split(",");
|
||||||
|
break;
|
||||||
|
case "charlist":
|
||||||
|
ret.values = Array.slice(ret.value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
|
||||||
get store() storage.options,
|
get store() storage.options,
|
||||||
|
|
||||||
getPref: function (name, forcedDefault)
|
getPref: function (name, forcedDefault)
|
||||||
|
|||||||
@@ -1289,6 +1289,7 @@ function ItemList(id) //{{{
|
|||||||
|
|
||||||
doc.body.id = id + "-content";
|
doc.body.id = id + "-content";
|
||||||
doc.body.appendChild(doc.createTextNode(""));
|
doc.body.appendChild(doc.createTextNode(""));
|
||||||
|
doc.body.style.borderTop = "1px solid black"; // FIXME: For cases where completions/MOW are shown at once. Should use :highlight.
|
||||||
|
|
||||||
var items = null;
|
var items = null;
|
||||||
var startIndex = -1; // The index of the first displayed item
|
var startIndex = -1; // The index of the first displayed item
|
||||||
@@ -1381,11 +1382,11 @@ function ItemList(id) //{{{
|
|||||||
d.appendChild(row);
|
d.appendChild(row);
|
||||||
dom.replaceChild(d, nodes.items);
|
dom.replaceChild(d, nodes.items);
|
||||||
nodes.items = d;
|
nodes.items = d;
|
||||||
nodes.up.style.display = (start == 0) ? "none" : "block";
|
nodes.up.style.display = (start == 0) && "none";
|
||||||
nodes.down.style.display = (end == context.items.length) ? "none" : "block";
|
nodes.down.style.display = (end == context.items.length) && "none";
|
||||||
});
|
});
|
||||||
|
|
||||||
divNodes.noCompletions.style.display = (off > 0) ? "none" : "block";
|
divNodes.noCompletions.style.display = (off > 0) && "none";
|
||||||
|
|
||||||
completionElements = div.getElementsByClassName("hl-CompItem");
|
completionElements = div.getElementsByClassName("hl-CompItem");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user