From a9707ac099b0af942eecb722cc10816fd6441bb4 Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Mon, 21 Aug 2023 09:29:57 +0000 Subject: [PATCH] [FIX] mail: only allow image operations for images in AttachmentViewer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First bug ========= Steps to reproduce ------------------ - Go to A project task - Upload an pdf - Preview the pdf - Press on the "+" key ``` TypeError: Cannot read properties of null (reading 'offsetWidth') at AttachmentViewer.updateZoomerStyle ``` Cause of the issue ------------------ Some operations should only be called when the current attachment is an image. Second bug ========== Steps to reproduce ------------------ - Go to documents - Click on an image document - Edit the "Tags" field and type + The image is resized Cause of the issue ------------------ In the documents app, the viewer is not fullscreen. The keyboard actions should only be used when the attachment viewer is focused. The onKeyDown was bound to the document. Solution -------- We can bind the `onKeyDown` to the AttachmentViewer. Since we now need the viewer focused, we can use the autofocus hook. opw-3456439 closes odoo/odoo#133126 X-original-commit: 7fa95127e55e21bcaf28191c872cd0a1b8a0a6a6 Related: odoo/enterprise#46270 Signed-off-by: Alexandre Kühn (aku) Signed-off-by: Hubert Van De Walle --- .../src/core/file_viewer/file_viewer.js | 36 ++++++++++--------- .../src/core/file_viewer/file_viewer.xml | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/addons/web/static/src/core/file_viewer/file_viewer.js b/addons/web/static/src/core/file_viewer/file_viewer.js index f92156331d0..899b2f95090 100644 --- a/addons/web/static/src/core/file_viewer/file_viewer.js +++ b/addons/web/static/src/core/file_viewer/file_viewer.js @@ -1,7 +1,7 @@ /* @odoo-module */ -import { Component, useExternalListener, useRef, useState } from "@odoo/owl"; -import { useService } from "@web/core/utils/hooks"; +import { Component, useRef, useState } from "@odoo/owl"; +import { useAutofocus, useService } from "@web/core/utils/hooks"; /** * @typedef {Object} File @@ -31,6 +31,7 @@ export class FileViewer extends Component { }; setup() { + useAutofocus(); this.imageRef = useRef("image"); this.zoomerRef = useRef("zoomer"); @@ -48,7 +49,6 @@ export class FileViewer extends Component { y: 0, }; - useExternalListener(document, "keydown", this.onKeydown); this.state = useState({ index: this.props.startIndex, file: this.props.files[this.props.startIndex], @@ -96,20 +96,22 @@ export class FileViewer extends Component { case "q": this.close(); break; - case "r": - this.rotate(); - break; - case "+": - this.zoomIn(); - break; - case "-": - this.zoomOut(); - break; - case "0": - this.resetZoom(); - break; - default: - return; + } + if (this.state.file.isImage) { + switch (ev.key) { + case "r": + this.rotate(); + break; + case "+": + this.zoomIn(); + break; + case "-": + this.zoomOut(); + break; + case "0": + this.resetZoom(); + break; + } } } diff --git a/addons/web/static/src/core/file_viewer/file_viewer.xml b/addons/web/static/src/core/file_viewer/file_viewer.xml index 62953ac80c2..00590ba022f 100644 --- a/addons/web/static/src/core/file_viewer/file_viewer.xml +++ b/addons/web/static/src/core/file_viewer/file_viewer.xml @@ -3,7 +3,7 @@
-
+