2 using System.Collections.Generic;
5 namespace FooEditEngine
7 class SyntaxHilightGenerator : ILineInfoGenerator
9 const long AllowCallTicks = 1000 * 10000; //see.DateTime.Ticks プロパティ
10 long lastUpdateTicks = DateTime.Now.Ticks;
11 IFoldingStrategy _folding;
17 internal IHilighter Hilighter { get; set; }
19 public void Clear(LineToIndexTable lti)
21 for (int i = 0; i < lti.Count; i++)
22 lti.GetRaw(i).Syntax = null;
23 lti.ClearLayoutCache();
27 public bool Generate(Document doc, LineToIndexTable lti, bool force = true)
29 if (this.Hilighter == null || doc.IsLocked)
32 long nowTick = DateTime.Now.Ticks;
33 bool sync = force || !this._IsSync;
34 if (sync || Math.Abs(nowTick - this.lastUpdateTicks) >= AllowCallTicks)
36 for (int i = 0; i < lti.Count; i++)
37 this.HilightLine(lti, i);
39 this.Hilighter.Reset();
40 lti.ClearLayoutCache();
42 this.lastUpdateTicks = nowTick;
51 private void HilightLine(LineToIndexTable lti, int row)
54 List<SyntaxInfo> syntax = new List<SyntaxInfo>();
55 string str = lti[row];
56 int level = this.Hilighter.DoHilight(str, str.Length, (s) =>
58 if (s.type == TokenType.None || s.type == TokenType.Control)
60 if (str[s.index + s.length - 1] == Document.NewLine)
62 syntax.Add(new SyntaxInfo(s.index, s.length, s.type));
65 LineToIndexTableData lineData = lti.GetRaw(row);
66 lineData.Syntax = syntax.ToArray();
70 public void Update(Document doc, int startIndex, int insertLength, int removeLength)