fix https://github.com/oqtane/oqtane.blogs/issues/44 - rich text editor throwing exception in specific scenario

This commit is contained in:
sbwalker
2024-04-11 09:03:41 -04:00
parent b898c90f41
commit 83543bbddc

View File

@ -63,8 +63,7 @@
</span> </span>
} }
</div> </div>
<div @ref="@_editorElement"> <div @ref="@_editorElement"></div>
</div>
</div> </div>
</div> </div>
</TabPanel> </TabPanel>
@ -104,6 +103,7 @@
</div> </div>
@code { @code {
private bool _initialized = false;
private ElementReference _editorElement; private ElementReference _editorElement;
private ElementReference _toolBar; private ElementReference _toolBar;
private bool _richfilemanager = false; private bool _richfilemanager = false;
@ -178,19 +178,24 @@
DebugLevel); DebugLevel);
} }
if (!_richfilemanager) if (_initialized)
{
if (!_richfilemanager) // do not override the content when the file manager is displayed
{ {
await interop.LoadEditorContent(_editorElement, _richhtml); await interop.LoadEditorContent(_editorElement, _richhtml);
} }
if (string.IsNullOrEmpty(_originalrichhtml)) if (string.IsNullOrEmpty(_originalrichhtml))
{ {
// preserve a copy of the rich text content (Quill sanitizes content so we need to retrieve it from the editor) // preserve a copy of the rich text content (Quill sanitizes content so we need to retrieve it from the editor as it may have changed)
_originalrichhtml = await interop.GetHtml(_editorElement); _originalrichhtml = await interop.GetHtml(_editorElement);
} }
} }
} }
_initialized = true; // ensures that the rich text editor is created before trying to access its methods
}
public void CloseRichFileManager() public void CloseRichFileManager()
{ {
_richfilemanager = false; _richfilemanager = false;