mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-23 22:04:25 +02:00
doc/lib: Fix that highlighting a search messes up the text around the match
refs #6630
This commit is contained in:
parent
54292eed20
commit
195aa581cb
@ -141,16 +141,15 @@ class SectionRenderer extends Renderer
|
|||||||
$matches = $match->getMatches();
|
$matches = $match->getMatches();
|
||||||
ksort($matches);
|
ksort($matches);
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
$parentNode = $node->parentNode;
|
$fragment = $doc->createDocumentFragment();
|
||||||
/** @type \DOMElement $parentNode */
|
|
||||||
$parentNode->removeChild($node);
|
|
||||||
foreach ($matches as $position => $match) {
|
foreach ($matches as $position => $match) {
|
||||||
$parentNode->appendChild($doc->createTextNode(substr($text, $offset, $position - $offset)));
|
$fragment->appendChild($doc->createTextNode(substr($text, $offset, $position - $offset)));
|
||||||
$parentNode->appendChild($doc->createElement('span', $match))
|
$fragment->appendChild($doc->createElement('span', $match))
|
||||||
->setAttribute('class', DocSearchMatch::HIGHLIGHT_CSS_CLASS);
|
->setAttribute('class', DocSearchMatch::HIGHLIGHT_CSS_CLASS);
|
||||||
$offset = $position + strlen($match);
|
$offset = $position + strlen($match);
|
||||||
}
|
}
|
||||||
$parentNode->appendChild($doc->createTextNode(substr($text, $offset)));
|
$fragment->appendChild($doc->createTextNode(substr($text, $offset)));
|
||||||
|
$node->parentNode->replaceChild($fragment, $node);
|
||||||
}
|
}
|
||||||
return $doc->saveHTML();
|
return $doc->saveHTML();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user