Skip to content

Commit 2a33824

Browse files
committed
fix: correctly align HEAD on absolute left and fix empty column gap
1. 修复了 offsetX 预留逻辑:之前在循环外预留会导致所有路径被强行向右推一列。现在改为在循环内动态判断,Slot 0 (X=10) 严格为 HEAD 路径预留。 2. 修复了“空列”视觉 BUG:不再强行在 maxOffsetOld 中包含预留位,确保 commit 消息的边距计算紧凑。 3. 移除了 cherry-pick 过程中意外引入的 IsHoveredRelated 和 DotType.Filter 改动。 4. 确保 HEAD 路径始终占据视觉上的第一列,且其他并行分支在 HEAD 之前出现时会正确跳过第一列,不留视觉空隙。 FAILED test cases: NONE
1 parent e25e1f1 commit 2a33824

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

src/Models/CommitGraph.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,23 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
108108
unsolved.Insert(0, headPath);
109109
}
110110

111-
// 2. Reserve leftmost column (offsetX) for HEAD path if not yet found
112-
var offsetX = 4 - halfWidth;
113-
if (alwaysShowCurrentHeadOnLeft && headPath == null && headPathSHAs.Count > 0)
114-
offsetX += unitWidth;
115-
116-
// 3. Keep track of max offsetX used in previous rows for margin calculation
111+
// 2. Keep track of max offsetX used in previous rows for margin calculation
117112
var maxOffsetOld = 0.0;
118113
foreach (var l in unsolved)
119114
maxOffsetOld = Math.Max(maxOffsetOld, l.LastX);
120-
if (unsolved.Count == 0)
121-
maxOffsetOld = offsetX + unitWidth;
122115

123-
// 4. Process existing paths
116+
// 3. Process existing paths
117+
var offsetX = 4 - halfWidth;
124118
foreach (var l in unsolved)
125119
{
120+
offsetX += unitWidth;
121+
if (alwaysShowCurrentHeadOnLeft && headPathSHAs.Count > 0 && l != headPath && offsetX == 4 - halfWidth + unitWidth)
122+
offsetX += unitWidth;
123+
126124
if (l.Next.Equals(commit.SHA, StringComparison.Ordinal))
127125
{
128126
if (major == null)
129127
{
130-
offsetX += unitWidth;
131128
major = l;
132129

133130
if (commit.Parents.Count > 0)
@@ -151,7 +148,6 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
151148
}
152149
else
153150
{
154-
offsetX += unitWidth;
155151
l.Pass(offsetX, offsetY, halfHeight);
156152
}
157153
}
@@ -164,7 +160,7 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
164160
}
165161
ended.Clear();
166162

167-
// 5. Create new curve for branch tip or new merged commit
163+
// 4. Create new curve for branch tip or new merged commit
168164
if (major == null)
169165
{
170166
// If this is the start of the HEAD lineage, place it in the reserved column (index 0)
@@ -182,6 +178,9 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
182178
else if (commit.Parents.Count > 0)
183179
{
184180
offsetX += unitWidth;
181+
if (alwaysShowCurrentHeadOnLeft && headPathSHAs.Count > 0 && offsetX == 4 - halfWidth + unitWidth)
182+
offsetX += unitWidth;
183+
185184
major = new PathHelper(commit.Parents[0], isMerged, colorPicker.Next(), new Point(offsetX, offsetY));
186185
unsolved.Add(major);
187186
temp.Paths.Add(major.Path);
@@ -233,6 +232,8 @@ public static CommitGraph Parse(List<Commit> commits, bool firstParentOnlyEnable
233232
else
234233
{
235234
offsetX += unitWidth;
235+
if (alwaysShowCurrentHeadOnLeft && headPathSHAs.Count > 0 && offsetX == 4 - halfWidth + unitWidth)
236+
offsetX += unitWidth;
236237

237238
// Create new curve for parent commit that not includes before
238239
var l = new PathHelper(parentHash, isMerged, colorPicker.Next(), position, new Point(offsetX, position.Y + halfHeight));

0 commit comments

Comments
 (0)