diff --git a/src/AvaloniaEdit.Demo/CustomMargin.cs b/src/AvaloniaEdit.Demo/CustomMargin.cs index 3b4809b..b776acb 100644 --- a/src/AvaloniaEdit.Demo/CustomMargin.cs +++ b/src/AvaloniaEdit.Demo/CustomMargin.cs @@ -4,6 +4,7 @@ using Avalonia; using Avalonia.Input; using Avalonia.Media; using Avalonia.Media.Immutable; +using AvaloniaEdit.Document; using AvaloniaEdit.Editing; using AvaloniaEdit.Rendering; @@ -51,9 +52,16 @@ namespace AvaloniaEdit.Demo protected override void OnTextViewChanged(TextView? oldTextView, TextView? newTextView) { if (oldTextView != null) + { oldTextView.VisualLinesChanged -= OnVisualLinesChanged; + oldTextView.DocumentChanged -= OnDocumentChanged; + } + if (newTextView != null) + { newTextView.VisualLinesChanged += OnVisualLinesChanged; + newTextView.DocumentChanged += OnDocumentChanged; + } base.OnTextViewChanged(oldTextView, newTextView); } @@ -63,6 +71,12 @@ namespace AvaloniaEdit.Demo InvalidateVisual(); } + private void OnDocumentChanged(object? sender, DocumentChangedEventArgs e) + { + _markedDocumentLines.Clear(); + InvalidateVisual(); + } + protected override Size MeasureOverride(Size availableSize) { return new Size(20, 0); @@ -86,6 +100,7 @@ namespace AvaloniaEdit.Demo protected override void OnPointerExited(PointerEventArgs e) { _pointerOverLine = -1; + InvalidateVisual(); base.OnPointerExited(e); } @@ -112,12 +127,12 @@ namespace AvaloniaEdit.Demo { foreach (var visualLine in TextView.VisualLines) { - double y = TextView.VerticalOffset + visualLine.VisualTop + visualLine.Height / 2; + double y = visualLine.VisualTop - TextView.VerticalOffset + visualLine.Height / 2; - if (_pointerOverLine == visualLine.FirstDocumentLine.LineNumber) - context.DrawEllipse(_pointerOverBrush, _pointerOverPen, new Point(10, y), 8, 8); - else if (_markedDocumentLines.Contains(visualLine.FirstDocumentLine.LineNumber)) + if (_markedDocumentLines.Contains(visualLine.FirstDocumentLine.LineNumber)) context.DrawEllipse(_markerBrush, _markerPen, new Point(10, y), 8, 8); + else if (_pointerOverLine == visualLine.FirstDocumentLine.LineNumber) + context.DrawEllipse(_pointerOverBrush, _pointerOverPen, new Point(10, y), 8, 8); } }