Fix placeholder headings causing exceptions in getTranscludedFrom()

Follow-up to 8de940b587.

Change-Id: Iddf045105fac6ab8cdaa933fd2abcf6dbbd37d42
This commit is contained in:
Bartosz Dziewoński 2022-01-11 22:58:57 +01:00
parent 272b6595f5
commit 8b426c7e5c
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();
}
}