From 981290ee9c88ea00440268d2a7b829d3a601a2d2 Mon Sep 17 00:00:00 2001 From: Stanislas Gueniffey Date: Tue, 21 Feb 2023 15:09:12 +0000 Subject: [PATCH] [IMP] web_editor: Ctrl+Click open links in new tab By default, clicking on links in a contentEditable context does not open the link because it would make it hard to edit it otherwise. This is a problem now that the views are always in edit mode because it means the user cannot quickly and easily click on links to open them. This commit aims to solve this conundrum by finding a middle-ground between these two use cases, that is reintroducing the oh-so loved Ctrl+Click behavior that was commonly used in previous versions. This required two changes: 1. Explicitely implementing the behavior of opening the link in a new tab in that case since it is not the native behavior in a contentEditable context. 2. Giving special treatment to links inside a contentEditable context in the `globalClick` listener introduced at [1] such that the event can actually reach the custom handler in the editor. task-id 3188438 [1]: https://github.com/odoo/odoo/commit/47acba560a8954f10bfa97b28daf90047005fdf1#diff-ce4923ebad38db28d4fc17267c93d147c4404feefd42eb140ef990bddbe1a9ffR93 closes odoo/odoo#115428 X-original-commit: 8bd6b28f7915d7d84ff42722e5cb4b6f798cb81d Signed-off-by: David Monjoie (dmo) --- addons/web/static/src/webclient/webclient.js | 1 + addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/addons/web/static/src/webclient/webclient.js b/addons/web/static/src/webclient/webclient.js index 1603ed3a4c4..6c3662f8a0d 100644 --- a/addons/web/static/src/webclient/webclient.js +++ b/addons/web/static/src/webclient/webclient.js @@ -100,6 +100,7 @@ export class WebClient extends Component { // we do not want any other listener to execute. if ( ev.ctrlKey && + !ev.target.isContentEditable && ((ev.target instanceof HTMLAnchorElement && ev.target.href) || (ev.target instanceof HTMLElement && ev.target.closest("a[href]:not([href=''])"))) ) { diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index fd5e93eb1a3..d3abc556786 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -369,6 +369,9 @@ const Wysiwyg = Widget.extend({ && !$target.find('> [data-oe-model]').length && !$target[0].closest('.o_extra_menu_items') && $target[0].isContentEditable) { + if (ev.ctrlKey || ev.metaKey) { + window.open(ev.target.href, '_blank') + } this.linkPopover = $target.data('popover-widget-initialized'); if (!this.linkPopover) { // TODO this code is ugly maybe the mutex should be in the