*** empty log message ***
authorhanda <handa>
Wed, 22 Apr 2009 11:40:04 +0000 (11:40 +0000)
committerhanda <handa>
Wed, 22 Apr 2009 11:40:04 +0000 (11:40 +0000)
MText.cs

index cdb6ad3..6b69daf 100644 (file)
--- a/MText.cs
+++ b/MText.cs
@@ -467,6 +467,7 @@ namespace M17N.Core
            {
              MInterval root = (MInterval) p.Val;
              root.Pop (from, to);
+             DumpPropNested ();
              root.MergeAfterChange (from, to);
            }
        }
@@ -1101,7 +1102,15 @@ namespace M17N.Core
 
       private void vacate_node (MInterval interval)
       {
-       M17N.DebugPrint ("vacate #{0} to #{1}", ID, interval.ID);
+       vacate_node (interval, null);
+      }
+
+      private void vacate_node (MInterval interval, MInterval stop)
+      {
+       if (interval != null)
+         M17N.DebugPrint ("vacate #{0} to #{1}\n", ID, interval.ID);
+       else
+         M17N.DebugPrint ("vacate #{0} to null\n", ID);
        if (interval != null)
          interval.Parent = Parent;
        if (Parent == null)
@@ -1119,7 +1128,7 @@ namespace M17N.Core
            int diff = Length;
            if (interval != null)
              diff -= interval.Length;
-           for (MInterval i = Parent; i != null; i = i.Parent)
+           for (MInterval i = Parent; i != stop; i = i.Parent)
              i.Length -= diff;
          }
       }
@@ -1215,7 +1224,7 @@ namespace M17N.Core
       private static void merge_nodes (MInterval head, MInterval tail)
       {
        M17N.DebugPrint ("merging "); head.DumpOne (true, false);
-       M17N.DebugPrint (" through "); tail.DumpOne (true, true);
+       M17N.DebugPrint (" through "); tail.DumpOne (true, false);
 
        int from = head.From;
        int to = tail.To;
@@ -1224,7 +1233,7 @@ namespace M17N.Core
        for (root = head; root.To + head.RightLength < to;
             root = root.Parent);
        
-       M17N.DebugPrint ("common root is "); root.DumpOne (false, true);
+       M17N.DebugPrint (" common root is "); root.DumpOne (false, true);
 
        if (from < root.From)
          {
@@ -1232,31 +1241,14 @@ namespace M17N.Core
 
            while (true)
              {
-               int len = prev.Length - prev.LeftLength;
-
                M17N.DebugPrint ("merging "); prev.DumpOne (false, true);
+               prev.vacate_node (prev.Left, root);
+               if (prev == head)
+                 break;
                if (prev.Left != null)
-                 {
-                   prev.Left.Parent = prev.Parent;
-                   if (prev.Parent.Right == prev)
-                     prev.Parent.Right = prev.Left;
-                   else
-                     prev.Parent.Left = prev.Left;
-                   for (MInterval i = prev.Parent; i != root; i = i.Parent)
-                     i.Length -= len;
-                   if (prev == head)
-                     break;
-                   prev = prev.Left.RightMost;
-                 }
+                 prev = prev.Left.RightMost;
                else
-                 {
-                   prev.Parent.Right = null;
-                   for (MInterval i = prev.Parent; i != root; i = i.Parent)
-                     i.Length -= len;
-                   if (prev == head)
-                     break;
-                   prev = prev.Parent;
-                 }
+                 prev = prev.Parent;
              }
          }
        if (root.To < to)
@@ -1265,31 +1257,14 @@ namespace M17N.Core
 
            while (true)
              {
-               int len = next.Length - next.RightLength;
-
                M17N.DebugPrint ("merging "); next.DumpOne (false, true);
+               next.vacate_node (next.Right, root);
+               if (next == tail)
+                 break;
                if (next.Right != null)
-                 {
-                   next.Right.Parent = next.Parent;
-                   if (next.Parent.Left == next)
-                     next.Parent.Left = next.Right;
-                   else
-                     next.Parent.Right = next.Right;
-                   for (MInterval i = next.Parent; i != root; i = i.Parent)
-                     i.Length -= len;
-                   if (next == tail)
-                     break;
-                   next = next.Right.LeftMost;
-                 }
+                 next = next.Right.LeftMost;
                else
-                 {
-                   next.Parent.Left = null;
-                   for (MInterval i = next.Parent; i != root; i = i.Parent)
-                     i.Length -= len;
-                   if (next == tail)
-                     break;
-                   next = next.Parent;
-                 }
+                 next = next.Parent;
              }
          }
       }