mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 21:32:25 +01:00
Highlight invalid syntax (sort-of) in javascript completion.
This commit is contained in:
@@ -217,9 +217,13 @@ function Completion() //{{{
|
||||
let pop = function pop(arg)
|
||||
{
|
||||
if (top[CHAR] != arg)
|
||||
{
|
||||
commandline.highlight(top[OFFSET] + 1, i + 1, "SPELLCHECK");
|
||||
commandline.highlight(top[OFFSET], top[OFFSET] + 1, "FIND");
|
||||
throw new Error("Invalid JS");
|
||||
}
|
||||
if (i == str.length - 1)
|
||||
completion.parenMatch = top[OFFSET];
|
||||
commandline.highlight(top[OFFSET], top[OFFSET] + 1, "FIND");
|
||||
// The closing character of this stack frame will have pushed a new
|
||||
// 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.
|
||||
@@ -324,6 +328,9 @@ function Completion() //{{{
|
||||
|
||||
this.complete = function complete(string)
|
||||
{
|
||||
commandline.highlight(0, 0, "SPELLCHECK");
|
||||
commandline.highlight(0, 0, "FIND");
|
||||
|
||||
let self = this;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1164,33 +1164,34 @@ function CommandLine() //{{{
|
||||
}
|
||||
},
|
||||
|
||||
highlight: function (start, end, type)
|
||||
{
|
||||
// FIXME: Kludge.
|
||||
try // Firefox <3.1 doesn't have repaintSelection
|
||||
{
|
||||
const selType = Components.interfaces.nsISelectionController["SELECTION_" + type];
|
||||
let editor = document.getElementById("liberator-commandline-command")
|
||||
.inputField.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
|
||||
let sel = editor.selectionController.getSelection(selType);
|
||||
sel.removeAllRanges();
|
||||
|
||||
let range = editor.selection.getRangeAt(0).cloneRange();
|
||||
let n = this.getCommand().indexOf(" ") + 1;
|
||||
let node = range.startContainer;
|
||||
range.setStart(node, start + n);
|
||||
range.setEnd(node, end + n);
|
||||
sel.addRange(range);
|
||||
editor.selectionController.repaintSelection(selType);
|
||||
}
|
||||
catch (e) {}
|
||||
},
|
||||
|
||||
// to allow asynchronous adding of completions
|
||||
setCompletions: function (compl, start)
|
||||
{
|
||||
if (liberator.mode != modes.COMMAND_LINE)
|
||||
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 (completion.parenMatch != null)
|
||||
{
|
||||
let range = editor.selection.getRangeAt(0).cloneRange();
|
||||
let paren = 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.
|
||||
if (compl.length == 0)
|
||||
return completionList.hide();
|
||||
|
||||
Reference in New Issue
Block a user