Exemple #1
0
        bool MarkTokensInLine(IDocument document, int lineNumber, ref bool spanChanged)
        {
            currentLineNumber = lineNumber;
            bool        processNextLine = false;
            LineSegment previousLine    = (lineNumber > 0 ? document.GetLineSegment(lineNumber - 1) : null);

            currentSpanStack = ((previousLine != null && previousLine.HighlightSpanStack != null) ? previousLine.HighlightSpanStack.Clone() : null);
            if (currentSpanStack != null)
            {
                while (!currentSpanStack.IsEmpty && currentSpanStack.Peek().StopEOL)
                {
                    currentSpanStack.Pop();
                }
                if (currentSpanStack.IsEmpty)
                {
                    currentSpanStack = null;
                }
            }

            currentLine = (LineSegment)document.LineSegmentCollection[lineNumber];

            if (currentLine.Length == -1)   // happens when buffer is empty !
            {
                return(false);
            }

            List <TextWord> words = ParseLine(document);

            if (currentSpanStack != null && currentSpanStack.IsEmpty)
            {
                currentSpanStack = null;
            }

            // Check if the span state has changed, if so we must re-render the next line
            // This check may seem utterly complicated but I didn't want to introduce any function calls
            // or allocations here for perf reasons.
            if (currentLine.HighlightSpanStack != currentSpanStack)
            {
                if (currentLine.HighlightSpanStack == null)
                {
                    processNextLine = false;
                    foreach (Span sp in currentSpanStack)
                    {
                        if (!sp.StopEOL)
                        {
                            spanChanged     = true;
                            processNextLine = true;
                            break;
                        }
                    }
                }
                else if (currentSpanStack == null)
                {
                    processNextLine = false;
                    foreach (Span sp in currentLine.HighlightSpanStack)
                    {
                        if (!sp.StopEOL)
                        {
                            spanChanged     = true;
                            processNextLine = true;
                            break;
                        }
                    }
                }
                else
                {
                    SpanStack.Enumerator e1 = currentSpanStack.GetEnumerator();
                    SpanStack.Enumerator e2 = currentLine.HighlightSpanStack.GetEnumerator();
                    bool done = false;
                    while (!done)
                    {
                        bool blockSpanIn1 = false;
                        while (e1.MoveNext())
                        {
                            if (!((Span)e1.Current).StopEOL)
                            {
                                blockSpanIn1 = true;
                                break;
                            }
                        }
                        bool blockSpanIn2 = false;
                        while (e2.MoveNext())
                        {
                            if (!((Span)e2.Current).StopEOL)
                            {
                                blockSpanIn2 = true;
                                break;
                            }
                        }
                        if (blockSpanIn1 || blockSpanIn2)
                        {
                            if (blockSpanIn1 && blockSpanIn2)
                            {
                                if (e1.Current != e2.Current)
                                {
                                    done            = true;
                                    processNextLine = true;
                                    spanChanged     = true;
                                }
                            }
                            else
                            {
                                spanChanged     = true;
                                done            = true;
                                processNextLine = true;
                            }
                        }
                        else
                        {
                            done            = true;
                            processNextLine = false;
                        }
                    }
                }
            }
            else
            {
                processNextLine = false;
            }

            //// Alex: remove old words
            if (currentLine.Words != null)
            {
                currentLine.Words.Clear();
            }
            currentLine.Words = words;
            currentLine.HighlightSpanStack = (currentSpanStack != null && !currentSpanStack.IsEmpty) ? currentSpanStack : null;

            return(processNextLine);
        }
        private bool MarkTokensInLine(IDocument document, int lineNumber, ref bool spanChanged)
        {
            LineSegment lineSegment;
            SpanStack   spanStacks;
            SpanStack   spanStacks1;

            this.currentLineNumber = lineNumber;
            bool flag = false;

            if (lineNumber > 0)
            {
                lineSegment = document.GetLineSegment(lineNumber - 1);
            }
            else
            {
                lineSegment = null;
            }
            LineSegment lineSegment1 = lineSegment;

            if (lineSegment1 == null || lineSegment1.HighlightSpanStack == null)
            {
                spanStacks = null;
            }
            else
            {
                spanStacks = lineSegment1.HighlightSpanStack.Clone();
            }
            this.currentSpanStack = spanStacks;
            if (this.currentSpanStack != null)
            {
                while (!this.currentSpanStack.IsEmpty && this.currentSpanStack.Peek().StopEOL)
                {
                    this.currentSpanStack.Pop();
                }
                if (this.currentSpanStack.IsEmpty)
                {
                    this.currentSpanStack = null;
                }
            }
            this.currentLine = document.LineSegmentCollection[lineNumber];
            if (this.currentLine.Length == -1)
            {
                return(false);
            }
            List <TextWord> textWords = this.ParseLine(document);

            if (this.currentSpanStack != null && this.currentSpanStack.IsEmpty)
            {
                this.currentSpanStack = null;
            }
            if (this.currentLine.HighlightSpanStack == this.currentSpanStack)
            {
                flag = false;
            }
            else if (this.currentLine.HighlightSpanStack == null)
            {
                flag = false;
                foreach (Span span in this.currentSpanStack)
                {
                    if (span.StopEOL)
                    {
                        continue;
                    }
                    spanChanged = true;
                    flag        = true;
                    break;
                }
            }
            else if (this.currentSpanStack != null)
            {
                SpanStack.Enumerator enumerator  = this.currentSpanStack.GetEnumerator();
                SpanStack.Enumerator enumerator1 = this.currentLine.HighlightSpanStack.GetEnumerator();
                bool flag1 = false;
                while (!flag1)
                {
                    bool flag2 = false;
                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current.StopEOL)
                        {
                            continue;
                        }
                        flag2 = true;
                        break;
                    }
                    bool flag3 = false;
                    while (enumerator1.MoveNext())
                    {
                        if (enumerator1.Current.StopEOL)
                        {
                            continue;
                        }
                        flag3 = true;
                        break;
                    }
                    if (!flag2 && !flag3)
                    {
                        flag1 = true;
                        flag  = false;
                    }
                    else if (!flag2 || !flag3)
                    {
                        spanChanged = true;
                        flag1       = true;
                        flag        = true;
                    }
                    else
                    {
                        if (enumerator.Current == enumerator1.Current)
                        {
                            continue;
                        }
                        flag1       = true;
                        flag        = true;
                        spanChanged = true;
                    }
                }
            }
            else
            {
                flag = false;
                foreach (Span highlightSpanStack in this.currentLine.HighlightSpanStack)
                {
                    if (highlightSpanStack.StopEOL)
                    {
                        continue;
                    }
                    spanChanged = true;
                    flag        = true;
                    break;
                }
            }
            if (this.currentLine.Words != null)
            {
                this.currentLine.Words.Clear();
            }
            this.currentLine.Words = textWords;
            LineSegment lineSegment2 = this.currentLine;

            if (this.currentSpanStack == null || this.currentSpanStack.IsEmpty)
            {
                spanStacks1 = null;
            }
            else
            {
                spanStacks1 = this.currentSpanStack;
            }
            lineSegment2.HighlightSpanStack = spanStacks1;
            return(flag);
        }