Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed possible NRE on MarkdownTextBlock. #586

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedE
{
if (d is MarkdownTextBlock self && e.NewValue != null)
{
self.ApplyText(self.Text, true);
self.ApplyText(true);
}
}

Expand Down Expand Up @@ -87,16 +87,20 @@ private void ApplyConfig(MarkdownConfig config)
}
}

private void ApplyText(string text, bool rerender)
private void ApplyText(bool rerender)
{
var markdown = Markdown.Parse(text, _pipeline);
if (_renderer != null)
{
if (rerender)
{
_renderer.ReloadDocument();
}
_renderer.Render(markdown);

if (!string.IsNullOrEmpty(Text))
{
var markdown = Markdown.Parse(Text, _pipeline);
_renderer.Render(markdown);
}
}
}

Expand All @@ -109,7 +113,7 @@ private void Build()
_renderer = new WinUIRenderer(_document, Config);
}
_pipeline.Setup(_renderer);
ApplyText(Text, false);
ApplyText(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,22 @@ public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest()

Assert.IsFalse(component.IsLoaded);
}

[UIThreadTestMethod]
public async Task MarkdownTextBlockEmptyTextValueTest()
{
var component = new MarkdownTextBlock
{
Config = new()
};

Assert.IsNotNull(component);
Assert.IsFalse(component.IsLoaded);

await LoadTestContentAsync(component);
Assert.IsTrue(component.IsLoaded);

await UnloadTestContentAsync(component);
Assert.IsFalse(component.IsLoaded);
}
}
Loading