1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-04 18:35:47 +01:00

Replace older values with :sty/:hi -append rather than simply concatenating the old string.

This commit is contained in:
Kris Maglione
2010-12-21 20:56:19 -05:00
parent 198a321c59
commit 362981e1b1
3 changed files with 39 additions and 21 deletions

View File

@@ -207,14 +207,7 @@ const RangeFinder = Module("rangefinder", {
"Highlight all /find pattern matches on the current page after submission",
"boolean", false, {
setter: function (value) {
try {
if (value)
rangefinder.highlight();
else
rangefinder.clear();
}
catch (e) {}
rangefinder[value ? "highlight" : "clear"]();
return value;
}
});

View File

@@ -108,7 +108,7 @@ const Highlights = Module("Highlight", {
let highlight = this.highlight[key] || this._create(false, [key]);
if (append)
newStyle = (highlight.value || "").replace(/;?\s*$/, "; " + newStyle);
newStyle = Styles.append(highlight.value || "", newStyle);
if (/^\s*$/.test(newStyle))
newStyle = null;
if (newStyle == null) {

View File

@@ -249,6 +249,17 @@ const Styles = Module("Styles", {
services.stylesheet.unregisterSheet(uri, type);
},
}, {
append: function (dest, src, sort) {
let props = {};
for each (let str in [dest, src])
for (let prop in Styles.propertyIter(str))
props[prop.name] = prop.value;
return Object.keys(props)[sort ? "sort" : "slice"]()
.map(function (prop) prop + ": " + props[prop] + ";")
.join(" ");
},
completeSite: function (context, content) {
context.anchored = false;
try {
@@ -294,12 +305,22 @@ const Styles = Module("Styles", {
return test(arguments[1]);
},
propertyIter: function (str, always) {
this.propertyPattern.lastIndex = 0;
let match;
while ((!match || match[0]) && (match = Styles.propertyPattern.exec(str)))
if (always || match[0])
yield this.Property.fromArray(match);
},
Property: Struct("whole", "preSpace", "name", "value", "postSpace"),
propertyPattern: util.regexp(<![CDATA[
(?:
(\s*)
(<space>*)
([-a-z]*)
(?:
\s* : \s* (
<space>* : \s* (
(?:
[-\w]
(?:
@@ -308,14 +329,19 @@ const Styles = Module("Styles", {
\s* (?: \) | $)
)?
\s*
| \s* <string> \s* | [^;}]*
| \s* <string> \s*
| <space>*
| [^;}]*
)*
)
)?
)
(\s* (?: ; | $) )
(<space>* (?: ; | $) )
]]>, "gi",
{ string: /(?:"(?:[^\\"]|\\.)*(?:"|$)|'(?:[^\\']|\\.)*(?:'|$))/ })
{
space: /(?: \s | \/\* .*? \*\/ )/,
string: /(?:"(?:[^\\"]|\\.)*(?:"|$)|'(?:[^\\']|\\.)*(?:'|$))/
})
}, {
commands: function (dactyl, modules, window) {
const commands = modules.commands;
@@ -347,7 +373,7 @@ const Styles = Module("Styles", {
let sheet = styles.get(false, name);
if (sheet) {
filter = sheet.sites.concat(filter).join(",");
css = sheet.css + " " + css;
css = Styles.append(sheet.css, css);
}
}
styles.addSheet(false, name, filter, css, args["-agent"]);
@@ -480,12 +506,11 @@ const Styles = Module("Styles", {
context.title = ["CSS Property"];
context.keys = { text: function (p) p + ":", description: function () "" };
Styles.propertyPattern.lastIndex = 0;
let match, lastMatch;
while ((!match || match[0]) && (match = Styles.propertyPattern.exec(context.filter)) && (match[0].length || !lastMatch))
lastMatch = match;
if (lastMatch != null && !lastMatch[3] && !lastMatch[4]) {
context.advance(lastMatch.index + lastMatch[1].length)
for (let match in Styles.propertyIter(context.filter, true))
var lastMatch = match;
if (lastMatch != null && !lastMatch.value && !lastMatch.postSpace) {
context.advance(lastMatch.index + lastMatch.name.length)
context.completions = names;
}
};