public void SetSelection(TextLocation startPosition, TextLocation endPosition, bool isRect)
        {
            ClearWithoutUpdate();

            // Make sure to clean out old stuff too.
            int ymin = Math.Min(StartPosition.Y, startPosition.Y);
            int ymax = Math.Max(StartPosition.Y, startPosition.Y);

            // Save new.
            _isRect       = isRect;
            StartPosition = startPosition;
            EndPosition   = endPosition;

            _document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.LinesBetween, ymin, ymax));
            _document.CommitUpdate();

            OnSelectionChanged(EventArgs.Empty);
        }
Example #2
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;
        }
Example #3
0
        public void UpdateFoldings(List <FoldMarker> newFoldings)
        {
            int oldFoldingsCount = _foldMarker.Count;

            lock (this)
            {
                if (newFoldings != null && newFoldings.Count != 0)
                {
                    newFoldings.Sort();
                    if (_foldMarker.Count == newFoldings.Count)
                    {
                        for (int i = 0; i < _foldMarker.Count; ++i)
                        {
                            newFoldings[i].IsFolded = _foldMarker[i].IsFolded;
                        }
                        _foldMarker = newFoldings;
                    }
                    else
                    {
                        for (int i = 0, j = 0; i < _foldMarker.Count && j < newFoldings.Count;)
                        {
                            int n = newFoldings[j].CompareTo(_foldMarker[i]);
                            if (n > 0)
                            {
                                ++i;
                            }
                            else
                            {
                                if (n == 0)
                                {
                                    newFoldings[j].IsFolded = _foldMarker[i].IsFolded;
                                }
                                ++j;
                            }
                        }
                    }
                }
                if (newFoldings != null)
                {
                    _foldMarker      = newFoldings;
                    _foldMarkerByEnd = new List <FoldMarker>(newFoldings);
                    _foldMarkerByEnd.Sort(EndComparer.Instance);
                }
                else
                {
                    _foldMarker.Clear();
                    _foldMarkerByEnd.Clear();
                }
            }
            if (oldFoldingsCount != _foldMarker.Count)
            {
                _document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
                _document.CommitUpdate();
            }
        }
Example #4
0
        public void MarkTokens(Document document, List <LineSegment> inputLines)
        {
            if (Rules.Count == 0)
            {
                return;
            }

            Dictionary <LineSegment, bool> processedLines = new Dictionary <LineSegment, bool>();

            bool spanChanged = false;
            int  documentLineSegmentCount = document.LineSegmentCollection.Count;

            foreach (LineSegment lineToProcess in inputLines)
            {
                if (!processedLines.ContainsKey(lineToProcess))
                {
                    int  lineNumber      = lineToProcess.LineNumber;
                    bool processNextLine = true;

                    if (lineNumber != -1)
                    {
                        while (processNextLine && lineNumber < documentLineSegmentCount)
                        {
                            processNextLine = MarkTokensInLine(document, lineNumber, ref spanChanged);
                            processedLines[_currentLine] = true;
                            ++lineNumber;
                        }
                    }
                }
            }

            if (spanChanged || inputLines.Count > 20)
            {
                // if the span was changed (more than inputLines lines had to be reevaluated)
                // or if there are many lines in inputLines, it's faster to update the whole
                // text area instead of many small segments
                document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea));
            }
            else
            {
                //				document.Caret.ValidateCaretPos();
                //				document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, document.GetLineNumberForOffset(document.Caret.Offset)));
                //
                foreach (LineSegment lineToProcess in inputLines)
                {
                    document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineToProcess.LineNumber));
                }
            }
            document.CommitUpdate();
            _currentLine = null;
        }