Skip to content

Commit

Permalink
fix(Studio): Anchors being updated incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Dec 14, 2024
1 parent 70cb1da commit b3a2a9c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Studio/CelesteStudio/Editing/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ public void ReplaceLines(int row, string[] newLines) {
break;
}

int newLineCount = newLines.Length > 0 ? newLines.Length - 1 : 0;
if (Caret.Row >= row) {
int newLineCount = newLines.Length > 0 ? newLines.Length-1 : 0;
Caret.Row += newLineCount;
}

Expand All @@ -876,12 +876,16 @@ public void ReplaceLines(int row, string[] newLines) {
anchor.OnRemoved?.Invoke();
}
}

// Move anchors below down
if (newLineCount == 0) {
return;
}
for (int currRow = CurrentLines.Count - 1; currRow > row + 1 ; currRow--) {
if (CurrentAnchors.Remove(currRow, out var belowAnchors)) {
CurrentAnchors[currRow + newLines.Length - 2] = belowAnchors;
CurrentAnchors[currRow + newLineCount] = belowAnchors;
foreach (var anchor in belowAnchors) {
anchor.Row += newLines.Length - 2;
anchor.Row += newLineCount;
}
}
}
Expand Down

0 comments on commit b3a2a9c

Please sign in to comment.