enhance: only re-calculate highlight chunk when it is needed

This commit is contained in:
leo 2024-09-29 13:48:48 +08:00
parent e945367b28
commit d5671ea8df
No known key found for this signature in database

View file

@ -437,8 +437,8 @@ namespace SourceGit.Views
base.OnLoaded(e); base.OnLoaded(e);
TextArea.TextView.ContextRequested += OnTextViewContextRequested; TextArea.TextView.ContextRequested += OnTextViewContextRequested;
TextArea.TextView.PointerEntered += OnTextViewPointerEntered; TextArea.TextView.PointerEntered += OnTextViewPointerChanged;
TextArea.TextView.PointerMoved += OnTextViewPointerMoved; TextArea.TextView.PointerMoved += OnTextViewPointerChanged;
TextArea.TextView.PointerWheelChanged += OnTextViewPointerWheelChanged; TextArea.TextView.PointerWheelChanged += OnTextViewPointerWheelChanged;
UpdateTextMate(); UpdateTextMate();
@ -449,8 +449,8 @@ namespace SourceGit.Views
base.OnUnloaded(e); base.OnUnloaded(e);
TextArea.TextView.ContextRequested -= OnTextViewContextRequested; TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
TextArea.TextView.PointerEntered -= OnTextViewPointerEntered; TextArea.TextView.PointerEntered -= OnTextViewPointerChanged;
TextArea.TextView.PointerMoved -= OnTextViewPointerMoved; TextArea.TextView.PointerMoved -= OnTextViewPointerChanged;
TextArea.TextView.PointerWheelChanged -= OnTextViewPointerWheelChanged; TextArea.TextView.PointerWheelChanged -= OnTextViewPointerWheelChanged;
if (_textMate != null) if (_textMate != null)
@ -510,10 +510,19 @@ namespace SourceGit.Views
e.Handled = true; e.Handled = true;
} }
private void OnTextViewPointerEntered(object sender, PointerEventArgs e) private void OnTextViewPointerChanged(object sender, PointerEventArgs e)
{ {
if (EnableChunkSelection && sender is TextView view) if (EnableChunkSelection && sender is TextView view)
{ {
var selection = TextArea.Selection;
if (selection == null || selection.IsEmpty)
{
if (_lastSelectStart != _lastSelectEnd)
{
_lastSelectStart = TextLocation.Empty;
_lastSelectEnd = TextLocation.Empty;
}
var chunk = SelectedChunk; var chunk = SelectedChunk;
if (chunk != null) if (chunk != null)
{ {
@ -523,21 +532,20 @@ namespace SourceGit.Views
} }
UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset); UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset);
}
}
private void OnTextViewPointerMoved(object sender, PointerEventArgs e)
{
if (EnableChunkSelection && sender is TextView view)
{
var chunk = SelectedChunk;
if (chunk != null)
{
var rect = new Rect(0, chunk.Y, Bounds.Width, chunk.Height);
if (rect.Contains(e.GetPosition(this)))
return; return;
} }
var start = selection.StartPosition.Location;
var end = selection.EndPosition.Location;
if (_lastSelectStart != start || _lastSelectEnd != end)
{
_lastSelectStart = start;
_lastSelectEnd = end;
UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset);
return;
}
if (SelectedChunk == null)
UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset); UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset);
} }
} }
@ -657,7 +665,9 @@ namespace SourceGit.Views
} }
private TextMate.Installation _textMate = null; private TextMate.Installation _textMate = null;
protected LineStyleTransformer _lineStyleTransformer = null; private TextLocation _lastSelectStart = TextLocation.Empty;
private TextLocation _lastSelectEnd = TextLocation.Empty;
private LineStyleTransformer _lineStyleTransformer = null;
} }
public class CombinedTextDiffPresenter : ThemedTextDiffPresenter public class CombinedTextDiffPresenter : ThemedTextDiffPresenter