From 2bf0b904cd3ebf831c9b47e6f59ab508ae968f81 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 23 Mar 2021 13:04:15 +0000 Subject: [PATCH] Don't listen for two-up keyboard shortcuts if in input (#979) --- .../Compress/Output/custom-els/TwoUp/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/lazy-app/Compress/Output/custom-els/TwoUp/index.ts b/src/client/lazy-app/Compress/Output/custom-els/TwoUp/index.ts index c2cb7b95..6b5b5715 100644 --- a/src/client/lazy-app/Compress/Output/custom-els/TwoUp/index.ts +++ b/src/client/lazy-app/Compress/Output/custom-els/TwoUp/index.ts @@ -69,7 +69,7 @@ export default class TwoUp extends HTMLElement { }, }); - window.addEventListener('keydown', event => this._onKeyDown(event)); + window.addEventListener('keydown', (event) => this._onKeyDown(event)); } connectedCallback() { @@ -98,19 +98,24 @@ export default class TwoUp extends HTMLElement { // KeyDown event handler private _onKeyDown(event: KeyboardEvent) { + const target = event.target; + if (target instanceof HTMLElement && target.closest('input')) return; + if (event.code === 'Digit1' || event.code === 'Numpad1') { this._position = 0; this._relativePosition = 0; this._setPosition(); } else if (event.code === 'Digit2' || event.code === 'Numpad2') { - const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width'; + const dimensionAxis = + this.orientation === 'vertical' ? 'height' : 'width'; const bounds = this.getBoundingClientRect(); this._position = bounds[dimensionAxis] / 2; - this._relativePosition = (this._position / bounds[dimensionAxis]) / 2; + this._relativePosition = this._position / bounds[dimensionAxis] / 2; this._setPosition(); } else if (event.code === 'Digit3' || event.code === 'Numpad3') { - const dimensionAxis = this.orientation === 'vertical' ? 'height' : 'width'; + const dimensionAxis = + this.orientation === 'vertical' ? 'height' : 'width'; const bounds = this.getBoundingClientRect(); this._position = bounds[dimensionAxis];