From 105243afa6008abe9176348baafb8de2ce7b2d9c Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 27 Mar 2017 17:51:03 +0200 Subject: [PATCH] [FIX] web_editor: fix select and modify video There was an issue when selecting a video tag: - a tag inside the video tag would be selected instead of the video tag so video could not be removed or modified (modifying it would add a video or image inside the video itself and so on). - the selection was not conveyed to the editor so it would be lost consequently due to some code who restored it to what was saved on the editor. This fix solves this by changing how the video tag was selected and saving the selected range on the editor. opw-724701 --- addons/web_editor/static/src/js/rte.summernote.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/rte.summernote.js b/addons/web_editor/static/src/js/rte.summernote.js index 869ece9cf58..df8aae48055 100644 --- a/addons/web_editor/static/src/js/rte.summernote.js +++ b/addons/web_editor/static/src/js/rte.summernote.js @@ -267,7 +267,15 @@ eventHandler.modules.popover.update = function ($popover, oStyle, isAirMode) { $imagePopover.find('.o_image_alt').text( (alt || "").replace(/"/g, '"') ).parent().toggle(oStyle.image.tagName === "IMG"); $imagePopover.show(); - range.createFromNode(dom.firstChild(oStyle.image)).select(); + // for video tag (non-void) we select the range over the tag, + // for other media types we get the first descendant leaf element + var target_node = oStyle.image; + if (!oStyle.image.className.match(/(^|\s)media_iframe_video(\s|$)/i)) { + target_node = dom.firstChild(target_node); + } + range.createFromNode(target_node).select(); + // save range on the editor so it is not lost if restored + eventHandler.modules.editor.saveRange(dom.makeLayoutInfo(target_node).editable()); } else { $(".note-control-selection").hide(); }