diff --git a/SkEditor/Views/RefactorWindow.axaml.cs b/SkEditor/Views/RefactorWindow.axaml.cs index 2c00533..98fc7f3 100644 --- a/SkEditor/Views/RefactorWindow.axaml.cs +++ b/SkEditor/Views/RefactorWindow.axaml.cs @@ -43,20 +43,36 @@ private static async Task RemoveComments() private static string RemoveMultiLineComments(string text) { - var CommentChar = "###"; + var commentChar = "###"; int startIndex = 0; - while ((startIndex = text.IndexOf(CommentChar, startIndex)) != -1) + while ((startIndex = text.IndexOf(commentChar, startIndex)) != -1) { - int endIndex = text.IndexOf(CommentChar, startIndex + CommentChar.Length); + int endIndex = text.IndexOf(commentChar, startIndex + commentChar.Length); if (endIndex == -1) break; - endIndex += CommentChar.Length; + if (IsInsideQuotes(text, startIndex)) + { + startIndex = endIndex + commentChar.Length; + continue; + } + + endIndex += commentChar.Length; text = text.Remove(startIndex, endIndex - startIndex); } return text; } + private static bool IsInsideQuotes(string text, int index) + { + int quoteCount = 0; + for (int i = 0; i < index; i++) + { + if (text[i] == '"') quoteCount++; + } + return (quoteCount % 2 != 0); + } + private static string RemoveSingleLineComments(string text) { var lines = text.Split('\n');