mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 18:02:27 +01:00
Give :pageinfo an optional argument. Add completion.optionValue.
This commit is contained in:
@@ -490,8 +490,15 @@ function Buffer() //{{{
|
||||
|
||||
commands.add(["pa[geinfo]"],
|
||||
"Show various page information",
|
||||
function () { buffer.showPageInfo(true); },
|
||||
{ argCount: "0" });
|
||||
function (args) { buffer.showPageInfo(true, args[0]); },
|
||||
{
|
||||
argCount: "?",
|
||||
completer: function (context)
|
||||
{
|
||||
context.title = ["Page Info"];
|
||||
completion.optionValue(context, "pageinfo", "+", "");
|
||||
}
|
||||
});
|
||||
|
||||
commands.add(["pagest[yle]"],
|
||||
"Select the author style sheet to apply",
|
||||
@@ -1263,7 +1270,7 @@ function Buffer() //{{{
|
||||
liberator.echo(<>Element:<br/>{util.objectToString(elem, true)}</>, commandline.FORCE_MULTILINE);
|
||||
},
|
||||
|
||||
showPageInfo: function (verbose)
|
||||
showPageInfo: function (verbose, sections)
|
||||
{
|
||||
// Ctrl-g single line output
|
||||
if (!verbose)
|
||||
@@ -1283,7 +1290,7 @@ function Buffer() //{{{
|
||||
return;
|
||||
}
|
||||
|
||||
let option = options["pageinfo"];
|
||||
let option = sections || options["pageinfo"];
|
||||
let list = template.map(option, function (option) {
|
||||
let opt = pageInfo[option];
|
||||
if (opt)
|
||||
|
||||
@@ -1340,6 +1340,53 @@ function Completion() //{{{
|
||||
|
||||
option: function option(filter) commands.get("set").completer(filter), // XXX
|
||||
|
||||
optionValue: function (context, name, op, curValue)
|
||||
{
|
||||
let opt = options.get(name);
|
||||
let completer = opt.completer;
|
||||
|
||||
let curValues = curValue != null ? opt.parseValues(curValue) : opt.values;
|
||||
let newValues = opt.parseValues(context.filter);
|
||||
|
||||
let len = context.filter.length;
|
||||
switch (opt.type)
|
||||
{
|
||||
case "boolean":
|
||||
if (!completer)
|
||||
completer = function () [["true", ""], ["false", ""]];
|
||||
break;
|
||||
case "stringlist":
|
||||
len = newValues.pop().length;
|
||||
break;
|
||||
case "charlist":
|
||||
len = 0;
|
||||
break;
|
||||
}
|
||||
// TODO: Highlight when invalid
|
||||
context.advance(context.filter.length - len);
|
||||
|
||||
/* Not vim compatible, but is a significant enough improvement
|
||||
* that it's worth breaking compatibility.
|
||||
*/
|
||||
let completions = completer(context);
|
||||
if (!completions)
|
||||
return;
|
||||
if (newValues instanceof Array)
|
||||
{
|
||||
completions = completions.filter(function (val) newValues.indexOf(val[0]) == -1);
|
||||
switch (op)
|
||||
{
|
||||
case "+":
|
||||
completions = completions.filter(function (val) curValues.indexOf(val[0]) == -1);
|
||||
break;
|
||||
case "-":
|
||||
completions = completions.filter(function (val) curValues.indexOf(val[0]) > -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
context.completions = completions;
|
||||
},
|
||||
|
||||
preference: function preference(filter) commands.get("set").completer(filter, true), // XXX
|
||||
|
||||
search: function search(context, noSuggest)
|
||||
|
||||
@@ -708,9 +708,9 @@ function Options() //{{{
|
||||
return;
|
||||
|
||||
let [name, value] = filter.split("=", 2);
|
||||
let offset = name.length + 1;
|
||||
let opt = options.parseOpt(filter, modifiers);
|
||||
let option = opt.option;
|
||||
context.advance(name.length + 1);
|
||||
|
||||
if (!option)
|
||||
context.highlight(0, name.length, "SPELLCHECK");
|
||||
@@ -718,56 +718,16 @@ function Options() //{{{
|
||||
if (opt.get || opt.reset || !option || prefix)
|
||||
return;
|
||||
|
||||
let completer = option.completer;
|
||||
|
||||
let len = opt.value.length;
|
||||
|
||||
switch (option.type)
|
||||
{
|
||||
case "boolean":
|
||||
completer = function () [["true", ""], ["false", ""]];
|
||||
break;
|
||||
case "stringlist":
|
||||
len = opt.values.pop().length;
|
||||
break;
|
||||
case "charlist":
|
||||
len = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
context.advance(filter.length - len);
|
||||
filter = context.filter;
|
||||
|
||||
/* Not vim compatible, but is a significant enough improvement
|
||||
* that it's worth breaking compatibility.
|
||||
*/
|
||||
let completions = [];
|
||||
if (!opt.value)
|
||||
completions = [[option.value, "Current value"], [option.defaultValue, "Default value"]].filter(function (f) f[0]);
|
||||
{
|
||||
context.fork("default", 0, this, function (context) {
|
||||
context.title = ["Extra Completions"];
|
||||
context.completions = [[option.value, "Current value"], [option.defaultValue, "Default value"]].filter(function (f) f[0])
|
||||
});
|
||||
}
|
||||
|
||||
context.title = ["Option Value"];
|
||||
if (completer)
|
||||
{
|
||||
let res = completer(context);
|
||||
if (!res)
|
||||
return;
|
||||
completions = completions.concat(res);
|
||||
if (option.values instanceof Array)
|
||||
{
|
||||
completions = completions.filter(function (val) opt.values.indexOf(val[0]) == -1);
|
||||
switch (opt.operator)
|
||||
{
|
||||
case "+":
|
||||
completions = completions.filter(function (val) opt.optionValues.indexOf(val[0]) == -1);
|
||||
break;
|
||||
case "-":
|
||||
completions = completions.filter(function (val) opt.optionValues.indexOf(val[0]) > -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
context.compare = function (a, b) 0;
|
||||
context.completions = completions;
|
||||
completion.optionValue(context, opt.name, opt.operator);
|
||||
},
|
||||
literal: true,
|
||||
serial: function () [
|
||||
|
||||
@@ -48,7 +48,7 @@ const template = {
|
||||
var desc = this.process[1].call(this, item, this.getKey(item, "description"));
|
||||
}
|
||||
|
||||
return <div highlight={class || "CompItem"}>
|
||||
return <div highlight={class || "CompItem"} style="white-space: nowrap">
|
||||
<!-- The non-breaking spaces prevent empty elements
|
||||
- from pushing the baseline down and enlarging
|
||||
- the row.
|
||||
|
||||
Reference in New Issue
Block a user