void DocumentChanged(object sender, DocumentEventArgs e) { int oldCount = _foldMarker.Count; _document.UpdateSegmentListOnDocumentChange(_foldMarker, e); if (oldCount != _foldMarker.Count) { _document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); } }
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; }
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); }
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; }