enhance: extends highlight area of selected/detected chunk to line number area

This commit is contained in:
leo 2024-07-26 10:18:28 +08:00
parent 1bff77cfcf
commit aae1c41dcd
No known key found for this signature in database

View file

@ -391,19 +391,13 @@ namespace SourceGit.Views
base.Render(context); base.Render(context);
var chunk = SelectedChunk; var chunk = SelectedChunk;
if (chunk == null || (!chunk.Combined && chunk.IsOldSide != IsOld) || chunk.Height == 0) if (chunk == null || (!chunk.Combined && chunk.IsOldSide != IsOld))
return;
var view = TextArea.TextView;
if (view == null || !view.VisualLinesValid)
return; return;
var color = (Color)this.FindResource("SystemAccentColor"); var color = (Color)this.FindResource("SystemAccentColor");
var brush = new SolidColorBrush(color, 0.1); var brush = new SolidColorBrush(color, 0.1);
var pen = new Pen(color.ToUInt32()); var pen = new Pen(color.ToUInt32());
var rect = new Rect(0, chunk.Y, Bounds.Width, chunk.Height);
var x = ((Point)view.TranslatePoint(new Point(0, 0), this)).X;
var rect = new Rect(x - 4, chunk.Y, view.Bounds.Width + 7, chunk.Height);
context.DrawRectangle(brush, null, rect); context.DrawRectangle(brush, null, rect);
context.DrawLine(pen, rect.TopLeft, rect.TopRight); context.DrawLine(pen, rect.TopLeft, rect.TopRight);
@ -683,28 +677,12 @@ namespace SourceGit.Views
var lastLineIdx = view.VisualLines[^1].FirstDocumentLine.LineNumber - 1; var lastLineIdx = view.VisualLines[^1].FirstDocumentLine.LineNumber - 1;
if (endIdx < firstLineIdx) if (endIdx < firstLineIdx)
{ {
TrySetChunk(new TextDiffViewChunk() TrySetChunk(null);
{
Y = 0,
Height = 0,
StartIdx = startIdx,
EndIdx = endIdx,
Combined = true,
IsOldSide = false,
});
return; return;
} }
else if (startIdx > lastLineIdx) else if (startIdx > lastLineIdx)
{ {
TrySetChunk(new TextDiffViewChunk() TrySetChunk(null);
{
Y = 0,
Height = 0,
StartIdx = startIdx,
EndIdx = endIdx,
Combined = true,
IsOldSide = false,
});
return; return;
} }
@ -877,32 +855,12 @@ namespace SourceGit.Views
var lastLineIdx = view.VisualLines[^1].FirstDocumentLine.LineNumber - 1; var lastLineIdx = view.VisualLines[^1].FirstDocumentLine.LineNumber - 1;
if (endIdx < firstLineIdx) if (endIdx < firstLineIdx)
{ {
diff.ConvertsToCombinedRange(parent.DataContext as Models.TextDiff, ref startIdx, ref endIdx, IsOld); TrySetChunk(null);
TrySetChunk(new TextDiffViewChunk()
{
Y = 0,
Height = 0,
StartIdx = startIdx,
EndIdx = endIdx,
Combined = false,
IsOldSide = IsOld,
});
return; return;
} }
else if (startIdx > lastLineIdx) else if (startIdx > lastLineIdx)
{ {
diff.ConvertsToCombinedRange(parent.DataContext as Models.TextDiff, ref startIdx, ref endIdx, IsOld); TrySetChunk(null);
TrySetChunk(new TextDiffViewChunk()
{
Y = 0,
Height = 0,
StartIdx = startIdx,
EndIdx = endIdx,
Combined = false,
IsOldSide = IsOld,
});
return; return;
} }
@ -1121,7 +1079,7 @@ namespace SourceGit.Views
SelectedChunkProperty.Changed.AddClassHandler<TextDiffView>((v, _) => SelectedChunkProperty.Changed.AddClassHandler<TextDiffView>((v, _) =>
{ {
var chunk = v.SelectedChunk; var chunk = v.SelectedChunk;
if (chunk == null || chunk.Height == 0) if (chunk == null)
{ {
v.Popup.IsVisible = false; v.Popup.IsVisible = false;
return; return;