Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/content/cssProperties.js

Issue 29336406: Issue 3654 - Properly split up selectors when applying CSS property filters (Closed)
Patch Set: Created Feb. 15, 2016, 5:17 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/cssProperties.js
===================================================================
--- a/chrome/content/cssProperties.js
+++ b/chrome/content/cssProperties.js
@@ -1,8 +1,45 @@
+function splitSelector(selector)
Sebastian Noack 2016/02/15 17:19:08 This logic has been copied (with some minor change
kzar 2016/02/15 17:30:14 Acknowledged. (Mind filing an issue for that?)
Sebastian Noack 2016/02/15 17:49:31 I attached the patch the same issue: https://coder
+{
+ if (selector.indexOf(",") == -1)
+ return [selector];
+
+ var selectors = [];
+ var start = 0;
+ var level = 0;
+ var sep = "";
+
+ for (var i = 0; i < selector.length; i++)
+ {
+ var chr = selector[i];
+
+ if (chr == "\\") // ignore escaped characters
+ i++;
+ else if (chr == sep) // don't split within quoted text
+ sep = ""; // e.g. [attr=","]
+ else if (sep == "")
+ {
+ if (chr == '"' || chr == "'")
+ sep = chr;
+ else if (chr == "(") // don't split between parentheses
+ level++; // e.g. :matches(div,span)
+ else if (chr == ")")
+ level = Math.max(0, level - 1);
+ else if (chr == "," && level == 0)
+ {
+ selectors.push(selector.substring(start, i));
+ start = i + 1;
+ }
+ }
+ }
+
+ selectors.push(selector.substring(start));
+ return selectors;
+}
+
function CSSPropertyFilters(window, addSelectorsFunc) {
this.window = window;
this.addSelectorsFunc = addSelectorsFunc;
}
-
CSSPropertyFilters.prototype = {
stringifyStyle: function(style)
{
@@ -40,7 +77,11 @@
regexp = pattern.regexp = new RegExp(regexp);
if (regexp.test(style))
- selectors.push(pattern.prefix + rule.selectorText + pattern.suffix);
+ {
+ var subSelectors = splitSelector(rule.selectorText);
+ for (var k = 0; k < subSelectors.length; k++)
+ selectors.push(pattern.prefix + subSelectors[k] + pattern.suffix);
+ }
}
}
},
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld