RED-10592: fixed listener to esc key in pdf viewer.

This commit is contained in:
Nicoleta Panaghiu 2024-12-04 13:23:46 +02:00
parent c9bb6bc6a5
commit 1dc069a091
2 changed files with 24 additions and 37 deletions

View File

@ -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();
}

View File

@ -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;