From 5be974283da1bad121e1ba3779d764a2c2b7c78a Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Fri, 10 Sep 2021 12:07:24 +0000 Subject: [PATCH] [IMP] web_editor: add possibility to not focus LinkTool input Before this commit, when requesting the link tool in the right panel, it would always focus its input. This commit adds an option to not focus the input when link tool is requested. It will be used by next commit. task-2618494 X-original-commit: ad13055d58b6cd92d56f483bce17ab2e19216809 Part-of: odoo/odoo#76372 --- .../static/src/js/wysiwyg/widgets/link.js | 14 ++++++++------ .../src/js/wysiwyg/widgets/link_popover_widget.js | 5 ++++- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 3 ++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js index 442ff8ef74f..aabc8a73212 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -127,12 +127,14 @@ const Link = Widget.extend({ this._updateOptionsUI(); this._adaptPreview(); - // ensure the focus in the first input of the link modal - setTimeout(()=> { - const firstInput = this.$('input:visible:first'); - firstInput.focus(); - firstInput.select(); - }, 0); + if (!this.options.noFocusUrl) { + // ensure the focus in the first input of the link modal + setTimeout(()=> { + const firstInput = this.$('input:visible:first'); + firstInput.focus(); + firstInput.select(); + }, 0); + } return this._super.apply(this, arguments); }, diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js index 7a076adb3e5..415ae197829 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link_popover_widget.js @@ -168,7 +168,10 @@ const LinkPopoverWidget = Widget.extend({ * @param {Event} ev */ _onEditLinkClick(ev) { - $('#toolbar #create-link').click(); + $('#wrapwrap').data('wysiwyg').toggleLinkTools({ + forceOpen: true, + link: this.$target[0], + }); ev.stopImmediatePropagation(); }, /** diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 326d24ad1dc..43f310890c7 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -796,6 +796,7 @@ const Wysiwyg = Widget.extend({ * @param {boolean} [options.forceOpen] default: false * @param {boolean} [options.forceDialog] force to open the dialog * @param {boolean} [options.link] The anchor element to edit if it is known. + * @param {boolean} [options.noFocusUrl=false] Disable the automatic focusing of the URL field. */ toggleLinkTools(options = {}) { if (this.snippetsMenu && !options.forceDialog) { @@ -804,7 +805,7 @@ const Wysiwyg = Widget.extend({ } if (options.forceOpen || !this.linkTools) { const $btn = this.toolbar.$el.find('#create-link'); - this.linkTools = new weWidgets.LinkTools(this, {wysiwyg: this}, this.odooEditor.editable, {}, $btn, options.link || this.lastMediaClicked); + this.linkTools = new weWidgets.LinkTools(this, {wysiwyg: this, noFocusUrl: options.noFocusUrl}, this.odooEditor.editable, {}, $btn, options.link || this.lastMediaClicked); const _onMousedown = ev => { if (!ev.target.closest('.oe-toolbar') && !ev.target.closest('.ui-autocomplete')) { // Destroy the link tools on click anywhere outside the