Skip to content

Commit

Permalink
Implement descendent selector matching
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Nov 28, 2024
1 parent 2e81b2f commit 95dd92b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/wp-includes/html-api/class-wp-css-selectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,19 @@ private function explore_matches( array $selectors, array $breadcrumbs ): bool {
return $this->explore_matches( $selectors, array_slice( $breadcrumbs, 1 ) );

case self::COMBINATOR_DESCENDANT:
$ident = $selector->type_selector->ident;

// Find _all_ the breadcrumbs that match and recurse from each of them.
for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
if ( '*' === $selector->type_selector->ident || strcasecmp( $breadcrumbs[ $i ], $selector->type_selector->ident ) === 0 ) {
$next_crumbs = array_slice( $breadcrumbs, $i + 1 );
if ( $this->explore_matches( array_slice( $selectors, 2 ), $next_crumbs ) ) {
return true;
}
}
}
return false;

default:
throw new Exception( "Combinator '{$combinator}' is not supported yet." );
}
Expand Down

0 comments on commit 95dd92b

Please sign in to comment.