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 cf276f786..e782c483a 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 @@ -181,8 +181,6 @@ export class FilePreviewScreenComponent } } }); - - this.#handleDeleteRectangleOnEsc(); } get changed() { @@ -296,11 +294,13 @@ export class FilePreviewScreenComponent this._viewerHeaderService.enableLoadAllAnnotations(); // Reset the button state (since the viewer is reused between files) super.ngOnDetach(); document.documentElement.removeEventListener('fullscreenchange', this.fullscreenListener); + this.pdf.instance.UI.hotkeys.off('esc'); this._changeRef.markForCheck(); } ngOnDestroy() { document.documentElement.removeEventListener('fullscreenchange', this.fullscreenListener); + this.pdf.instance.UI.hotkeys.off('esc'); super.ngOnDestroy(); } @@ -343,6 +343,7 @@ export class FilePreviewScreenComponent this.pdfProxyService.configureElements(); this.#restoreOldFilters(); document.documentElement.addEventListener('fullscreenchange', this.fullscreenListener); + this.pdf.instance.UI.hotkeys.on('esc', this.#handleDeleteRectangle); this.#openComponentLogDialogIfDefault(); this._viewerHeaderService.resetLayers(); @@ -588,18 +589,16 @@ export class FilePreviewScreenComponent return newAnnotations; } - #handleDeleteRectangleOnEsc() { - this.pdf.instance.UI.hotkeys.on('esc', e => { - e.preventDefault(); - if (!!this._annotationManager.selected[0]) { - const doesHaveWrapper = this._fileDataService.find(this._annotationManager.selected[0]?.Id); - if (!doesHaveWrapper) { - this._annotationManager.delete(this._annotationManager.selected[0]?.Id); - } else { - this._annotationManager.deselect(this._annotationManager.selected[0]?.Id); - } + #handleDeleteRectangle($event: KeyboardEvent) { + $event.preventDefault(); + if (!!this._annotationManager.selected[0]) { + const doesHaveWrapper = this._fileDataService.find(this._annotationManager.selected[0]?.Id); + if (!doesHaveWrapper) { + this._annotationManager.delete(this._annotationManager.selected[0]?.Id); + } else { + this._annotationManager.deselect(this._annotationManager.selected[0]?.Id); } - }); + } } #rebuildFilters() {