зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1713334 - Part 6: Actively prevent text deletion in DeleteRangeTransaction r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D118239
This commit is contained in:
Родитель
2de7595469
Коммит
3f6f05b7eb
|
@ -202,6 +202,39 @@ nsresult DeleteRangeTransaction::CreateTxnsToDeleteBetween(
|
||||||
return NS_OK;
|
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<Text> textNode =
|
||||||
|
Text::FromNodeOrNull(aStart.Container()->GetFirstChild());
|
||||||
|
MOZ_ASSERT(textNode);
|
||||||
|
|
||||||
|
RefPtr<DeleteTextTransaction> 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<nsresult> 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
|
// Even if we detect invalid range, we should ignore it for removing
|
||||||
// specified range's nodes as far as possible.
|
// specified range's nodes as far as possible.
|
||||||
// XXX This is super expensive. Probably, we should make
|
// XXX This is super expensive. Probably, we should make
|
||||||
|
|
|
@ -314,6 +314,7 @@ skip-if = toolkit == 'android'
|
||||||
[test_state_change_on_reframe.html]
|
[test_state_change_on_reframe.html]
|
||||||
[test_textarea_value_not_include_cr.html]
|
[test_textarea_value_not_include_cr.html]
|
||||||
[test_texteditor_textnode.html]
|
[test_texteditor_textnode.html]
|
||||||
|
[test_texteditor_tripleclick_setvalue.html]
|
||||||
[test_typing_at_edge_of_anchor.html]
|
[test_typing_at_edge_of_anchor.html]
|
||||||
[test_undo_after_spellchecker_replaces_word.html]
|
[test_undo_after_spellchecker_replaces_word.html]
|
||||||
skip-if = toolkit == 'android'
|
skip-if = toolkit == 'android'
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test for TextEditor triple click and SetValue</title>
|
||||||
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font: 1em/1 Ahem
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<input id="input" value="foo bar baz">
|
||||||
|
<script>
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
SimpleTest.waitForFocus(() => {
|
||||||
|
const { input } = document.all;
|
||||||
|
input.focus();
|
||||||
|
synthesizeMouse(input, 5, 5, { clickCount: 3 }, window);
|
||||||
|
is(input.selectionStart, 0, "selectionStart should be 0");
|
||||||
|
is(input.selectionEnd, input.value.length, "selectionEnd should be the end of the value");
|
||||||
|
synthesizeKey("KEY_Backspace");
|
||||||
|
is(input.value, "", ".value should be empty");
|
||||||
|
|
||||||
|
input.value = "hmm";
|
||||||
|
is(input.value, "hmm", ".value must be set");
|
||||||
|
SimpleTest.finish();
|
||||||
|
});
|
||||||
|
</script>
|
Загрузка…
Ссылка в новой задаче