Skip to content

Commit 6f8396b

Browse files
committed
fix: allow merging with checkboxes if one side all lines are removed
1 parent 99a435a commit 6f8396b

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎src/Models/Conflict.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23

34
namespace SourceGit.Models
@@ -91,6 +92,10 @@ public class ConflictRegion
9192
public List<string> OursContent { get; set; } = new();
9293
public List<string> TheirsContent { get; set; } = new();
9394

95+
// An empty side still takes one (placeholder) row in its panel, so that it can be picked.
96+
public int OursRowCount => Math.Max(OursContent.Count, 1);
97+
public int TheirsRowCount => Math.Max(TheirsContent.Count, 1);
98+
9499
public List<ConflictPick> Picks { get; set; } = new();
95100
public bool HasChoice { get; set; } = false;
96101
public bool IsCustom { get; set; } = false;

‎src/ViewModels/MergeConflictEditor.cs‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public Models.ConflictLineDecoration GetSideLineDecoration(Models.ConflictPanelT
154154
return default;
155155

156156
var r = _conflictRegions[info.RegionIndex];
157-
var count = side == Models.ConflictPanelType.Ours ? r.OursContent.Count : r.TheirsContent.Count;
157+
var count = side == Models.ConflictPanelType.Ours ? r.OursRowCount : r.TheirsRowCount;
158158
return new(Models.ConflictLineType.None, true, r.IsResolved, info.IndexInSide == 0, info.IndexInSide == count - 1);
159159
}
160160

@@ -188,8 +188,8 @@ public int FindRegionByResultLine(int line)
188188
var r = _conflictRegions[regionIdx];
189189
return panel switch
190190
{
191-
Models.ConflictPanelType.Ours => (r.OursFirst, r.OursContent.Count),
192-
Models.ConflictPanelType.Theirs => (r.TheirsFirst, r.TheirsContent.Count),
191+
Models.ConflictPanelType.Ours => (r.OursFirst, r.OursRowCount),
192+
Models.ConflictPanelType.Theirs => (r.TheirsFirst, r.TheirsRowCount),
193193
_ => (_ranges[regionIdx].FirstLine, _ranges[regionIdx].LineCount),
194194
};
195195
}
@@ -413,6 +413,9 @@ private void ParseOriginalContent(string content)
413413
i++;
414414
}
415415

416+
if (region.OursContent.Count == 0)
417+
oursLines.Add(new(Models.ConflictLineType.None, string.Empty) { RegionIndex = regionIdx, IndexInSide = 0 });
418+
416419
// Skip diff3 base section if present
417420
if (i < lines.Length && lines[i].StartsWith("|||||||", StringComparison.Ordinal))
418421
{
@@ -437,6 +440,9 @@ private void ParseOriginalContent(string content)
437440
i++;
438441
}
439442

443+
if (region.TheirsContent.Count == 0)
444+
theirsLines.Add(new(Models.ConflictLineType.None, string.Empty) { RegionIndex = regionIdx, IndexInSide = 0 });
445+
440446
// Capture end marker (e.g., ">>>>>>> feature-branch")
441447
if (i < lines.Length && lines[i].StartsWith(">>>>>>>", StringComparison.Ordinal))
442448
{
@@ -510,7 +516,13 @@ private List<string> ComposeRegion(Models.ConflictRegion r, List<Models.Conflict
510516
foreach (var pick in r.Picks)
511517
{
512518
var isOurs = pick.Side == Models.ConflictPanelType.Ours;
513-
lines.Add(isOurs ? r.OursContent[pick.Index] : r.TheirsContent[pick.Index]);
519+
var content = isOurs ? r.OursContent : r.TheirsContent;
520+
521+
// The placeholder row of an empty side contributes no lines.
522+
if (pick.Index >= content.Count)
523+
continue;
524+
525+
lines.Add(content[pick.Index]);
514526
types.Add(isOurs ? Models.ConflictLineType.Ours : Models.ConflictLineType.Theirs);
515527
}
516528

@@ -566,7 +578,7 @@ private void ApplyRegion(int regionIdx)
566578

567579
private void AddAllPicks(Models.ConflictRegion r, Models.ConflictPanelType side)
568580
{
569-
var count = side == Models.ConflictPanelType.Ours ? r.OursContent.Count : r.TheirsContent.Count;
581+
var count = side == Models.ConflictPanelType.Ours ? r.OursRowCount : r.TheirsRowCount;
570582
for (var i = 0; i < count; i++)
571583
r.Picks.Add(new(side, i));
572584
}

‎src/Views/MergeConflictEditor.axaml.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ public override void Render(DrawingContext context)
893893
foreach (var c in conflicts)
894894
{
895895
var topY = c.OursFirst * unitHeight;
896-
var bottomY = topY + Math.Max(c.OursContent.Count * unitHeight, 2);
896+
var bottomY = topY + Math.Max(c.OursRowCount * unitHeight, 2);
897897
var bg = blockBGs[c.IsResolved ? 1 : 0];
898898
context.DrawRectangle(bg, null, new Rect(0, topY, Bounds.Width, bottomY - topY));
899899
}
@@ -1147,7 +1147,7 @@ private void OnCollapseUnchangedChanged(object sender, RoutedEventArgs e)
11471147
}
11481148

11491149
if (!isEnd)
1150-
gapStart = region.OursFirst + region.OursContent.Count;
1150+
gapStart = region.OursFirst + region.OursRowCount;
11511151
}
11521152
}
11531153

0 commit comments

Comments
 (0)