/// <summary> /// This method is called when a text view is removed from this HighlightingColorizer, /// and also when the TextDocument on any associated text view changes. /// </summary> protected virtual void DeregisterServices(TextView textView) { if (highlighter != null) { if (isInHighlightingGroup) { highlighter.EndHighlighting(); isInHighlightingGroup = false; } highlighter.HighlightingStateChanged -= OnHighlightStateChanged; // remove highlighter if it is registered if (textView.Services.GetService(typeof(IHighlighter)) == highlighter) { textView.Services.RemoveService(typeof(IHighlighter)); } if (!isFixedHighlighter) { if (highlighter != null) { highlighter.Dispose(); } highlighter = null; } } }
/// <summary> /// Creates a new <see cref="FixedHighlighter"/> for a copy of a portion /// of the input document (including the original highlighting). /// </summary> public static FixedHighlighter CreateView(IHighlighter highlighter, int offset, int endOffset) { var oldDocument = highlighter.Document; // ReadOnlyDocument would be better; but displaying the view in AvalonEdit // requires a TextDocument var newDocument = new TextDocument(oldDocument.CreateSnapshot(offset, endOffset - offset)); var oldStartLine = oldDocument.GetLineByOffset(offset); var oldEndLine = oldDocument.GetLineByOffset(endOffset); int oldStartLineNumber = oldStartLine.LineNumber; HighlightedLine[] newLines = new HighlightedLine[oldEndLine.LineNumber - oldStartLineNumber + 1]; highlighter.BeginHighlighting(); try { for (int i = 0; i < newLines.Length; i++) { HighlightedLine oldHighlightedLine = highlighter.HighlightLine(oldStartLineNumber + i); IDocumentLine newLine = newDocument.GetLineByNumber(1 + i); HighlightedLine newHighlightedLine = new HighlightedLine(newDocument, newLine); MoveSections(oldHighlightedLine.Sections, -offset, newLine.Offset, newLine.EndOffset, newHighlightedLine.Sections); newHighlightedLine.ValidateInvariants(); newLines[i] = newHighlightedLine; } } finally { highlighter.EndHighlighting(); } return new FixedHighlighter(newDocument, newLines); }
/// <summary> /// Creates a new <see cref="FixedHighlighter"/> for a copy of a portion /// of the input document (including the original highlighting). /// </summary> public static FixedHighlighter CreateView(IHighlighter highlighter, int offset, int endOffset) { var oldDocument = highlighter.Document; // ReadOnlyDocument would be better; but displaying the view in AvalonEdit // requires a TextDocument var newDocument = new TextDocument(oldDocument.CreateSnapshot(offset, endOffset - offset)); var oldStartLine = oldDocument.GetLineByOffset(offset); var oldEndLine = oldDocument.GetLineByOffset(endOffset); int oldStartLineNumber = oldStartLine.LineNumber; HighlightedLine[] newLines = new HighlightedLine[oldEndLine.LineNumber - oldStartLineNumber + 1]; highlighter.BeginHighlighting(); try { for (int i = 0; i < newLines.Length; i++) { HighlightedLine oldHighlightedLine = highlighter.HighlightLine(oldStartLineNumber + i); IDocumentLine newLine = newDocument.GetLineByNumber(1 + i); HighlightedLine newHighlightedLine = new HighlightedLine(newDocument, newLine); MoveSections(oldHighlightedLine.Sections, -offset, newLine.Offset, newLine.EndOffset, newHighlightedLine.Sections); newHighlightedLine.ValidateInvariants(); newLines[i] = newHighlightedLine; } } finally { highlighter.EndHighlighting(); } return(new FixedHighlighter(newDocument, newLines)); }
public void EndHighlighting() { baseHighlighter.EndHighlighting(); }