Bug 1695650 - Consider selection editable even if the anchor is the empty <br> element. r=masayuki

Otherwise we disable the context menu commands which seems bad. This also
matches the HTML editor.

Differential Revision: https://phabricator.services.mozilla.com/D107513
This commit is contained in:
Emilio Cobos Álvarez 2021-03-09 01:32:47 +00:00
Родитель 313bc2e629
Коммит 0a34cbc059
3 изменённых файлов: 18 добавлений и 3 удалений

Просмотреть файл

@ -662,9 +662,7 @@ bool EditorBase::IsSelectionEditable() {
// XXX we just check that the anchor node is editable at the moment
// we should check that all nodes in the selection are editable
nsCOMPtr<nsINode> anchorNode = SelectionRefPtr()->GetAnchorNode();
return anchorNode && anchorNode->IsContent() &&
EditorUtils::IsEditableContent(*anchorNode->AsContent(),
GetEditorType());
return anchorNode && anchorNode->IsContent() && anchorNode->IsEditable();
}
nsINode* anchorNode = SelectionRefPtr()->GetAnchorNode();

Просмотреть файл

@ -266,6 +266,7 @@ skip-if = os == 'android'
[test_middle_click_paste.html]
skip-if = headless
[test_nsIEditor_insertLineBreak.html]
[test_nsIEditor_isSelectionEditable.html]
[test_nsIEditorMailSupport_insertAsCitedQuotation.html]
[test_nsIHTMLEditor_getElementOrParentByTagName.html]
[test_nsIHTMLEditor_getParagraphState.html]

Просмотреть файл

@ -0,0 +1,16 @@
<!doctype html>
<title>Test for nsIEditor.isSelectionEditable</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<input>
<textarea></textarea>
<script>
for (let tag of ["input", "textarea"]) {
let node = document.querySelector(tag);
ok(SpecialPowers.wrap(node).editor.isSelectionEditable, "Empty editor selection should be editable");
node.value = "abcd";
ok(SpecialPowers.wrap(node).editor.isSelectionEditable, "Non-empty editor selection should be editable");
node.value = "";
ok(SpecialPowers.wrap(node).editor.isSelectionEditable, "Empty editor selection should be editable after setting value");
}
</script>