From 220fae9fe5585e252f0f10967d0c6a1ee0b4655f Mon Sep 17 00:00:00 2001 From: Alexandre Zollinger Chohfi Date: Wed, 6 Nov 2024 12:25:50 -0800 Subject: [PATCH 1/3] Fixed possible NRE on MarkdownTextBlock. --- .../src/MarkdownTextBlock.xaml.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs b/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs index b3b984797..efba3cb4b 100644 --- a/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs +++ b/components/MarkdownTextBlock/src/MarkdownTextBlock.xaml.cs @@ -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); } } @@ -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); + } } } @@ -109,7 +113,7 @@ private void Build() _renderer = new WinUIRenderer(_document, Config); } _pipeline.Setup(_renderer); - ApplyText(Text, false); + ApplyText(false); } } } From 40e24a546e5630aadcfd11515446deeffcf51e65 Mon Sep 17 00:00:00 2001 From: Alexandre Zollinger Chohfi Date: Mon, 11 Nov 2024 14:15:05 -0800 Subject: [PATCH 2/3] Added test. --- .../ExampleMarkdownTextBlockTestClass.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs b/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs index 19eef0a75..e46bc89c4 100644 --- a/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs +++ b/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs @@ -131,4 +131,27 @@ public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() Assert.IsFalse(component.IsLoaded); } + + // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: + [TestMethod] + public async Task ComplexAsyncLoadUIExampleWithCustomConfigTest() + { + await EnqueueAsync(async () => + { + var component = new MarkdownTextBlock + { + Config = new MarkdownConfig() + }; + Assert.IsNotNull(component); + Assert.IsFalse(component.IsLoaded); + + await LoadTestContentAsync(component); + + Assert.IsTrue(component.IsLoaded); + + await UnloadTestContentAsync(component); + + Assert.IsFalse(component.IsLoaded); + }); + } } From 09d917ea8cbf8a146752bf69fbd75071228063ff Mon Sep 17 00:00:00 2001 From: Arlo Godfrey Date: Wed, 13 Nov 2024 14:14:45 -0600 Subject: [PATCH 3/3] Cleanup new test case --- .../ExampleMarkdownTextBlockTestClass.cs | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs b/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs index e46bc89c4..2c7db300d 100644 --- a/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs +++ b/components/MarkdownTextBlock/tests/ExampleMarkdownTextBlockTestClass.cs @@ -132,26 +132,21 @@ public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() Assert.IsFalse(component.IsLoaded); } - // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: - [TestMethod] - public async Task ComplexAsyncLoadUIExampleWithCustomConfigTest() + [UIThreadTestMethod] + public async Task MarkdownTextBlockEmptyTextValueTest() { - await EnqueueAsync(async () => + var component = new MarkdownTextBlock { - var component = new MarkdownTextBlock - { - Config = new MarkdownConfig() - }; - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); + Config = new() + }; - Assert.IsTrue(component.IsLoaded); + Assert.IsNotNull(component); + Assert.IsFalse(component.IsLoaded); - await UnloadTestContentAsync(component); + await LoadTestContentAsync(component); + Assert.IsTrue(component.IsLoaded); - Assert.IsFalse(component.IsLoaded); - }); + await UnloadTestContentAsync(component); + Assert.IsFalse(component.IsLoaded); } }