Exemplo n.º 1
0
        public void MarkTokens(Document document)
        {
            if (Rules.Count == 0)
            {
                return;
            }

            int lineNumber = 0;

            while (lineNumber < document.TotalNumberOfLines)
            {
                LineSegment previousLine = (lineNumber > 0 ? document.GetLineSegment(lineNumber - 1) : null);
                if (lineNumber >= document.LineSegmentCollection.Count)   // may be, if the last line ends with a delimiter
                {
                    break;                                                // then the last line is not in the collection :)
                }

                _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;
                }

                _currentLineNumber = lineNumber;
                List <TextWord> words = ParseLine(document);
                // Alex: clear old words
                if (_currentLine.Words != null)
                {
                    _currentLine.Words.Clear();
                }
                _currentLine.Words = words;
                _currentLine.HighlightSpanStack = (_currentSpanStack == null || _currentSpanStack.IsEmpty) ? null : _currentSpanStack;

                ++lineNumber;
            }

            document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
            document.CommitUpdate();
            _currentLine = null;
        }
 void CreateAnchor()
 {
     if (_document != null)
     {
         LineSegment line = _document.GetLineSegment(Math.Max(0, Math.Min(_location.Line, _document.TotalNumberOfLines - 1)));
         Anchor = line.CreateAnchor(Math.Max(0, Math.Min(_location.Column, line.Length)));
         // after insertion: keep bookmarks after the initial whitespace (see DefaultFormattingStrategy.SmartReplaceLine)
         Anchor.MovementType = AnchorMovementType.AfterInsertion;
         Anchor.Deleted     += AnchorDeleted;
     }
 }
        public FoldMarker(Document document, int startLine, int startColumn, int endLine, int endColumn, FoldType foldType, string foldText, bool isFolded)
        {
            this.document = document;

            startLine = Math.Min(document.TotalNumberOfLines - 1, Math.Max(startLine, 0));
            LineSegment startLineSegment = document.GetLineSegment(startLine);

            endLine = Math.Min(document.TotalNumberOfLines - 1, Math.Max(endLine, 0));
            LineSegment endLineSegment = document.GetLineSegment(endLine);

            // Prevent the region from completely disappearing
            if (string.IsNullOrEmpty(foldText))
            {
                foldText = "...";
            }

            this.FoldType = foldType;
            this.FoldText = foldText;
            this.offset   = startLineSegment.Offset + Math.Min(startColumn, startLineSegment.Length);
            this.length   = (endLineSegment.Offset + Math.Min(endColumn, endLineSegment.Length)) - this.offset;
            this.IsFolded = isFolded;
        }
 static void GetPointForOffset(Document document, int offset, out int line, out int column)
 {
     if (offset > document.TextLength)
     {
         line   = document.TotalNumberOfLines + 1;
         column = 1;
     }
     else if (offset < 0)
     {
         line   = -1;
         column = -1;
     }
     else
     {
         line   = document.GetLineNumberForOffset(offset);
         column = offset - document.GetLineSegment(line).Offset;
     }
 }
Exemplo n.º 5
0
        bool MarkTokensInLine(Document 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 = 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);
        }
 /// <remarks>
 /// Returns true, if the line lineNumber is empty or filled with whitespaces.
 /// </remarks>
 public static bool IsEmptyLine(Document document, int lineNumber)
 {
     return(IsEmptyLine(document, document.GetLineSegment(lineNumber)));
 }
        public static string GetLineAsString(Document document, int lineNumber)
        {
            LineSegment line = document.GetLineSegment(lineNumber);

            return(document.GetText(line.Offset, line.Length));
        }