private function resetContainer(ContextInterface $context, Cursor $cursor)
{
$context->setContainer($context->getDocument());
while ($context->getContainer()->hasChildren()) {
$lastChild = $context->getContainer()->lastChild();
if (!$lastChild->isOpen()) {
break;
}
$context->setContainer($lastChild);
if (!$context->getContainer()->matchesNextLine($cursor)) {
$context->setContainer($context->getContainer()->parent());
// back up to the last matching block
break;
}
}
}