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 6c137a79f..87e531a03 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 e8a3bb9d9..a6713bd63 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 @@ -300,7 +300,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni super.ngOnDestroy(); } - @Bind() handleEscInsideViewer($event: KeyboardEvent) { $event.preventDefault(); if (!!this._annotationManager.selected[0]) { @@ -374,7 +373,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 9a1ad929b..16ca88fe5 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, @@ -168,7 +183,6 @@ export class PdfViewer { this.#disableHotkeys(); this.#getSelectedText(); this.#listenForCommandF(); - this.#listenForEsc(); this.#listenForShift(); this.#clearSearchResultsWhenVisibilityChanged(); }); @@ -276,23 +290,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;