Skip to content

Commit

Permalink
revert(Studio): "Fix using labels when toggling comment"
Browse files Browse the repository at this point in the history
This reverts commit b070aaf.
  • Loading branch information
psyGamer committed Oct 8, 2024
1 parent 2e49d47 commit 10d3621
Showing 1 changed file with 45 additions and 63 deletions.
108 changes: 45 additions & 63 deletions Studio/CelesteStudio/Editing/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2832,32 +2832,26 @@ private void OnToggleCommentBreakpoints() {
for (int row = minRow; row <= maxRow; row++) {
var line = Document.Lines[row];
if (allCommented && CommentedBreakpointRegex.IsMatch(line)) {
int hashIdx = line.IndexOf("# ", StringComparison.Ordinal);
Document.ReplaceLine(row, line.Remove(hashIdx, "# ".Length));
int hashIdx = line.IndexOf('#');
Document.ReplaceLine(row, line.Remove(hashIdx, 1));

// Shift everything over
if (row == minRow) {
Document.Selection.Start.Col -= "# ".Length;
}
if (row == maxRow) {
Document.Selection.End.Col -= "# ".Length;
}
if (row == Document.Caret.Row) {
Document.Caret.Col -= "# ".Length;
}
if (row == minRow)
Document.Selection.Start.Col--;
if (row == maxRow)
Document.Selection.End.Col--;
if (row == Document.Caret.Row)
Document.Caret.Col--;
} else if (!allCommented && UncommentedBreakpointRegex.IsMatch(line)) {
Document.ReplaceLine(row, $"# {line}");
Document.ReplaceLine(row, $"#{line}");

// Shift everything over
if (row == minRow) {
Document.Selection.Start.Col += "# ".Length;
}
if (row == maxRow) {
Document.Selection.End.Col += "# ".Length;
}
if (row == Document.Caret.Row) {
Document.Caret.Col += "# ".Length;
}
if (row == minRow)
Document.Selection.Start.Col++;
if (row == maxRow)
Document.Selection.End.Col++;
if (row == Document.Caret.Row)
Document.Caret.Col++;
}
}

Expand Down Expand Up @@ -2895,32 +2889,26 @@ private void OnToggleCommentInputs() {
continue;
}

int hashIdx = line.IndexOf("# ", StringComparison.Ordinal);
Document.ReplaceLine(row, line.Remove(hashIdx, "# ".Length));
int hashIdx = line.IndexOf('#');
Document.ReplaceLine(row, line.Remove(hashIdx, 1));

// Shift everything over
if (row == minRow) {
Document.Selection.Start.Col -= "# ".Length;
}
if (row == maxRow) {
Document.Selection.End.Col -= "# ".Length;
}
if (row == Document.Caret.Row) {
Document.Caret.Col -= "# ".Length;
}
if (row == minRow)
Document.Selection.Start.Col--;
if (row == maxRow)
Document.Selection.End.Col--;
if (row == Document.Caret.Row)
Document.Caret.Col--;
} else {
Document.ReplaceLine(row, $"# {line}");
Document.ReplaceLine(row, $"#{line}");

// Shift everything over
if (row == minRow) {
Document.Selection.Start.Col += "# ".Length;
}
if (row == maxRow) {
Document.Selection.End.Col += "# ".Length;
}
if (row == Document.Caret.Row) {
Document.Caret.Col += "# ".Length;
}
if (row == minRow)
Document.Selection.Start.Col++;
if (row == maxRow)
Document.Selection.End.Col++;
if (row == Document.Caret.Row)
Document.Caret.Col++;
}
}

Expand Down Expand Up @@ -2956,32 +2944,26 @@ private void OnToggleCommentText() {
var line = Document.Lines[row];

if (allCommented) {
int hashIdx = line.IndexOf("# ", StringComparison.Ordinal);
Document.ReplaceLine(row, line.Remove(hashIdx, "# ".Length));
int hashIdx = line.IndexOf('#');
Document.ReplaceLine(row, line.Remove(hashIdx, 1));

// Shift everything over
if (row == minRow) {
Document.Selection.Start.Col -= "# ".Length;
}
if (row == maxRow) {
Document.Selection.End.Col -= "# ".Length;
}
if (row == Document.Caret.Row) {
Document.Caret.Col -= "# ".Length;
}
if (row == minRow)
Document.Selection.Start.Col--;
if (row == maxRow)
Document.Selection.End.Col--;
if (row == Document.Caret.Row)
Document.Caret.Col--;
} else {
Document.ReplaceLine(row, $"# {line}");
Document.ReplaceLine(row, $"#{line}");

// Shift everything over
if (row == minRow) {
Document.Selection.Start.Col += "# ".Length;
}
if (row == maxRow) {
Document.Selection.End.Col += "# ".Length;
}
if (row == Document.Caret.Row) {
Document.Caret.Col += "# ".Length;
}
if (row == minRow)
Document.Selection.Start.Col++;
if (row == maxRow)
Document.Selection.End.Col++;
if (row == Document.Caret.Row)
Document.Caret.Col++;
}
}

Expand Down

0 comments on commit 10d3621

Please sign in to comment.