This commit is contained in:
Daniel Peñalba 2024-07-29 10:38:02 +02:00
Родитель 144483e17d
Коммит 251c1a84fb
1 изменённых файлов: 19 добавлений и 4 удалений

Просмотреть файл

@ -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);
}
}