Merge pull request #4137 from sbwalker/dev

fix #4134 - RichTextEditor scenarios
This commit is contained in:
Shaun Walker
2024-04-12 13:25:59 -04:00
committed by GitHub

View File

@ -109,12 +109,12 @@
private bool _richfilemanager = false; private bool _richfilemanager = false;
private FileManager _fileManager; private FileManager _fileManager;
private string _richhtml = string.Empty; private string _richhtml = string.Empty;
private string _originalrichhtml = string.Empty;
private bool _rawfilemanager = false; private bool _rawfilemanager = false;
private string _rawhtml = string.Empty; private string _rawhtml = string.Empty;
private string _originalrawhtml = string.Empty; private string _originalrawhtml = string.Empty;
private string _message = string.Empty; private string _message = string.Empty;
private string _activetab = "Rich"; private string _activetab = "Rich";
private bool _contentchanged = false;
[Parameter] [Parameter]
public string Content { get; set; } public string Content { get; set; }
@ -156,7 +156,7 @@
_richhtml = Content; _richhtml = Content;
_rawhtml = Content; _rawhtml = Content;
_originalrawhtml = _rawhtml; // preserve for comparison later _originalrawhtml = _rawhtml; // preserve for comparison later
_originalrichhtml = ""; _contentchanged = true;
if (!AllowRichText) if (!AllowRichText)
{ {
@ -181,24 +181,32 @@
Placeholder, Placeholder,
Theme, Theme,
DebugLevel); DebugLevel);
await interop.LoadEditorContent(_editorElement, _richhtml);
_initialized = true;
} }
else
if (_initialized)
{ {
if (!_richfilemanager) // do not override the content when the file manager is displayed if (_initialized)
{ {
await interop.LoadEditorContent(_editorElement, _richhtml); if (_contentchanged)
} {
// reload if content passed to component has changed
if (string.IsNullOrEmpty(_originalrichhtml)) await interop.LoadEditorContent(_editorElement, _richhtml);
{ }
// 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) else
_originalrichhtml = await interop.GetHtml(_editorElement); {
var richhtml = await interop.GetHtml(_editorElement);
if (richhtml != _richhtml)
{
await interop.LoadEditorContent(_editorElement, richhtml);
}
}
_contentchanged = false;
} }
} }
} }
_initialized = true; // ensures that the rich text editor is created before trying to access its methods
} }
public void CloseRichFileManager() public void CloseRichFileManager()
@ -224,23 +232,17 @@
} }
else else
{ {
var richhtml = "";
if (AllowRichText) if (AllowRichText)
{ {
// return rich text content if it has changed // return rich text content
var interop = new RichTextEditorInterop(JSRuntime); var interop = new RichTextEditorInterop(JSRuntime);
richhtml = await interop.GetHtml(_editorElement); return await interop.GetHtml(_editorElement);
} }
// rich text value will only be blank if AllowRichText is disabled or the JS Interop method failed else
if (richhtml != _originalrichhtml && !string.IsNullOrEmpty(richhtml) && !string.IsNullOrEmpty(_originalrichhtml)) {
{
return richhtml;
}
else
{
// return original raw html content // return original raw html content
return _originalrawhtml; return _originalrawhtml;
} }
} }
} }