From 3c5217c31791ede41c053ea386691309afe8db65 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Wed, 4 Dec 2024 13:07:50 +0200 Subject: [PATCH] RED-10592: fixed listener to esc key in pdf viewer. --- .../file-header/file-header.component.ts | 1 - .../file-preview-screen.component.ts | 9 +++-- .../pdf-viewer/services/pdf-viewer.service.ts | 33 +++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-header/file-header.component.ts b/apps/red-ui/src/app/modules/file-preview/components/file-header/file-header.component.ts index 97409b17c..bb4076329 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-header/file-header.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/file-header/file-header.component.ts @@ -4,7 +4,6 @@ import { Component, computed, ElementRef, - HostListener, Input, NgZone, OnDestroy, diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index ce9cc2edd..e6553d348 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -275,7 +275,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni super.ngOnDestroy(); } - @Bind() handleEscInsideViewer($event: KeyboardEvent) { $event.preventDefault(); if (!!this._annotationManager.selected[0]) { @@ -349,7 +348,13 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni this.pdfProxyService.configureElements(); this.#restoreOldFilters(); - this.pdf.instance.UI.hotkeys.on('esc', this.handleEscInsideViewer); + this.pdf.instance.UI.hotkeys.on('esc', { + keydown: (e: KeyboardEvent) => this.pdf.escKeyHandler.keydown(e), + keyup: (e: KeyboardEvent) => { + this.pdf.escKeyHandler.keyup(e); + this.handleEscInsideViewer(e); + }, + }); this._viewerHeaderService.resetLayers(); this.pdf.instance.UI.iframeWindow.document.removeEventListener('click', this.handleViewerClick); this.pdf.instance.UI.iframeWindow.document.addEventListener('click', this.handleViewerClick); diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/pdf-viewer.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/pdf-viewer.service.ts index c2aae990e..43d709928 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/pdf-viewer.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/pdf-viewer.service.ts @@ -65,6 +65,21 @@ export class PdfViewer { }; selectedText = ''; + readonly escKeyHandler = { + keydown: (e: KeyboardEvent) => { + e.preventDefault(); + this.#clickSelectToolButton(); + }, + keyup: (e: KeyboardEvent) => { + e.preventDefault(); + if (this.#isElementActive('searchPanel') && !this._annotationManager.resizingAnnotationId) { + this.#focusViewer(); + this.deactivateSearch(); + } + this.#clickSelectToolButton(); + }, + }; + constructor( private readonly _logger: NGXLogger, private readonly _errorService: ErrorService, @@ -170,7 +185,6 @@ export class PdfViewer { this.#disableHotkeys(); this.#getSelectedText(); this.#listenForCommandF(); - this.#listenForEsc(); this.#listenForShift(); this.#clearSearchResultsWhenVisibilityChanged(); }); @@ -278,23 +292,6 @@ export class PdfViewer { }); } - #listenForEsc() { - this.#instance.UI.hotkeys.on('esc', { - keydown: (e: KeyboardEvent) => { - e.preventDefault(); - this.#clickSelectToolButton(); - }, - keyup: (e: KeyboardEvent) => { - e.preventDefault(); - if (this.#isElementActive('searchPanel') && !this._annotationManager.resizingAnnotationId) { - this.#focusViewer(); - this.deactivateSearch(); - } - this.#clickSelectToolButton(); - }, - }); - } - #listenForShift() { this.#instance.UI.iframeWindow.addEventListener('keydown', e => { if (e.target === this.#searchInput) return;