mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 09:48:00 +01:00
Fix some args completion bugs. Update where JS completion waits for tab.
This commit is contained in:
@@ -308,7 +308,7 @@ function Bookmarks() //{{{
|
||||
{
|
||||
argCount: "?",
|
||||
bang: true,
|
||||
options: [[["-title", "-t"], commands.OPTION_STRING],
|
||||
options: [[["-title", "-t"], commands.OPTION_STRING, null, function () [[content.document.title, "Current Page Title"]]],
|
||||
[["-tags", "-T"], commands.OPTION_LIST, null, tags],
|
||||
[["-keyword", "-k"], commands.OPTION_STRING, function (arg) /\w/.test(arg)]]
|
||||
});
|
||||
|
||||
@@ -480,8 +480,6 @@ function Commands() //{{{
|
||||
continue;
|
||||
}
|
||||
|
||||
matchOpts(sub);
|
||||
|
||||
var optname = "";
|
||||
if (!onlyArgumentsRemaining)
|
||||
{
|
||||
@@ -530,10 +528,12 @@ function Commands() //{{{
|
||||
let type = argTypes[opt[1]];
|
||||
if (type && (!complete || arg != null))
|
||||
{
|
||||
let orig = arg;
|
||||
arg = type.parse(arg);
|
||||
if (arg == null || (typeof arg == "number" && isNaN(arg)))
|
||||
{
|
||||
echoerr("Invalid argument for " + type.description + " option: " + optname);
|
||||
if (!complete || orig != "" || args.completeStart != str.length)
|
||||
echoerr("Invalid argument for " + type.description + " option: " + optname);
|
||||
if (complete)
|
||||
complete.highlight(args.completeStart, count - 1, "SPELLCHECK");
|
||||
else
|
||||
@@ -566,6 +566,8 @@ function Commands() //{{{
|
||||
}
|
||||
}
|
||||
|
||||
matchOpts(sub);
|
||||
|
||||
if (complete)
|
||||
{
|
||||
if (argCount == "0" || args.length > 0 && (/[1?]/.test(argCount)))
|
||||
|
||||
@@ -499,7 +499,7 @@ function Completion() //{{{
|
||||
{
|
||||
let json = Components.classes["@mozilla.org/dom/json;1"]
|
||||
.createInstance(Components.interfaces.nsIJSON);
|
||||
const OFFSET = 0, CHAR = 1, STATEMENTS = 2, DOTS = 3, FULL_STATEMENTS = 4, FUNCTIONS = 5;
|
||||
const OFFSET = 0, CHAR = 1, STATEMENTS = 2, DOTS = 3, FULL_STATEMENTS = 4, COMMA = 5, FUNCTIONS = 6;
|
||||
let stack = [];
|
||||
let functions = [];
|
||||
let top = []; /* The element on the top of the stack. */
|
||||
@@ -634,7 +634,7 @@ function Completion() //{{{
|
||||
/* Push and pop the stack, maintaining references to 'top' and 'last'. */
|
||||
let push = function push(arg)
|
||||
{
|
||||
top = [i, arg, [i], [], [], []];
|
||||
top = [i, arg, [i], [], [], [], []];
|
||||
last = top[CHAR];
|
||||
stack.push(top);
|
||||
}
|
||||
@@ -734,8 +734,9 @@ function Completion() //{{{
|
||||
case "]": pop("["); break;
|
||||
case "}": pop("{"); /* Fallthrough */
|
||||
case ";":
|
||||
case ",":
|
||||
top[FULL_STATEMENTS].push(i);
|
||||
case ",":
|
||||
top[COMMA];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -788,6 +789,7 @@ function Completion() //{{{
|
||||
prev = v + 1;
|
||||
}
|
||||
|
||||
// Don't eval any function calls unless the user presses tab.
|
||||
function checkFunction(start, end, key)
|
||||
{
|
||||
let res = functions.some(function (idx) idx >= start && idx < end);
|
||||
@@ -981,7 +983,7 @@ function Completion() //{{{
|
||||
// Split up the arguments
|
||||
let prev = get(-2)[OFFSET];
|
||||
let args = [];
|
||||
for (let [i, idx] in Iterator(get(-2)[FULL_STATEMENTS]))
|
||||
for (let [i, idx] in Iterator(get(-2)[COMMA]))
|
||||
{
|
||||
let arg = str.substring(prev + 1, idx);
|
||||
prev = idx;
|
||||
@@ -1006,13 +1008,6 @@ function Completion() //{{{
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for a keypress.
|
||||
if (!this.context.tabPressed && /[{([\])}"';]/.test(str[lastIdx - 1]) && last != '"' && last != '"')
|
||||
{
|
||||
this.context.waitingForTab = true;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* str = "foo.bar.baz"
|
||||
* obj = "foo.bar"
|
||||
@@ -1025,6 +1020,14 @@ function Completion() //{{{
|
||||
|
||||
let [offset, obj, key] = getObjKey(-1);
|
||||
|
||||
// Wait for a keypress before completing the default objects.
|
||||
if (!this.context.tabPressed && key == "" && obj.length == 2)
|
||||
{
|
||||
this.context.waitingForTab = true;
|
||||
this.context.message = "Waiting for key press";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^(?:\w[\w\d]*)?$/.test(key))
|
||||
return; /* Not a word. Forget it. Can this even happen? */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user