Index: /CKEditor/trunk/CHANGES.html
===================================================================
--- /CKEditor/trunk/CHANGES.html	(revision 5142)
+++ /CKEditor/trunk/CHANGES.html	(revision 5143)
@@ -100,4 +100,5 @@
 		<li><a href="http://dev.fckeditor.net/ticket/5095">#5095</a> : Safari on Mac deleted current selection when Edit menu was clicked.</li>
 		<li><a href="http://dev.fckeditor.net/ticket/5140">#5140</a> : In High Contrast mode, arrows will now be displayed for menus with submenus.</li>
+		<li><a href="http://dev.fckeditor.net/ticket/5163">#5163</a> : The undo system was not working on some specific cases.</li>
 		<li>Updated the following language files:<ul>
 			<li><a href="http://dev.fckeditor.net/ticket/5006">#5006</a> : Dutch;</li>
Index: /CKEditor/trunk/_source/core/dom/node.js
===================================================================
--- /CKEditor/trunk/_source/core/dom/node.js	(revision 5142)
+++ /CKEditor/trunk/_source/core/dom/node.js	(revision 5143)
@@ -195,25 +195,28 @@
 				var currentIndex = -1;
 
-				for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )
-				{
-					var candidate = parentNode.childNodes[i];
-
-					if ( normalized &&
-							candidate.nodeType == 3 &&
-							candidate.previousSibling &&
-							candidate.previousSibling.nodeType == 3 )
+				if ( parentNode )
+				{
+					for ( var i = 0 ; i < parentNode.childNodes.length ; i++ )
 					{
-						continue;
+						var candidate = parentNode.childNodes[i];
+
+						if ( normalized &&
+								candidate.nodeType == 3 &&
+								candidate.previousSibling &&
+								candidate.previousSibling.nodeType == 3 )
+						{
+							continue;
+						}
+
+						currentIndex++;
+
+						if ( candidate == node )
+							break;
 					}
 
-					currentIndex++;
-
-					if ( candidate == node )
-						break;
+					address.unshift( currentIndex );
 				}
 
-				address.unshift( currentIndex );
-
-				node = node.parentNode;
+				node = parentNode;
 			}
 
