matchesPath method

  1. @override
bool matchesPath(
  1. List<Element> elem
)
override

Implementation

@override
bool matchesPath(List<Element> elem) {
  // first, make sure the final path element matches, we don't want
  // extra stuff below the last selector.
  final lastSelector = pathSelectors.last;
  final lastPath = elem.last;

  if(!lastSelector.matches(lastPath)) {
    return false;
  }

  // if the last matches, then go up the path making sure that we can
  // find all the other path selectors.
  var curPath = elem.length - 2;
  var curSel = pathSelectors.length - 2;
  while(curSel >= 0 && curPath >= 0) {
    final sel   = pathSelectors[curSel];
    final item  = elem[curPath];
    if(sel.matches(item)) {
      if(curSel == 0) {
        return true;
      }
      curSel--;
    }
    curPath--;
  }

  return false;
}