mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 21:02:25 +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: "?",
|
argCount: "?",
|
||||||
bang: true,
|
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],
|
[["-tags", "-T"], commands.OPTION_LIST, null, tags],
|
||||||
[["-keyword", "-k"], commands.OPTION_STRING, function (arg) /\w/.test(arg)]]
|
[["-keyword", "-k"], commands.OPTION_STRING, function (arg) /\w/.test(arg)]]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -480,8 +480,6 @@ function Commands() //{{{
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
matchOpts(sub);
|
|
||||||
|
|
||||||
var optname = "";
|
var optname = "";
|
||||||
if (!onlyArgumentsRemaining)
|
if (!onlyArgumentsRemaining)
|
||||||
{
|
{
|
||||||
@@ -530,9 +528,11 @@ function Commands() //{{{
|
|||||||
let type = argTypes[opt[1]];
|
let type = argTypes[opt[1]];
|
||||||
if (type && (!complete || arg != null))
|
if (type && (!complete || arg != null))
|
||||||
{
|
{
|
||||||
|
let orig = arg;
|
||||||
arg = type.parse(arg);
|
arg = type.parse(arg);
|
||||||
if (arg == null || (typeof arg == "number" && isNaN(arg)))
|
if (arg == null || (typeof arg == "number" && isNaN(arg)))
|
||||||
{
|
{
|
||||||
|
if (!complete || orig != "" || args.completeStart != str.length)
|
||||||
echoerr("Invalid argument for " + type.description + " option: " + optname);
|
echoerr("Invalid argument for " + type.description + " option: " + optname);
|
||||||
if (complete)
|
if (complete)
|
||||||
complete.highlight(args.completeStart, count - 1, "SPELLCHECK");
|
complete.highlight(args.completeStart, count - 1, "SPELLCHECK");
|
||||||
@@ -566,6 +566,8 @@ function Commands() //{{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matchOpts(sub);
|
||||||
|
|
||||||
if (complete)
|
if (complete)
|
||||||
{
|
{
|
||||||
if (argCount == "0" || args.length > 0 && (/[1?]/.test(argCount)))
|
if (argCount == "0" || args.length > 0 && (/[1?]/.test(argCount)))
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ function Completion() //{{{
|
|||||||
{
|
{
|
||||||
let json = Components.classes["@mozilla.org/dom/json;1"]
|
let json = Components.classes["@mozilla.org/dom/json;1"]
|
||||||
.createInstance(Components.interfaces.nsIJSON);
|
.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 stack = [];
|
||||||
let functions = [];
|
let functions = [];
|
||||||
let top = []; /* The element on the top of the stack. */
|
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'. */
|
/* Push and pop the stack, maintaining references to 'top' and 'last'. */
|
||||||
let push = function push(arg)
|
let push = function push(arg)
|
||||||
{
|
{
|
||||||
top = [i, arg, [i], [], [], []];
|
top = [i, arg, [i], [], [], [], []];
|
||||||
last = top[CHAR];
|
last = top[CHAR];
|
||||||
stack.push(top);
|
stack.push(top);
|
||||||
}
|
}
|
||||||
@@ -734,8 +734,9 @@ function Completion() //{{{
|
|||||||
case "]": pop("["); break;
|
case "]": pop("["); break;
|
||||||
case "}": pop("{"); /* Fallthrough */
|
case "}": pop("{"); /* Fallthrough */
|
||||||
case ";":
|
case ";":
|
||||||
case ",":
|
|
||||||
top[FULL_STATEMENTS].push(i);
|
top[FULL_STATEMENTS].push(i);
|
||||||
|
case ",":
|
||||||
|
top[COMMA];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -788,6 +789,7 @@ function Completion() //{{{
|
|||||||
prev = v + 1;
|
prev = v + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't eval any function calls unless the user presses tab.
|
||||||
function checkFunction(start, end, key)
|
function checkFunction(start, end, key)
|
||||||
{
|
{
|
||||||
let res = functions.some(function (idx) idx >= start && idx < end);
|
let res = functions.some(function (idx) idx >= start && idx < end);
|
||||||
@@ -981,7 +983,7 @@ function Completion() //{{{
|
|||||||
// Split up the arguments
|
// Split up the arguments
|
||||||
let prev = get(-2)[OFFSET];
|
let prev = get(-2)[OFFSET];
|
||||||
let args = [];
|
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);
|
let arg = str.substring(prev + 1, idx);
|
||||||
prev = idx;
|
prev = idx;
|
||||||
@@ -1006,13 +1008,6 @@ function Completion() //{{{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for a keypress.
|
|
||||||
if (!this.context.tabPressed && /[{([\])}"';]/.test(str[lastIdx - 1]) && last != '"' && last != '"')
|
|
||||||
{
|
|
||||||
this.context.waitingForTab = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* str = "foo.bar.baz"
|
* str = "foo.bar.baz"
|
||||||
* obj = "foo.bar"
|
* obj = "foo.bar"
|
||||||
@@ -1025,6 +1020,14 @@ function Completion() //{{{
|
|||||||
|
|
||||||
let [offset, obj, key] = getObjKey(-1);
|
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))
|
if (!/^(?:\w[\w\d]*)?$/.test(key))
|
||||||
return; /* Not a word. Forget it. Can this even happen? */
|
return; /* Not a word. Forget it. Can this even happen? */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user