Bug 1953933 - Make TextEditor::IsEmpty() return true if it's not been initialized yet r=m_kato
`GetTextNode()` requires that the instance has already been initialized since it requires the native anonymous `<div>`. And `IsEmpty()` is a public method. Therefore, it should return `true` if there is no editor root, i.e., when it's not been initialized yet after creation or destroyed. Additionally, `TextControlState::GetValue()` should call `TextEditor::ComputeTextValue()` if the editor has not been initialized because it requires the native anonymous subtree to compute the value. I'm not sure whether this is a bug when `<textarea>` is being initialized. (I guess that it should get the default value of the text control element or `mValue` in the case, but we should do that in another bug separately.) I couldn't find the crash testcase, so, this does not contain a new test. Differential Revision: https://phabricator.services.mozilla.com/D241543
This commit is contained in:
@@ -2537,7 +2537,9 @@ void TextControlState::GetValue(nsAString& aValue, bool aIgnoreWrap,
|
|||||||
// XXXbz if we could just get the textContent of our anonymous content (eg
|
// XXXbz if we could just get the textContent of our anonymous content (eg
|
||||||
// if plaintext editor didn't create <br> nodes all over), we wouldn't need
|
// if plaintext editor didn't create <br> nodes all over), we wouldn't need
|
||||||
// this.
|
// this.
|
||||||
{ /* Scope for AutoNoJSAPI. */
|
// XXX If mTextEditor has not been initialized yet, ComputeTextValue()
|
||||||
|
// anyway returns empty string. Is this always expected here?
|
||||||
|
if (mEditorInitialized) {
|
||||||
AutoNoJSAPI nojsapi;
|
AutoNoJSAPI nojsapi;
|
||||||
|
|
||||||
DebugOnly<nsresult> rv = mTextEditor->ComputeTextValue(flags, aValue);
|
DebugOnly<nsresult> rv = mTextEditor->ComputeTextValue(flags, aValue);
|
||||||
|
|||||||
@@ -480,6 +480,17 @@ already_AddRefed<Element> TextEditor::GetInputEventTargetElement() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool TextEditor::IsEmpty() const {
|
bool TextEditor::IsEmpty() const {
|
||||||
|
// This is a public method. Therefore, it might have not been initialized yet
|
||||||
|
// when this is called. Let's return true in such case, but warn it because
|
||||||
|
// it may return different value than actual value which is stored by the
|
||||||
|
// text control element.
|
||||||
|
MOZ_ASSERT_IF(mInitSucceeded, GetRoot());
|
||||||
|
if (NS_WARN_IF(!GetRoot())) {
|
||||||
|
NS_ASSERTION(false,
|
||||||
|
"Make the root caller stop doing that before initializing or "
|
||||||
|
"after destroying the TextEditor");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
const Text* const textNode = GetTextNode();
|
const Text* const textNode = GetTextNode();
|
||||||
MOZ_DIAGNOSTIC_ASSERT_IF(textNode,
|
MOZ_DIAGNOSTIC_ASSERT_IF(textNode,
|
||||||
!Text::FromNodeOrNull(textNode->GetNextSibling()));
|
!Text::FromNodeOrNull(textNode->GetNextSibling()));
|
||||||
|
|||||||
Reference in New Issue
Block a user