OSDN Git Service

読み込み時に行分割を行わず、レタリング時に行分割を行うようにした
[fooeditengine/FooEditEngine.git] / Core / Document.cs
index b808f4a..5395d20 100644 (file)
@@ -791,6 +791,9 @@ namespace FooEditEngine
                 throw new InvalidOperationException("");
             if (start < 0 || start + length < 0 || start + length > this.Length)
                 throw new ArgumentOutOfRangeException("startかendが指定できる範囲を超えてます");
+            //選択範囲が消されたとき
+            foreach (Selection sel in this.Selections)
+                this.LayoutLines.ClearLayoutCache(sel.start, sel.length);
             this.Selections.Clear();
             if (length < 0)
             {
@@ -803,12 +806,13 @@ namespace FooEditEngine
                 TextPoint startTextPoint = this.LayoutLines.GetTextPointFromIndex(start);
                 TextPoint endTextPoint = this.LayoutLines.GetTextPointFromIndex(start + length);
                 this.SelectByRectangle(new TextRectangle(startTextPoint, endTextPoint));
+                this.LayoutLines.ClearLayoutCache(start, length);
             }
             else if (length != 0)
             {
                 this.Selections.Add(Selection.Create(start, length));
+                this.LayoutLines.ClearLayoutCache(start, length);
             }
-            this.LayoutLines.ClearLayoutCache();
             this.SelectionChanged(this, null);
         }
 
@@ -911,7 +915,9 @@ namespace FooEditEngine
                 start--;
 
             if (find_sep_func(str[start]))
+            {
                 start++;
+            }
 
             int end = index;
             while (end < this.Length && !find_sep_func(str[end]))
@@ -1131,15 +1137,11 @@ namespace FooEditEngine
             try
             {
                 this.Clear();
-                this.LayoutLines.IsFrozneDirtyFlag = true;
                 await this.buffer.LoadAsync(fs, tokenSource);
             }
             finally
             {
-                this.Dirty = false; //ファイルの内容とドキュメントの中身は同じなのでダーティフラグは偽にする
                 this.PerformLayout();
-                //これ以降の操作にだけダーティフラグを適用しないとおかしなことになる
-                this.LayoutLines.IsFrozneDirtyFlag = false;
                 if (this.LoadProgress != null)
                     this.LoadProgress(this, new ProgressEventArgs(ProgressState.Complete));
             }
@@ -1151,36 +1153,10 @@ namespace FooEditEngine
         /// <param name="fs">IStreamWriterオブジェクト</param>
         /// <param name="tokenSource">キャンセルトークン</param>
         /// <returns>Taskオブジェクト</returns>
-        /// <remarks>非同期操作中はこのメソッドを実行することはできません。同時にダーティフラグもクリアされます</remarks>
+        /// <remarks>非同期操作中はこのメソッドを実行することはできません</remarks>
         public async Task SaveAsync(TextWriter fs, CancellationTokenSource tokenSource = null)
         {
-            try
-            {
-                await this.buffer.LockAsync().ConfigureAwait(false);
-                StringBuilder line = new StringBuilder();
-                for (int i = 0; i < this.Length; i++)
-                {
-                    char c = this[i];
-                    line.Append(c);
-                    if (c == Document.NewLine || i == this.Length - 1)
-                    {
-                        string str = line.ToString();
-                        str = str.Replace(Document.NewLine.ToString(), fs.NewLine);
-                        await fs.WriteAsync(str).ConfigureAwait(false);
-                        line.Clear();
-                        if (tokenSource != null)
-                            tokenSource.Token.ThrowIfCancellationRequested();
-#if TEST_ASYNC
-                    System.Threading.Thread.Sleep(10);
-#endif
-                    }
-                }
-                this.Dirty = false;
-            }
-            finally
-            {
-                this.buffer.UnLock();
-            }
+            await this.buffer.SaveAsync(fs, tokenSource);
         }
 
         /// <summary>