# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: moodle/lib/outputcomponents.php
--- moodle/lib/outputcomponents.php Base (1.155)
+++ moodle/lib/outputcomponents.php Locally Modified (Based On 1.155)
@@ -2342,9 +2342,13 @@
             if (preg_match('/^(\-*)/', $line, $match) && $lastchild != null && $lastdepth !== null) {
                 $depth = strlen($match[1]);
                 if ($depth < $lastdepth) {
-                    if ($lastdepth > 1) {
-                        $depth = $lastdepth - 1;
-                        $lastchild = $lastchild->get_parent()->get_parent()->add($bits[0], $bits[1], $bits[2], $bits[3]);
+                    $difference = $lastdepth - $depth;
+                    if ($lastdepth > 1 && $lastdepth != $difference) {
+                        $tempchild = $lastchild->get_parent();
+                        for ($i =0; $i < $difference; $i++) {
+                            $tempchild = $tempchild->get_parent();
+                        }
+                        $lastchild = $tempchild->add($bits[0], $bits[1], $bits[2], $bits[3]);
                     } else {
                         $depth = 0;
                         $lastchild = new custom_menu_item($bits[0], $bits[1], $bits[2], $bits[3]);
