[FIX] web_editor: properly bind dblclick to videos to edit them

Commit [1] refactored the event handler code in charge of handling
double click on media elements to edit them. A mistake was made making
the code consider inner elements of the media instead of the media as a
whole when clicking on it.

Steps to reproduce:
- Enter edit mode on the homepage
- Add a text-image snippet
- Change the image to a video (after dblclick on the image for instance)
- Try to change it back with a dblclick => it does nothing

[1]: https://github.com/odoo/odoo/commit/8ca115b3b9dfe87b59b6b064a4d85ea152d9214c

X-original-commit: 4b47ae0022a3e50d53dc02e399412585fc2131ef
Part-of: odoo/odoo#131139
This commit is contained in:
qsm-odoo
2023-08-09 21:01:17 +02:00
parent ef1d17ad2b
commit 9f183ea0e9
2 changed files with 6 additions and 6 deletions
@@ -546,7 +546,7 @@ export class HtmlField extends Component {
this.props.record.data.attachment_ids.linkTo(attachment.res_id, attachment);
}
_onDblClickEditableMedia(ev) {
const el = ev.target;
const el = ev.currentTarget;
if (el.nodeName === 'IMG' && el.src) {
this.wysiwyg.showImageFullscreen(el.src);
}
@@ -486,12 +486,12 @@ export class Wysiwyg extends Component {
this.$editable.on('click', '.o_image, .media_iframe_video', e => e.preventDefault());
this.showTooltip = true;
this.$editable.on('dblclick', mediaSelector, ev => {
const target = ev.target;
if (target.isContentEditable || (target.parentElement && target.parentElement.isContentEditable)) {
const targetEl = ev.currentTarget;
if (targetEl.isContentEditable || (targetEl.parentElement && targetEl.parentElement.isContentEditable)) {
this.showTooltip = false;
if (!isProtected(this.odooEditor.document.getSelection().anchorNode)) {
if (this.options.onDblClickEditableMedia && target.nodeName === 'IMG' && target.src) {
if (this.options.onDblClickEditableMedia && targetEl.nodeName === 'IMG' && targetEl.src) {
this.options.onDblClickEditableMedia(ev);
} else {
this._onDblClickEditableMedia(ev);
@@ -2692,7 +2692,7 @@ export class Wysiwyg extends Component {
}
}
_onDblClickEditableMedia(ev) {
const $el = $(ev.target);
const $el = $(ev.currentTarget);
$el.selectElement();
if (!$el.parent().hasClass('o_stars')) {
// Waiting for all the options to be initialized before
@@ -2700,7 +2700,7 @@ export class Wysiwyg extends Component {
// been deleted in the meantime.
this.waitForEmptyMutexAction().then(() => {
if ($el[0].parentElement) {
this.openMediaDialog({ node: ev.target });
this.openMediaDialog({ node: $el[0] });
}
});
}