diff --git a/common/content/finder.js b/common/content/finder.js index 802eda5e..91a671da 100644 --- a/common/content/finder.js +++ b/common/content/finder.js @@ -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; } }); diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index d64e1d8a..c519b712 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -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) { diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 4a3a6ff7..acd3a64d 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -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(*) ([-a-z]*) (?: - \s* : \s* ( + * : \s* ( (?: [-\w] (?: @@ -308,14 +329,19 @@ const Styles = Module("Styles", { \s* (?: \) | $) )? \s* - | \s* \s* | [^;}]* + | \s* \s* + | * + | [^;}]* )* ) )? ) - (\s* (?: ; | $) ) + (* (?: ; | $) ) ]]>, "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; } };