Bug 1598944 - Allow to paste innerHTML in fragments. r=jdescottes

No reason not to.

Differential Revision: https://phabricator.services.mozilla.com/D55098

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-11-28 14:39:55 +00:00
Родитель 1df3a868f8
Коммит 06bd8b4c06
2 изменённых файлов: 15 добавлений и 7 удалений

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

@ -630,16 +630,21 @@ class MarkupContextMenu {
return [linkFollow, linkCopy];
}
_getPasteSubmenu(isEditableElement) {
_getPasteSubmenu(isElement, isFragment, isAnonymous) {
const isPasteable =
isEditableElement && this._getClipboardContentForPaste();
!isAnonymous &&
(isFragment || isElement) &&
this._getClipboardContentForPaste();
const disableAdjacentPaste =
!isPasteable ||
!isElement ||
this.selection.isRoot() ||
this.selection.isBodyNode() ||
this.selection.isHeadNode();
const disableFirstLastPaste =
!isPasteable || (this.selection.isHTMLNode() && this.selection.isRoot());
!isPasteable ||
!isElement ||
(this.selection.isHTMLNode() && this.selection.isRoot());
const pasteSubmenu = new Menu();
pasteSubmenu.append(
@ -656,7 +661,7 @@ class MarkupContextMenu {
id: "node-menu-pasteouterhtml",
label: INSPECTOR_L10N.getStr("inspectorPasteOuterHTML.label"),
accesskey: INSPECTOR_L10N.getStr("inspectorPasteOuterHTML.accesskey"),
disabled: !isPasteable,
disabled: !isPasteable || !isElement,
click: () => this._pasteOuterHTML(),
})
);
@ -902,7 +907,7 @@ class MarkupContextMenu {
menu.append(
new MenuItem({
label: INSPECTOR_L10N.getStr("inspectorPasteHTMLSubmenu.label"),
submenu: this._getPasteSubmenu(isEditableElement),
submenu: this._getPasteSubmenu(isElement, isFragment, isAnonymous),
})
);

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

@ -1625,8 +1625,11 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
}
const rawNode = node.rawNode;
if (rawNode.nodeType !== rawNode.ownerDocument.ELEMENT_NODE) {
throw new Error("Can only change innerHTML to element nodes");
if (
rawNode.nodeType !== rawNode.ownerDocument.ELEMENT_NODE &&
rawNode.nodeType !== rawNode.ownerDocument.DOCUMENT_FRAGMENT_NODE
) {
throw new Error("Can only change innerHTML to element or fragment nodes");
}
// eslint-disable-next-line no-unsanitized/property
rawNode.innerHTML = value;