@@ -235,16 +235,28 @@ public function isChild($id)
235235 */
236236 public function replaceChild ($ childId , AbstractNode $ newChild )
237237 {
238- $ oldChild = $ this ->getChild ($ childId );
239- $ keys = array_keys ($ this ->children );
240- $ index = array_search ($ childId , $ keys , true );
241- $ keys [$ index ] = $ newChild ->id ();
242- $ this ->children = array_combine ($ keys , $ this ->children );
243- $ this ->children [$ newChild ->id ()] = $ newChild ;
244- unset($ oldChild );
245-
246- //clear any cache
247- $ this ->clear ();
238+ $ oldChild = $ this ->children [$ childId ];
239+
240+ $ newChild ->prev = $ oldChild ['prev ' ];
241+ $ newChild ->next = $ oldChild ['next ' ];
242+
243+ $ keys = array_keys ($ this ->children );
244+ $ index = array_search ($ childId , $ keys , true );
245+ $ keys [$ index ] = $ newChild ->id ();
246+ $ this ->children = array_combine ($ keys , $ this ->children );
247+ $ this ->children [$ newChild ->id ()] = array (
248+ 'prev ' => $ oldChild ['prev ' ],
249+ 'node ' => $ newChild ,
250+ 'next ' => $ oldChild ['next ' ]
251+ );
252+
253+ if ($ oldChild ['prev ' ] && isset ($ this ->children [$ newChild ->prev ])) {
254+ $ this ->children [$ oldChild ['prev ' ]]['next ' ] = $ newChild ->id ();
255+ }
256+
257+ if ($ oldChild ['next ' ] && isset ($ this ->children [$ newChild ->next ])) {
258+ $ this ->children [$ oldChild ['next ' ]]['prev ' ] = $ newChild ->id ();
259+ }
248260 }
249261
250262 /**
0 commit comments