Fix nested selector ordering.

This commit is contained in:
Natalie Weizenbaum 2016-09-24 05:40:01 -07:00 committed by Natalie Weizenbaum
parent 79630cdc47
commit 98c5ffae9a
2 changed files with 20 additions and 5 deletions

View File

@ -69,14 +69,15 @@ class SelectorList extends Selector {
}
if (!_containsParentSelector) {
return new SelectorList(components.expand((complex) {
return parent.components.map((newComplex) => new ComplexSelector(
newComplex.components.toList()..addAll(complex.components)));
return new SelectorList(parent.components.expand((parentComplex) {
return components.map((childComplex) => new ComplexSelector(
parentComplex.components.toList()
..addAll(childComplex.components)));
}));
}
// TODO: handle line breaks
return new SelectorList(components.expand((complex) {
return new SelectorList(flattenVertically(components.map((complex) {
var newComplexes = [<ComplexSelectorComponent>[]];
for (var component in complex.components) {
if (component is CompoundSelector) {
@ -99,7 +100,7 @@ class SelectorList extends Selector {
}
}
return newComplexes.map((newComplex) => new ComplexSelector(newComplex));
}));
})));
}
Iterable<Iterable<ComplexSelectorComponent>> _resolveParentSelectorsCompound(

View File

@ -37,6 +37,20 @@ String pluralize(String name, int number, {String plural}) {
return '${name}s';
}
List/*<T>*/ flattenVertically/*<T>*/(Iterable<Iterable/*<T>*/ > iterable) {
var queues = iterable.map((inner) => new QueueList.from(inner)).toList();
if (queues.length == 1) return queues.first;
var result = /*<T>*/ [];
while (queues.isNotEmpty) {
queues.removeWhere((queue) {
result.add(queue.removeFirst());
return queue.isEmpty;
});
}
return result;
}
int codepointIndexToCodeUnitIndex(String string, int codepointIndex) {
var codeUnitIndex = 0;
for (var i = 0; i < codepointIndex; i++) {