diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index aee6bdf3cea..d2f50a7d1fa 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -2615,32 +2615,6 @@ var SnippetsMenu = Widget.extend({ } return editorToEnable; - }).then(async editor => { - // If a link was clicked, the linktools should be focused after - // the right panel is shown to the user. - // TODO: this should be reviewed to be done another way: we - // should avoid focusing something here while it is being - // rendered elsewhere. - if (this.options.wysiwyg.state.linkToolProps) { - let inputElement = document.querySelector('#o_link_dialog_url_input'); - if (!inputElement) { - // Wait for `linkTools` potential in-progress rendering - // before focusing the URL input on `snippetsMenu` (this - // prevents race condition for automated testing). - inputElement = await new Promise((resolve) => { - const observer = new MutationObserver(() => { - const inputElement = document.querySelector('#o_link_dialog_url_input'); - if (inputElement) { - observer.disconnect(); - resolve(inputElement); - } - }); - observer.observe(document.body, { childList: true, subtree: true }); - }); - } - inputElement.focus(); - } - return editor; }); }); }, diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 25ef94d3ee9..c2a8121b4f8 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1461,6 +1461,8 @@ export class Wysiwyg extends Component { } }; } + // update the shouldFocusUrl prop to focus on url when double click + this.state.linkToolProps.shouldFocusUrl = options.shouldFocusUrl; const _onClick = ev => { if ( !ev.target.closest('#create-link') && diff --git a/addons/website/static/src/js/editor/widget_link.js b/addons/website/static/src/js/editor/widget_link.js index a89644fdb54..98711705178 100644 --- a/addons/website/static/src/js/editor/widget_link.js +++ b/addons/website/static/src/js/editor/widget_link.js @@ -4,6 +4,7 @@ import { LinkTools } from '@web_editor/js/wysiwyg/widgets/link_tools'; import { patch } from "@web/core/utils/patch"; import { useService } from "@web/core/utils/hooks"; +import {status} from '@odoo/owl'; import wUtils from "@website/js/utils"; import { debounce } from "@web/core/utils/timing"; @@ -12,7 +13,6 @@ const LINK_DEBOUNCE = 1000; patch(LinkTools.prototype, { setup() { this.rpc = useService('rpc'); - this.rpc = this.env.services.rpc; return super.setup(...arguments); }, /** @@ -44,6 +44,7 @@ patch(LinkTools.prototype, { const fakeWidget = { _rpc: ({ route, params }) => this.rpc(route, params), trigger_up: this._onAutocompleteClose.bind(this), + isDestroyed: () => status(this) === 'destroyed', }; wUtils.autocompleteWithPages(fakeWidget, this.$el.find('input[name="url"]'), options); this._adaptPageAnchor(); diff --git a/addons/website/static/src/js/utils.js b/addons/website/static/src/js/utils.js index 2daaee74199..87dbc6f2b7a 100644 --- a/addons/website/static/src/js/utils.js +++ b/addons/website/static/src/js/utils.js @@ -88,6 +88,9 @@ function autocompleteWithPages(self, $input, options) { // avoid useless call to /website/get_suggested_links response(); } else { + if (self.isDestroyed?.()) { + return ; + } return self._rpc({ route: '/website/get_suggested_links', params: {