mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 09:17:59 +01:00
Add rudimentary paren/brace/quote matching for JS
This commit is contained in:
@@ -225,6 +225,8 @@ liberator.Completion = function () //{{{
|
|||||||
{
|
{
|
||||||
if (top[CHAR] != arg)
|
if (top[CHAR] != arg)
|
||||||
throw new Error("Invalid JS");
|
throw new Error("Invalid JS");
|
||||||
|
if (i == str.length - 1)
|
||||||
|
liberator.completion.parenMatch = top[OFFSET];
|
||||||
// The closing character of this stack frame will have pushed a new
|
// The closing character of this stack frame will have pushed a new
|
||||||
// statement, leaving us with an empty statement. This doesn't matter,
|
// statement, leaving us with an empty statement. This doesn't matter,
|
||||||
// now, as we simply throw away the frame when we pop it, but it may later.
|
// now, as we simply throw away the frame when we pop it, but it may later.
|
||||||
@@ -798,6 +800,8 @@ liberator.Completion = function () //{{{
|
|||||||
// provides completions for ex commands, including their arguments
|
// provides completions for ex commands, including their arguments
|
||||||
ex: function (str)
|
ex: function (str)
|
||||||
{
|
{
|
||||||
|
this.filterString = "";
|
||||||
|
this.parenMatch = null;
|
||||||
substrings = [];
|
substrings = [];
|
||||||
if (str.indexOf(cacheFilter["ex"]) != 0)
|
if (str.indexOf(cacheFilter["ex"]) != 0)
|
||||||
{
|
{
|
||||||
@@ -935,7 +939,7 @@ liberator.Completion = function () //{{{
|
|||||||
if (h[0].indexOf(begin) == 0 && (!end.length || h[0].substr(-end.length) == end))
|
if (h[0].indexOf(begin) == 0 && (!end.length || h[0].substr(-end.length) == end))
|
||||||
{
|
{
|
||||||
let query = h[0].substring(begin.length, h[0].length - end.length);
|
let query = h[0].substring(begin.length, h[0].length - end.length);
|
||||||
searches.push([decodeURIComponent(query),
|
searches.push([decodeURIComponent(query.replace("+", "%20")),
|
||||||
<>{begin}<span class="hl-Filter">{query}</span>{end}</>,
|
<>{begin}<span class="hl-Filter">{query}</span>{end}</>,
|
||||||
k[2]]);
|
k[2]]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1150,13 +1150,33 @@ liberator.CommandLine = function () //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// to allow asynchronous adding of completions, broken
|
// to allow asynchronous adding of completions
|
||||||
// since the completion -> ItemList rewrite
|
|
||||||
setCompletions: function (compl, start)
|
setCompletions: function (compl, start)
|
||||||
{
|
{
|
||||||
if (liberator.mode != liberator.modes.COMMAND_LINE)
|
if (liberator.mode != liberator.modes.COMMAND_LINE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// FIXME: Kludge.
|
||||||
|
try // Firefox <3.1 doesn't have repaintSelection
|
||||||
|
{
|
||||||
|
const SEL_TYPE = Components.interfaces.nsISelectionController.SELECTION_FIND;
|
||||||
|
let editor = document.getElementById("liberator-commandline-command")
|
||||||
|
.inputField.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
|
||||||
|
let sel = editor.selectionController.getSelection(SEL_TYPE);
|
||||||
|
sel.removeAllRanges();
|
||||||
|
if (liberator.completion.parenMatch != null)
|
||||||
|
{
|
||||||
|
let range = editor.selection.getRangeAt(0).cloneRange();
|
||||||
|
let paren = liberator.completion.parenMatch + this.getCommand().indexOf(" ") + 1;
|
||||||
|
let node = range.startContainer;
|
||||||
|
range.setStart(node, paren);
|
||||||
|
range.setEnd(node, paren + 1);
|
||||||
|
sel.addRange(range);
|
||||||
|
editor.selectionController.repaintSelection(SEL_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
|
||||||
/* Only hide if not pending.
|
/* Only hide if not pending.
|
||||||
if (compl.length == 0)
|
if (compl.length == 0)
|
||||||
return completionList.hide();
|
return completionList.hide();
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ liberator.util = { //{{{
|
|||||||
obj = <span class="hl-Title hl-Object">{obj}</span>.toXMLString();
|
obj = <span class="hl-Title hl-Object">{obj}</span>.toXMLString();
|
||||||
string += obj + "::\n";
|
string += obj + "::\n";
|
||||||
|
|
||||||
|
let keys = [];
|
||||||
try // window.content often does not want to be queried with "var i in object"
|
try // window.content often does not want to be queried with "var i in object"
|
||||||
{
|
{
|
||||||
for (let i in object)
|
for (let i in object)
|
||||||
@@ -273,12 +274,12 @@ liberator.util = { //{{{
|
|||||||
value = value.toXMLString();
|
value = value.toXMLString();
|
||||||
i = <span style="font-weight: bold;">{i}</span>.toXMLString();
|
i = <span style="font-weight: bold;">{i}</span>.toXMLString();
|
||||||
}
|
}
|
||||||
string += i + ": " + value + "\n";
|
keys.push(i + ": " + value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
|
|
||||||
return string;
|
return string + keys.sort().join("\n") + "\n";
|
||||||
},
|
},
|
||||||
|
|
||||||
range: function (start, end)
|
range: function (start, end)
|
||||||
|
|||||||
Reference in New Issue
Block a user