Ejemplo n.º 1
0
        private void Calc(HighlighterInfo h)
        {
            Match m;

            foreach (Pair <Regex, Color> rc in Regexes)
            {
                m = rc.t.Match(h.LineText);
                while (m.Success)
                {
                    Result.Enqueue(new Quad <int, int, int, Color>(h.Line, m.Index, m.Length, rc.u));
                    m = m.NextMatch();
                }
            }
        }
Ejemplo n.º 2
0
        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();
        }