From 1dc069a091910680caa0b6bae49f4d430e1910ee Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Wed, 4 Dec 2024 13:23:46 +0200 Subject: [PATCH] RED-10592: fixed listener to esc key in pdf viewer. --- .../file-preview-screen.component.ts | 28 +++++----------- .../pdf-viewer/services/pdf-viewer.service.ts | 33 +++++++++---------- 2 files changed, 24 insertions(+), 37 deletions(-) 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 565b97eec..bfd4d8682 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 @@ -1,9 +1,8 @@ -import { ActivatedRouteSnapshot, NavigationExtras, Router, RouterLink } from '@angular/router'; +import { ActivatedRouteSnapshot, NavigationExtras, Router } from '@angular/router'; import { ChangeDetectorRef, Component, effect, NgZone, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { ComponentCanDeactivate } from '@guards/can-deactivate.guard'; import { - CircleButtonComponent, CircleButtonTypes, ConfirmOption, ConfirmOptions, @@ -12,13 +11,12 @@ import { ErrorService, getConfig, IConfirmationDialogData, - IqserAllowDirective, IqserDialog, LoadingService, Toaster, } from '@iqser/common-ui'; import { copyLocalStorageFiltersValues, FilterService, NestedFilter, processFilters } from '@iqser/common-ui/lib/filtering'; -import { AutoUnsubscribe, Bind, bool, List, OnAttach, OnDetach } from '@iqser/common-ui/lib/utils'; +import { AutoUnsubscribe, bool, List, OnAttach, OnDetach } from '@iqser/common-ui/lib/utils'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { ManualRedactionEntryTypes, ManualRedactionEntryWrapper } from '@models/file/manual-redaction-entry.wrapper'; import { Dictionary, File, ViewModes } from '@red/domain'; @@ -60,12 +58,7 @@ import { ViewModeService } from './services/view-mode.service'; import { RedactTextData } from './utils/dialog-types'; import { MultiSelectService } from './services/multi-select.service'; import { NgIf } from '@angular/common'; -import { ViewSwitchComponent } from './components/view-switch/view-switch.component'; -import { ProcessingIndicatorComponent } from '@shared/components/processing-indicator/processing-indicator.component'; -import { UserManagementComponent } from './components/user-management/user-management.component'; import { TranslateModule } from '@ngx-translate/core'; -import { InitialsAvatarComponent } from '@common-ui/users'; -import { FileActionsComponent } from '../shared-dossiers/components/file-actions/file-actions.component'; import { FilePreviewRightContainerComponent } from './components/right-container/file-preview-right-container.component'; import { TypeFilterComponent } from '@shared/components/type-filter/type-filter.component'; import { FileHeaderComponent } from './components/file-header/file-header.component'; @@ -79,16 +72,8 @@ import { DocumentInfoService } from './services/document-info.service'; standalone: true, imports: [ NgIf, - ViewSwitchComponent, - ProcessingIndicatorComponent, - UserManagementComponent, TranslateModule, - InitialsAvatarComponent, - CircleButtonComponent, - IqserAllowDirective, - FileActionsComponent, DisableStopPropagationDirective, - RouterLink, FilePreviewRightContainerComponent, TypeFilterComponent, FileHeaderComponent, @@ -303,7 +288,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni super.ngOnDestroy(); } - @Bind() handleEscInsideViewer($event: KeyboardEvent) { $event.preventDefault(); if (!!this._annotationManager.selected[0]) { @@ -356,7 +340,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(); } 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 faacfd4ec..66ace1a36 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, @@ -163,7 +178,6 @@ export class PdfViewer { this.#disableHotkeys(); this.#getSelectedText(); this.#listenForCommandF(); - this.#listenForEsc(); this.#clearSearchResultsWhenVisibilityChanged(); }); @@ -270,23 +284,6 @@ export class PdfViewer { }); } - #listenForEsc() { - this.#instance.UI.hotkeys.on('esc', { - keydown: e => { - e.preventDefault(); - this.#clickSelectToolButton(); - }, - keyup: e => { - e.preventDefault(); - if (this.#isElementActive('searchPanel') && !this._annotationManager.resizingAnnotationId) { - this.#focusViewer(); - this.deactivateSearch(); - } - this.#clickSelectToolButton(); - }, - }); - } - #getSearchOption(optionId: string): boolean { const iframeWindow = this.#instance.UI.iframeWindow; const checkbox = iframeWindow.document.getElementById(optionId) as HTMLInputElement;