X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=Core%2FLineToIndex.cs;h=7f7094d4c0ab7986ed7784ac4e8637e4731eb8fa;hb=b3edc0d3744efd0a668e371ad2965602e3951432;hp=25a6ce1565deb5400b5af4e2547238590d8a3b90;hpb=afd969ca3e376e0418e6e2c3b5c28278527746fe;p=fooeditengine%2FFooEditEngine.git diff --git a/Core/LineToIndex.cs b/Core/LineToIndex.cs index 25a6ce1..7f7094d 100644 --- a/Core/LineToIndex.cs +++ b/Core/LineToIndex.cs @@ -121,6 +121,13 @@ namespace FooEditEngine End, } + interface ILineInfoGenerator + { + void Update(Document doc, int startIndex, int insertLength, int removeLength); + void Clear(LineToIndexTable lti); + bool Generate(Document doc, LineToIndexTable lti, bool force = true); + } + internal class LineToIndexTableData : IDisposable { /// @@ -212,20 +219,20 @@ namespace FooEditEngine Queue CacheEntries = new Queue(); GapBuffer Lines = new GapBuffer(); Document Document; - long lastUpdateTicks = DateTime.Now.Ticks; - const long AllowCallTicks = 1000 * 10000; //see.DateTime.Ticks プロパティ - bool _IsSync; ITextRender render; int stepRow = -1,stepLength = 0; const int STEP_ROW_IS_NONE = -1; - IFoldingStrategy _folding; + + const int FOLDING_INDEX = 0; + const int SYNTAX_HIGLITHER_INDEX = 1; + ILineInfoGenerator[] _generators = new ILineInfoGenerator[2]; internal LineToIndexTable(Document buf) { this.Document = buf; this.Document.Markers.Updated += Markers_Updated; - this.FoldingCollection = new FoldingCollection(); - this._IsSync = true; + this._generators[FOLDING_INDEX] = new FoldingGenerator(); + this._generators[SYNTAX_HIGLITHER_INDEX] = new SyntaxHilightGenerator(); #if DEBUG && !NETFX_CORE if (!Debugger.IsAttached) { @@ -269,26 +276,43 @@ namespace FooEditEngine /// public FoldingCollection FoldingCollection { - get; - private set; + get + { + return ((FoldingGenerator)this._generators[FOLDING_INDEX]).FoldingCollection; + } + private set + { + } } /// /// シンタックスハイライター /// - internal IHilighter Hilighter { get; set; } + internal IHilighter Hilighter + { + get + { + return ((SyntaxHilightGenerator)this._generators[SYNTAX_HIGLITHER_INDEX]).Hilighter; + } + set + { + ((SyntaxHilightGenerator)this._generators[SYNTAX_HIGLITHER_INDEX]).Hilighter = value; + if (value == null) + this._generators[FOLDING_INDEX].Clear(this); + } + } internal IFoldingStrategy FoldingStrategy { get { - return this._folding; + return ((FoldingGenerator)this._generators[FOLDING_INDEX]).FoldingStrategy; } set { - this._folding = value; + ((FoldingGenerator)this._generators[FOLDING_INDEX]).FoldingStrategy = value; if (value == null) - this.FoldingCollection.Clear(); + this._generators[FOLDING_INDEX].Clear(this); } } @@ -354,11 +378,8 @@ namespace FooEditEngine //行テーブルを更新する this.UpdateLineHeadIndex(deltaLength, row, 1); - this.FoldingCollection.UpdateData(this.Document, this.GetLineHeadIndex(row), insertedLength, removedLength); - - this._IsSync = false; - - this.lastUpdateTicks = DateTime.Now.Ticks; + foreach(var generator in this._generators) + generator.Update(this.Document, this.GetLineHeadIndex(row), insertedLength, removedLength); } internal void UpdateAsReplace(int index, int removedLength, int insertedLength) @@ -398,11 +419,8 @@ namespace FooEditEngine this.AddDummyLine(); - this.FoldingCollection.UpdateData(this.Document, index, insertedLength, removedLength); - - this._IsSync = false; - - this.lastUpdateTicks = DateTime.Now.Ticks; + foreach (var generator in this._generators) + generator.Update(this.Document, index, insertedLength, removedLength); } void GetRemoveRange(int index,int length,out int startRow,out int endRow) @@ -550,6 +568,17 @@ namespace FooEditEngine } /// + /// 生データを取得します + /// + /// 行 + /// LineToIndexTableData + /// いくつかの値は実態とかけ離れた値を返します。詳しくはLineToIndexTableDataの注意事項を参照すること + internal LineToIndexTableData GetRaw(int row) + { + return this.Lines[row]; + } + + /// /// 行番号をインデックスに変換します /// /// 行番号 @@ -729,43 +758,7 @@ namespace FooEditEngine /// デフォルトではドキュメントが更新されている時にだけ再生成されます public bool GenerateFolding(bool force = false) { - if (this.Document.Length == 0 || this.Document.IsLocked) - return false; - long nowTick = DateTime.Now.Ticks; - bool sync = force || !this._IsSync; - if (sync && Math.Abs(nowTick - this.lastUpdateTicks) >= AllowCallTicks) - { - this.GenerateFolding(0, this.Document.Length - 1); - this.lastUpdateTicks = nowTick; - this._IsSync = true; - return true; - } - return false; - } - - void GenerateFolding(int start, int end) - { - if (start > end) - throw new ArgumentException("start <= endである必要があります"); - if (this.FoldingStrategy != null) - { - //再生成するとすべて展開状態になってしまうので、閉じてるやつだけを保存しておく - FoldingItem[] closed_items = this.FoldingCollection.Where((e)=> { return !e.Expand; }).ToArray(); - - this.FoldingCollection.Clear(); - - var items = this.FoldingStrategy.AnalyzeDocument(this.Document, start, end) - .Where((item) => - { - int startRow = this.GetLineNumberFromIndex(item.Start); - int endRow = this.GetLineNumberFromIndex(item.End); - return startRow != endRow; - }) - .Select((item) => item); - this.FoldingCollection.AddRange(items); - - this.FoldingCollection.ApplyExpandStatus(closed_items); - } + return this._generators[FOLDING_INDEX].Generate(this.Document, this, force); } /// @@ -773,8 +766,7 @@ namespace FooEditEngine /// public void ClearFolding() { - this.FoldingCollection.Clear(); - this._IsSync = false; + this._generators[FOLDING_INDEX].Clear(this); } /// @@ -782,26 +774,7 @@ namespace FooEditEngine /// public bool HilightAll(bool force = false) { - if (this.Hilighter == null || this.Document.IsLocked) - return false; - - long nowTick = DateTime.Now.Ticks; - bool sync = force || !this._IsSync; - if (sync || Math.Abs(nowTick - this.lastUpdateTicks) >= AllowCallTicks) - { - for (int i = 0; i < this.Lines.Count; i++) - this.HilightLine(i); - - this.Hilighter.Reset(); - this.ClearLayoutCache(); - - this.lastUpdateTicks = nowTick; - - this._IsSync = true; - - return true; - } - return false; + return this._generators[SYNTAX_HIGLITHER_INDEX].Generate(this.Document, this, force); } /// @@ -809,10 +782,7 @@ namespace FooEditEngine /// public void ClearHilight() { - foreach (LineToIndexTableData line in this.Lines) - line.Syntax = null; - this.ClearLayoutCache(); - this._IsSync = false; + this._generators[SYNTAX_HIGLITHER_INDEX].Clear(this); } /// @@ -821,7 +791,7 @@ namespace FooEditEngine internal void Clear() { this.ClearLayoutCache(); - this.FoldingCollection.Clear(); + this.ClearFolding(); this.Lines.Clear(); LineToIndexTableData dummy = new LineToIndexTableData(); this.Lines.Add(dummy); @@ -830,25 +800,6 @@ namespace FooEditEngine Debug.WriteLine("Clear"); } - private void HilightLine(int row) - { - //シンタックスハイライトを行う - List syntax = new List(); - string str = this[row]; - int level = this.Hilighter.DoHilight(str, str.Length, (s) => - { - if (s.type == TokenType.None || s.type == TokenType.Control) - return; - if (str[s.index + s.length - 1] == Document.NewLine) - s.length--; - syntax.Add(new SyntaxInfo(s.index, s.length, s.type)); - }); - - LineToIndexTableData lineData = this.Lines[row]; - lineData.Syntax = syntax.ToArray(); - - } - #region IEnumerable メンバー ///