Merge "Fix placeholder headings causing exceptions in getTranscludedFrom()"

This commit is contained in:
jenkins-bot 2022-01-12 17:18:55 +00:00 committed by Gerrit Code Review
commit f189c985da
2 changed files with 15 additions and 2 deletions

View file

@ -518,10 +518,11 @@ class CommentUtils {
}
/**
* @param ImmutableRange $range
* @param ImmutableRange $range (must not be collapsed)
* @return Node
*/
public static function getRangeFirstNode( ImmutableRange $range ): Node {
Assert::precondition( !$range->collapsed, 'Range is not collapsed' );
// PHP bug: childNodes can be null
return $range->startContainer->childNodes && $range->startContainer->childNodes->length ?
$range->startContainer->childNodes[ $range->startOffset ] :
@ -529,10 +530,11 @@ class CommentUtils {
}
/**
* @param ImmutableRange $range
* @param ImmutableRange $range (must not be collapsed)
* @return Node
*/
public static function getRangeLastNode( ImmutableRange $range ): Node {
Assert::precondition( !$range->collapsed, 'Range is not collapsed' );
// PHP bug: childNodes can be null
return $range->endContainer->childNodes && $range->endContainer->childNodes->length ?
$range->endContainer->childNodes[ $range->endOffset - 1 ] :

View file

@ -97,4 +97,15 @@ class HeadingItem extends ThreadItem {
$this->getName() !== 'h-'
);
}
/**
* @inheritDoc
*/
public function getTranscludedFrom() {
// Placeholder headings break the usual logic, because their ranges are collapsed
if ( $this->isPlaceholderHeading() ) {
return false;
}
return parent::getTranscludedFrom();
}
}