diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts index 829047265..ef23b5c70 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts @@ -11,6 +11,7 @@ import { JustificationsService } from '@services/entity-services/justifications. import { Roles } from '@users/roles'; import { firstValueFrom } from 'rxjs'; import { ManualRedactionService } from '../../services/manual-redaction.service'; +import { REDAnnotationManager } from '../../../pdf-viewer/services/annotation-manager.service'; export interface LegalBasisOption { label?: string; @@ -40,6 +41,7 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme activeDossiersService: ActiveDossiersService, private readonly _dictionaryService: DictionaryService, protected readonly _dialogRef: MatDialogRef, + private readonly _annotationManager: REDAnnotationManager, @Inject(MAT_DIALOG_DATA) readonly data: { manualRedactionEntryWrapper: ManualRedactionEntryWrapper; dossierId: string; file: File }, ) { super(_dialogRef); @@ -111,6 +113,13 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme } } + close() { + super.close(); + if (this.isRectangle) { + this._annotationManager.delete(this._annotationManager.selected[0].Id); + } + } + #getRectangles() { const quads = this.data.manualRedactionEntryWrapper.manualRedactionEntry.positions.find(a => !!a); const value: string = this.form.get('multiplePages').value.replace(/[^0-9-,]/g, ''); 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 30a31b8cc..99358859d 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 @@ -294,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(); } @@ -309,6 +311,19 @@ export class FilePreviewScreenComponent } } + @Bind() + handleDeleteRectangleOnEsc($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); + } + } + } + async ngOnAttach(previousRoute: ActivatedRouteSnapshot) { if (!this.state.file().canBeOpened) { return this.#navigateToDossier(); @@ -341,7 +356,7 @@ export class FilePreviewScreenComponent this.pdfProxyService.configureElements(); this.#restoreOldFilters(); document.documentElement.addEventListener('fullscreenchange', this.fullscreenListener); - + this.pdf.instance.UI.hotkeys.on('esc', this.handleDeleteRectangleOnEsc); this.#openComponentLogDialogIfDefault(); 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 c42037705..83cab4409 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 @@ -266,12 +266,18 @@ export class PdfViewer { } #listenForEsc() { - this.#instance.UI.hotkeys.on('esc', e => { - e.preventDefault(); - if (this.#isElementActive('searchPanel') && !this._annotationManager.resizingAnnotationId) { - this.#focusViewer(); - this.deactivateSearch(); - } + this.#instance.UI.hotkeys.on('esc', { + keydown: e => { + e.preventDefault(); + }, + keyup: e => { + e.preventDefault(); + if (this.#isElementActive('searchPanel') && !this._annotationManager.resizingAnnotationId) { + this.#focusViewer(); + this.deactivateSearch(); + } + this.#clickSelectToolButton(); + }, }); } @@ -382,4 +388,9 @@ export class PdfViewer { this.instance.UI.iframeWindow.document.getElementById('SearchPanel__input').blur(); this.instance.UI.iframeWindow.focus(); } + + #clickSelectToolButton() { + const selectButton = this.instance.UI.iframeWindow.document.querySelector('[data-element="selectToolButton"]') as HTMLElement; + selectButton.click(); + } } diff --git a/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts b/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts index 33ed36234..6479fd377 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts @@ -65,6 +65,7 @@ export const DISABLED_HOTKEYS = [ 'SPACE', 'UP', 'DOWN', + 'ESCAPE', 'R', 'P', 'A',