mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 21:30:37 +08:00
fix: last line change may disable hunk operation in side-by-side diff (#2027)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -223,7 +223,7 @@ namespace SourceGit.ViewModels
|
||||
return new CombinedTextDiff(_option, _data, this);
|
||||
}
|
||||
|
||||
public void ConvertsToCombinedRange(ref int startLine, ref int endLine, bool isOldSide)
|
||||
public void GetCombinedRangeForSingleSide(ref int startLine, ref int endLine, bool isOldSide)
|
||||
{
|
||||
endLine = Math.Min(endLine, _data.Lines.Count - 1);
|
||||
|
||||
@@ -262,6 +262,32 @@ namespace SourceGit.ViewModels
|
||||
endLine = _data.Lines.IndexOf(endContent);
|
||||
}
|
||||
|
||||
public void GetCombinedRangeForBothSides(ref int startLine, ref int endLine, bool isOldSide)
|
||||
{
|
||||
var fromSide = isOldSide ? Old : New;
|
||||
endLine = Math.Min(endLine, fromSide.Count - 1);
|
||||
|
||||
// Since this function is only used for auto-detected hunk, we just need to find out the a first changed line
|
||||
// and then use `FindRangeByIndex` to get the range of hunk.
|
||||
for (int i = startLine; i <= endLine; i++)
|
||||
{
|
||||
var line = fromSide[i];
|
||||
if (line.Type == Models.TextDiffLineType.Added || line.Type == Models.TextDiffLineType.Deleted)
|
||||
{
|
||||
(startLine, endLine) = FindRangeByIndex(_data.Lines, _data.Lines.IndexOf(line));
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.Type == Models.TextDiffLineType.None)
|
||||
{
|
||||
var otherSide = isOldSide ? New : Old;
|
||||
var changedLine = otherSide[i]; // Find the changed line on the other side in the same position
|
||||
(startLine, endLine) = FindRangeByIndex(_data.Lines, _data.Lines.IndexOf(changedLine));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FillEmptyLines()
|
||||
{
|
||||
if (Old.Count < New.Count)
|
||||
|
||||
@@ -1183,7 +1183,7 @@ namespace SourceGit.Views
|
||||
endLine.GetTextLineVisualYPosition(endLine.TextLines[^1], VisualYPosition.TextBottom) - view.VerticalOffset :
|
||||
view.Bounds.Height;
|
||||
|
||||
diff.ConvertsToCombinedRange(ref startIdx, ref endIdx, IsOld);
|
||||
diff.GetCombinedRangeForSingleSide(ref startIdx, ref endIdx, IsOld);
|
||||
TrySetChunk(new(rectStartY, rectEndY - rectStartY, startIdx, endIdx, false, IsOld));
|
||||
}
|
||||
else
|
||||
@@ -1229,7 +1229,7 @@ namespace SourceGit.Views
|
||||
endLine.GetTextLineVisualYPosition(endLine.TextLines[^1], VisualYPosition.TextBottom) - view.VerticalOffset :
|
||||
view.Bounds.Height;
|
||||
|
||||
diff.ConvertsToCombinedRange(ref startIdx, ref endIdx, IsOld);
|
||||
diff.GetCombinedRangeForBothSides(ref startIdx, ref endIdx, IsOld);
|
||||
TrySetChunk(new(rectStartY, rectEndY - rectStartY, startIdx, endIdx, true, false));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user