לא בדקתי את הכל, אבל יש לי שיפור לרג'קס במתודה updateText
private void UpdateText()
{
Inlines.Clear();
string pattern = @"(<([bi])>(.*)</\1>)"; // Example pattern for bold and italic tags
int lastPos = 0;
var matches = Regex.Matches(HighlightedText, pattern);
foreach (Match match in matches)
{
// Add text before the match
if (match.Index > lastPos)
{
Inlines.Add(new Run(HighlightedText.Substring(lastPos, match.Index - lastPos)));
}
Inlines.Add(match.Groups[1].Value switch
{
"b" => new Bold(new Run(match.Groups[2].Value)),
"i" => new Italic(new Run(match.Groups[2].Value)),
});
lastPos = match.Index + match.Length;
}
// Add remaining text after the last match
if (lastPos < HighlightedText.Length)
{
Inlines.Add(new Run(HighlightedText.Substring(lastPos)));
}
}