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;
16 internal IHilighter Hilighter { get; set; }
18 public void Clear(LineToIndexTable lti)
20 for (int i = 0; i < lti.Count; i++)
21 lti.GetRaw(i).Syntax = null;
22 lti.ClearLayoutCache();
26 public bool Generate(Document doc, LineToIndexTable lti, bool force = true)
28 if (this.Hilighter == null)
31 long nowTick = DateTime.Now.Ticks;
32 bool sync = force || !this._IsSync;
33 if (sync || Math.Abs(nowTick - this.lastUpdateTicks) >= AllowCallTicks)
35 for (int i = 0; i < lti.Count; i++)
36 this.HilightLine(lti, i);
38 this.Hilighter.Reset();
39 lti.ClearLayoutCache();
41 this.lastUpdateTicks = nowTick;
50 private void HilightLine(LineToIndexTable lti, int row)
53 List<SyntaxInfo> syntax = new List<SyntaxInfo>();
54 string str = lti[row];
55 int level = this.Hilighter.DoHilight(str, str.Length, (s) =>
57 if (s.type == TokenType.None || s.type == TokenType.Control)
59 if (str[s.index + s.length - 1] == Document.NewLine)
61 syntax.Add(new SyntaxInfo(s.index, s.length, s.type));
64 LineToIndexTableData lineData = lti.GetRaw(row);
65 lineData.Syntax = syntax.ToArray();
69 public void Update(Document doc, int startIndex, int insertLength, int removeLength)