From ebfbfdac0e8415b7f6bd3f55686eba32e1ab3484 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Tue, 22 Nov 2022 15:38:58 +0000 Subject: [PATCH] [FIX] website: prevent CTRL-K from focusing on browser's URL bar Ever since the website is previewed in the iframe [1], pressing CTRL-K (or Meta-K on macOS) while previewing the website can result in focusing on the browser's URL bar on top of summoning the command palette. Steps to reproduce: - Preview the website - Click on the iframe to focus on it - Press CTRL|Meta - K - URL bar is focused This commit fixes that by preventing the default behaviour within the iframe and only summon the command palette. [1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b task-3035637 closes odoo/odoo#106483 X-original-commit: 797a0514b58a37efc5246a655339353c200b4214 Signed-off-by: Romain Derie (rde) Signed-off-by: Arthur Detroux (ard) --- .../src/client_actions/website_preview/website_preview.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.js b/addons/website/static/src/client_actions/website_preview/website_preview.js index 4d40f9a2a32..aae14db8e00 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.js +++ b/addons/website/static/src/client_actions/website_preview/website_preview.js @@ -9,6 +9,7 @@ import { WebsiteTranslator } from '../../components/translator/translator'; import { unslugHtmlDataObject } from '../../services/website_service'; import {OptimizeSEODialog} from '@website/components/dialog/seo'; import { routeToUrl } from "@web/core/browser/router_service"; +import { getActiveHotkey } from "@web/core/hotkeys/hotkey_service"; const { Component, onWillStart, onMounted, onWillUnmount, useRef, useEffect, useState } = owl; @@ -364,6 +365,11 @@ export class WebsitePreview extends Component { } }); this.iframe.el.contentDocument.addEventListener('keydown', ev => { + if (getActiveHotkey(ev) === 'control+k' && !this.websiteContext.edition) { + // Avoid for browsers to focus on the URL bar when pressing + // CTRL-K from within the iframe. + ev.preventDefault(); + } this.iframe.el.dispatchEvent(new KeyboardEvent('keydown', ev)); }); this.iframe.el.contentDocument.addEventListener('keyup', ev => {