Skip to content

Commit

Permalink
refactor(Studio): Tweak breakpoint commenting behaviour
Browse files Browse the repository at this point in the history
Now behaves like Studio v2
  • Loading branch information
psyGamer committed Sep 3, 2024
1 parent 0793246 commit 40f23d9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Studio/CelesteStudio/Editing/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2187,9 +2187,21 @@ private void OnToggleCommentBreakpoints() {
maxRow = Document.Lines.Count - 1;
}

// Only uncomment if all breakpoints are currently commented
// Otherwise just comment uncommented breakpoints
bool allCommented = true;
for (int row = minRow; row <= maxRow; row++) {
var line = Document.Lines[row];

if (UncommentedBreakpointRegex.IsMatch(line)) {
allCommented = false;
break;
}
}

for (int row = minRow; row <= maxRow; row++) {
var line = Document.Lines[row];
if (CommentedBreakpointRegex.IsMatch(line)) {
if (allCommented && CommentedBreakpointRegex.IsMatch(line)) {
int hashIdx = line.IndexOf('#');
Document.ReplaceLine(row, line.Remove(hashIdx, 1));

Expand All @@ -2200,7 +2212,7 @@ private void OnToggleCommentBreakpoints() {
Document.Selection.End.Col--;
if (row == Document.Caret.Row)
Document.Caret.Col--;
} else if (UncommentedBreakpointRegex.IsMatch(line)) {
} else if (!allCommented && UncommentedBreakpointRegex.IsMatch(line)) {
Document.ReplaceLine(row, $"#{line}");

// Shift everything over
Expand Down

0 comments on commit 40f23d9

Please sign in to comment.