Skip to content

Commit

Permalink
CompositorConfig // Drop invalid notes after changing MaxSpanLength.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Feb 13, 2025
1 parent 2ce18ab commit 9198bf4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Megrez/src/1_Compositor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,10 @@ public int Cursor {
/// </summary>
public int MaxSpanLength {
get => _maxSpanLength;
set => _maxSpanLength = Math.Max(6, value);
set {
_maxSpanLength = Math.Max(6, value);
DropNodesBeyondMaxSpanLength();
}
}

private int _marker = 0;
Expand Down Expand Up @@ -619,5 +622,20 @@ public void Clear() {
Cursor = 0;
Marker = 0;
}

/// <summary>
/// 清除所有幅長超過 MaxSpanLength 的節點。
/// </summary>
public void DropNodesBeyondMaxSpanLength() {
if (Spans.IsEmpty()) return;
var indicesOfPositions = new BRange(0, Spans.Count - 1).ToList();
foreach (int currentPos in indicesOfPositions) {
foreach (int currentSpanLength in Spans[currentPos].Nodes.Keys) {
if (currentSpanLength > MaxSpanLength) {
Spans[currentPos].Nodes.Remove(currentSpanLength);
}
}
}
}
}
} // namespace Megrez

0 comments on commit 9198bf4

Please sign in to comment.