Skip to content

Commit 95dd92b

Browse files
committed
Implement descendent selector matching
1 parent 2e81b2f commit 95dd92b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/wp-includes/html-api/class-wp-css-selectors.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,19 @@ private function explore_matches( array $selectors, array $breadcrumbs ): bool {
10711071
return $this->explore_matches( $selectors, array_slice( $breadcrumbs, 1 ) );
10721072

10731073
case self::COMBINATOR_DESCENDANT:
1074+
$ident = $selector->type_selector->ident;
1075+
1076+
// Find _all_ the breadcrumbs that match and recurse from each of them.
1077+
for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
1078+
if ( '*' === $selector->type_selector->ident || strcasecmp( $breadcrumbs[ $i ], $selector->type_selector->ident ) === 0 ) {
1079+
$next_crumbs = array_slice( $breadcrumbs, $i + 1 );
1080+
if ( $this->explore_matches( array_slice( $selectors, 2 ), $next_crumbs ) ) {
1081+
return true;
1082+
}
1083+
}
1084+
}
1085+
return false;
1086+
10741087
default:
10751088
throw new Exception( "Combinator '{$combinator}' is not supported yet." );
10761089
}

0 commit comments

Comments
 (0)