*** empty log message ***
authorhanda <handa>
Wed, 22 Apr 2009 08:07:05 +0000 (08:07 +0000)
committerhanda <handa>
Wed, 22 Apr 2009 08:07:05 +0000 (08:07 +0000)
MText.cs

index 50b573c..cdb6ad3 100644 (file)
--- a/MText.cs
+++ b/MText.cs
@@ -1229,15 +1229,12 @@ namespace M17N.Core
        if (from < root.From)
          {
            MInterval prev = root.Prev;
-           int deleting = root.From - from;
-           int deleted = 0;
 
-           while (deleted < deleting)
+           while (true)
              {
                int len = prev.Length - prev.LeftLength;
 
                M17N.DebugPrint ("merging "); prev.DumpOne (false, true);
-               deleted += len;
                if (prev.Left != null)
                  {
                    prev.Left.Parent = prev.Parent;
@@ -1245,33 +1242,32 @@ namespace M17N.Core
                      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;
                  }
                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.Right = null;
-                   prev.Length -= deleted;
                  }
              }
-           while (prev.Parent != root)
-             {
-               prev.Length -= deleted;
-               prev = prev.Parent;
-             }
          }
        if (root.To < to)
          {
            MInterval next = root.Next;
-           int deleting = root.To - to;
-           int deleted = 0;
 
-           while (deleted < deleting)
+           while (true)
              {
                int len = next.Length - next.RightLength;
 
                M17N.DebugPrint ("merging "); next.DumpOne (false, true);
-               deleted += len;
                if (next.Right != null)
                  {
                    next.Right.Parent = next.Parent;
@@ -1279,20 +1275,22 @@ namespace M17N.Core
                      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;
                  }
                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.Left = null;
-                   next.Length -= deleted;
                  }
              }
-           while (next.Parent != root)
-             {
-               next.Length -= deleted;
-               next = next.Parent;
-             }
          }
       }