mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-05 07:45:51 +01:00
Add crude CSS property completion.
This commit is contained in:
@@ -279,10 +279,11 @@ const CompletionContext = Class("CompletionContext", {
|
||||
delete this.cache.filtered;
|
||||
delete this.cache.filter;
|
||||
this.cache.rows = [];
|
||||
this.hasItems = items.length > 0;
|
||||
this._completions = items;
|
||||
this.itemCache[this.key] = items;
|
||||
}
|
||||
if (this._completions)
|
||||
this.hasItems = this._completions.length > 0;
|
||||
if (this.updateAsync && !this.noUpdate)
|
||||
util.callInMainThread(function () { this.onUpdate(); }, this);
|
||||
},
|
||||
|
||||
@@ -294,6 +294,7 @@ const Highlights = Module("Highlight", {
|
||||
let hl = highlight.get(args[0]);
|
||||
if (hl)
|
||||
context.completions = [[hl.value, "Current Value"], [hl.default || "", "Default Value"]];
|
||||
context.fork("css", 0, modules.completion, "css");
|
||||
}
|
||||
},
|
||||
hereDoc: true,
|
||||
|
||||
@@ -301,6 +301,7 @@ const Styles = Module("Styles", {
|
||||
let sheet = styles.get(false, args["-name"]);
|
||||
if (sheet)
|
||||
context.completions = [[sheet.css, "Current Value"]];
|
||||
context.fork("css", 0, modules.completion, "css");
|
||||
}
|
||||
},
|
||||
hereDoc: true,
|
||||
@@ -378,6 +379,44 @@ const Styles = Module("Styles", {
|
||||
});
|
||||
});
|
||||
},
|
||||
completion: function (dactyl, modules, window) {
|
||||
const names = Array.slice(util.computedStyle(window.document.createElement("div")));
|
||||
const string = /(?:"(?:[^\\"]|\\.)*(?:"|$)|'(?:[^\\']|\\.)*(?:'|$))/.source;
|
||||
const pattern = RegExp(String.replace(<![CDATA[
|
||||
(?:
|
||||
(\s*)
|
||||
([-a-z]*)
|
||||
(?:
|
||||
\s* : \s* (
|
||||
(?:
|
||||
[-\w]
|
||||
(?:
|
||||
\s* \( \s*
|
||||
(?: S | [^)]* )
|
||||
\s* (?: \) | $)
|
||||
)?
|
||||
\s*
|
||||
| \s* S \s* | [^;}]*
|
||||
)*
|
||||
)
|
||||
)?
|
||||
)
|
||||
(\s* (?: ; | $) )
|
||||
]]>, /S/g, string).replace(/\s*/g, ""), "gi");
|
||||
modules.completion.css = function (context) {
|
||||
context.title = ["Property"];
|
||||
context.keys = { text: function (p) p + ":", description: function () "" };
|
||||
|
||||
pattern.lastIndex = 0;
|
||||
let match, lastMatch;
|
||||
while ((!match || match[0]) && (match = pattern.exec(context.filter)) && (match[0].length || !lastMatch))
|
||||
lastMatch = match;
|
||||
if (lastMatch != null && !lastMatch[3] && !lastMatch[4]) {
|
||||
context.advance(lastMatch.index + lastMatch[1].length)
|
||||
context.completions = names;
|
||||
}
|
||||
};
|
||||
},
|
||||
javascript: function (dactyl, modules, window) {
|
||||
modules.JavaScript.setCompleter(["get", "addSheet", "removeSheet", "findSheets"].map(function (m) styles[m]),
|
||||
[ // Prototype: (system, name, filter, css, index)
|
||||
|
||||
Reference in New Issue
Block a user