[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) <dmo@odoo.com>
This commit is contained in:
@@ -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=''])")))
|
||||
) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user