public void Highlight(FlickerFreeRichEditTextBox box) { box._ignore = true; box._Paint = false; box.SuspendLayout(); box.SuspendDrawing(); int p0 = box.SelectionStart; int p1 = box.SelectionLength; box.SelectAll(); box.SelectionColor = Color.Black; if (_context != null) { string txt = box.Text; try { ScriptChecker checker = new ScriptChecker(txt, null); SortedList <Pair <int, int>, LintType> lints = checker.Lint(_context); string[] lines = box.Lines; if (lines.Length > 0) { box.Rtf = MakeRTF(lines, lints); /* * LinterType prev = LinterType.NONE; * LinterStep current = new LinterStep(0, 0, LinterType.NONE); * foreach (LinterStep lint in lints) * { * if (current.Line <= lint.Line && current.Position < lint.Position) * { * if (current.Lint != prev) * { * box.Select(box.GetFirstCharIndexFromLine(current.Line - 1) + current.Position, lint.Position - current.Position); * if (box.SelectionColor == Color.Black) * box.SelectionColor = LintColors[current.Lint]; * } * } * prev = current.Lint; * current = lint; * } */ } } catch { box.Text = txt; } } box.SelectionStart = p0; box.SelectionLength = p1; box._Paint = true; box.ResumeLayout(); box.ResumeDrawing(); box._ignore = false; }
public virtual void Highlight(FlickerFreeRichEditTextBox box) { box._ignore = true; box._Paint = false; box.Enabled = false; box.SuspendLayout(); box.SuspendDrawing(); int p0 = box.SelectionStart; int p1 = box.SelectionLength; box.SelectAll(); box.SelectionColor = Color.Black; HighlighterInfo[] h = new HighlighterInfo[box.Lines.Length]; for (int i = 0; i < box.Lines.Length; i++) { h[i] = new HighlighterInfo() { Line = i, LineText = box.Lines[i] } } ; Parallel.ForEach(h, Calc); while (Result.TryDequeue(out Quad <int, int, int, Color> r)) { box.Select(box.GetFirstCharIndexFromLine(r.t) + r.u, r.v); if (box.SelectionColor == Color.Black) { box.SelectionColor = r.w; } } box.SelectionStart = p0; box.SelectionLength = p1; box._Paint = true; box.ResumeLayout(); box.ResumeDrawing(); box._ignore = false; box.Enabled = true; box.ClearUndo(); }