await this.LockAsync().ConfigureAwait(false);\r
this.Clear();\r
this.FireUpdateEvent = false;\r
- this.UndoManager.BeginLock();\r
- string str;\r
- for (int i = 0; (str = await fs.ReadLineAsync().ConfigureAwait(false)) != null; i++)\r
- {\r
- int index = this.Length;\r
- if (index < 0)\r
- index = 0;\r
-\r
- this.Replace(index, 0, str + Document.NewLine);\r
-\r
- if (tokenSource != null)\r
- tokenSource.Token.ThrowIfCancellationRequested();\r
-#if TEST_ASYNC\r
- System.Threading.Thread.Sleep(10);\r
-#endif\r
- }\r
+ await this.buffer.LoadAsync(fs, tokenSource);\r
}\r
finally\r
{\r
this.FireUpdateEvent = true;\r
- this.UndoManager.EndLock();\r
this.UnLock();\r
}\r
}\r
using System.Linq;\r
using System.Text;\r
using System.Threading;\r
+using System.Threading.Tasks;\r
using Slusser.Collections.Generic;\r
\r
namespace FooEditEngine\r
this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, index, length, count));\r
}\r
\r
+ internal async Task LoadAsync(IStreamReader fs, CancellationTokenSource tokenSource = null)\r
+ {\r
+ string str;\r
+ for (int i = 0; (str = await fs.ReadLineAsync().ConfigureAwait(false)) != null; i++)\r
+ {\r
+ int index = this.Length;\r
+ if (index < 0)\r
+ index = 0;\r
+\r
+ this.buf.InsertRange(index, str + Document.NewLine, str.Length + 1);\r
+\r
+ if (tokenSource != null)\r
+ tokenSource.Token.ThrowIfCancellationRequested();\r
+#if TEST_ASYNC\r
+ System.Threading.Thread.Sleep(10);\r
+#endif\r
+ }\r
+ this.Update(this, new DocumentUpdateEventArgs(UpdateType.Clear, -1, -1, -1));\r
+ this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, 0, 0, buf.Count));\r
+ }\r
+\r
internal void Replace(string target, string pattern,bool ci = false)\r
{\r
TextSearch ts = new TextSearch(target,ci);\r