mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-25 03:12:21 +08:00
feature: allow to scroll text diff view to clicked position in minimap bar (#1679)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
<ContentControl Content="{Binding}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="vm:CombinedTextDiff">
|
||||
<Grid ColumnDefinitions="*,1,8">
|
||||
<Grid ColumnDefinitions="*,1,12">
|
||||
<v:CombinedTextDiffPresenter Grid.Column="0"
|
||||
FileName="{Binding File}"
|
||||
Foreground="{DynamicResource Brush.FG1}"
|
||||
|
||||
@@ -1334,6 +1334,8 @@ namespace SourceGit.Views
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
context.DrawRectangle(Brushes.Transparent, null, new Rect(0, 0, Bounds.Width, Bounds.Height));
|
||||
|
||||
var total = 0;
|
||||
if (DataContext is ViewModels.TwoSideTextDiff twoSideDiff)
|
||||
{
|
||||
@@ -1371,6 +1373,42 @@ namespace SourceGit.Views
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
{
|
||||
base.OnPointerPressed(e);
|
||||
|
||||
var range = DisplayRange;
|
||||
if (range == null || range.End == 0)
|
||||
return;
|
||||
|
||||
var total = 0;
|
||||
if (DataContext is ViewModels.TwoSideTextDiff twoSideDiff)
|
||||
{
|
||||
var halfWidth = Bounds.Width * 0.5;
|
||||
total = Math.Max(twoSideDiff.Old.Count, twoSideDiff.New.Count);
|
||||
}
|
||||
else if (DataContext is ViewModels.CombinedTextDiff combined)
|
||||
{
|
||||
var data = combined.Data;
|
||||
total = data.Lines.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var height = Bounds.Height;
|
||||
var startY = range.Start / (total * 1.0) * height;
|
||||
var endY = range.End / (total * 1.0) * height;
|
||||
var pressedY = e.GetPosition(this).Y;
|
||||
if (pressedY >= startY && pressedY <= endY)
|
||||
return;
|
||||
|
||||
var line = Math.Max(1, Math.Min(total, (int)Math.Ceiling(pressedY * total / height)));
|
||||
this.FindAncestorOfType<TextDiffView>()?.ScrollToLine(line);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void RenderSingleSide(DrawingContext context, List<Models.TextDiffLine> lines, double x, double width)
|
||||
{
|
||||
var total = lines.Count;
|
||||
@@ -1414,11 +1452,17 @@ namespace SourceGit.Views
|
||||
get => GetValue(SelectedChunkProperty);
|
||||
set => SetValue(SelectedChunkProperty, value);
|
||||
}
|
||||
|
||||
public TextDiffView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void ScrollToLine(int line)
|
||||
{
|
||||
this.FindDescendantOfType<ThemedTextDiffPresenter>()?.ScrollToLine(line);
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
Reference in New Issue
Block a user