diff --git a/editor/libeditor/DeleteRangeTransaction.cpp b/editor/libeditor/DeleteRangeTransaction.cpp index e2cf9d231682..470ed700f242 100644 --- a/editor/libeditor/DeleteRangeTransaction.cpp +++ b/editor/libeditor/DeleteRangeTransaction.cpp @@ -202,6 +202,39 @@ nsresult DeleteRangeTransaction::CreateTxnsToDeleteBetween( return NS_OK; } + if (mEditorBase->IsTextEditor()) { + // XXX(krosylight): We only want to delete anything within the text node in + // TextEditor, but there are things that still try deleting the text node + // itself (bug 1716714). Do this until we are 100% sure nothing does so. + MOZ_ASSERT(aStart.Container() == mEditorBase->GetRoot() && + aEnd.Container() == mEditorBase->GetRoot()); + MOZ_ASSERT( + aStart.Offset(RawRangeBoundary::OffsetFilter::kValidOffsets).value() == + 0); + MOZ_ASSERT( + aEnd.Offset(RawRangeBoundary::OffsetFilter::kValidOffsets).value() == + mEditorBase->GetRoot()->Length()); + + RefPtr textNode = + Text::FromNodeOrNull(aStart.Container()->GetFirstChild()); + MOZ_ASSERT(textNode); + + RefPtr deleteTextTransaction = + DeleteTextTransaction::MaybeCreate(*mEditorBase, *textNode, 0, + textNode->TextDataLength()); + // If the text node isn't editable, it should be never undone/redone. + // So, the transaction shouldn't be recorded. + if (!deleteTextTransaction) { + NS_WARNING("DeleteTextTransaction::MaybeCreate() failed"); + return NS_ERROR_FAILURE; + } + DebugOnly rvIgnored = AppendChild(deleteTextTransaction); + NS_WARNING_ASSERTION( + NS_SUCCEEDED(rvIgnored), + "DeleteRangeTransaction::AppendChild() failed, but ignored"); + return NS_OK; + } + // Even if we detect invalid range, we should ignore it for removing // specified range's nodes as far as possible. // XXX This is super expensive. Probably, we should make diff --git a/editor/libeditor/tests/mochitest.ini b/editor/libeditor/tests/mochitest.ini index 553913000a9c..b51a559c4463 100644 --- a/editor/libeditor/tests/mochitest.ini +++ b/editor/libeditor/tests/mochitest.ini @@ -314,6 +314,7 @@ skip-if = toolkit == 'android' [test_state_change_on_reframe.html] [test_textarea_value_not_include_cr.html] [test_texteditor_textnode.html] +[test_texteditor_tripleclick_setvalue.html] [test_typing_at_edge_of_anchor.html] [test_undo_after_spellchecker_replaces_word.html] skip-if = toolkit == 'android' diff --git a/editor/libeditor/tests/test_texteditor_tripleclick_setvalue.html b/editor/libeditor/tests/test_texteditor_tripleclick_setvalue.html new file mode 100644 index 000000000000..65ae2ce7e49a --- /dev/null +++ b/editor/libeditor/tests/test_texteditor_tripleclick_setvalue.html @@ -0,0 +1,27 @@ + + +Test for TextEditor triple click and SetValue + + + + +