A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Fix #242 - RegEx matches in multiline text don't highlight property (#381)
Etienne Baudoux0483499a3b87
diff --git a/src/dev/impl/DevToys/ViewModels/Tools/Text/RegEx/RegExToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/Text/RegEx/RegExToolViewModel.csindex de5d12bbb..1acad443b 100644--- a/src/dev/impl/DevToys/ViewModels/Tools/Text/RegEx/RegExToolViewModel.cs+++ b/src/dev/impl/DevToys/ViewModels/Tools/Text/RegEx/RegExToolViewModel.cs@@ -241,14 +241,15 @@ namespace DevToys.ViewModels.Tools.RegExstring? pattern = data.pattern.Trim('/');var regex = new Regex(data.pattern, GetOptions());- MatchCollection matches = regex.Matches(data.text.Replace("\r\n", "\r"));+ MatchCollection matches = regex.Matches(data.text);foreach (Match match in matches){+ int lineCount = CountLines(data.text, match.Index);spans.Add(new HighlightSpan(){- StartIndex = match.Index,+ StartIndex = match.Index - lineCount,Length = match.Length,BackgroundColor = highlighterBackgroundColor,ForegroundColor = highlighterForegroundColor@@ -311,5 +312,22 @@ namespace DevToys.ViewModels.Tools.RegExreturn options;}++ private int CountLines(string input, int maxLength)+ {+ int lines = 0;+ int i = 0;+ while (i > -1 && i < maxLength)+ {+ i = input.IndexOf("\r\n", startIndex: i);+ if (i > -1 && i < maxLength)+ {+ lines++;+ i++;+ }+ }++ return lines;+ }}}