Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix customMargin renders incorrectly when scrolling #444

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/AvaloniaEdit.Demo/CustomMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;

Expand Down Expand Up @@ -51,9 +52,16 @@ public CustomMargin()
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);
}
Expand All @@ -63,6 +71,12 @@ private void OnVisualLinesChanged(object? sender, EventArgs eventArgs)
InvalidateVisual();
}

private void OnDocumentChanged(object? sender, DocumentChangedEventArgs e)
{
_markedDocumentLines.Clear();
InvalidateVisual();
}

protected override Size MeasureOverride(Size availableSize)
{
return new Size(20, 0);
Expand All @@ -86,6 +100,7 @@ protected override void OnPointerMoved(PointerEventArgs e)
protected override void OnPointerExited(PointerEventArgs e)
{
_pointerOverLine = -1;
InvalidateVisual();

base.OnPointerExited(e);
}
Expand All @@ -112,12 +127,12 @@ public override void Render(DrawingContext context)
{
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);
}
}

Expand Down