From 127ce7578900b0c62c13c30e2b98de729d8b97f9 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Thu, 28 Sep 2023 17:36:29 +0300 Subject: [PATCH] RED-7605: Fixed search again + esc only on document focused. --- .../file-preview-screen.component.ts | 2 -- .../pdf-viewer/services/pdf-viewer.service.ts | 23 ++++++++++++++----- 2 files changed, 17 insertions(+), 8 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 53a69f27b..ad962f246 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 @@ -397,8 +397,6 @@ export class FilePreviewScreenComponent $event.preventDefault(); this.fullScreen = false; this.closeFullScreen(); - this.pdf.deactivateSearch(); - this.pdf.focusViewer(); this._changeRef.markForCheck(); } 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 731980fb4..2890bbf32 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 @@ -108,14 +108,9 @@ export class PdfViewer { } deactivateSearch() { - this.#clearSearchResultsWhenVisibilityChanged(); this.#instance.UI.closeElements(['searchPanel']); } - focusViewer() { - this.instance.UI.iframeWindow.focus(); - } - resetAnnotationActions() { if (this.#instance.UI.annotationPopup.getItems().length) { this.#logger.info('[PDF] Reset annotation actions'); @@ -167,8 +162,9 @@ export class PdfViewer { this.#setSelectionMode(); this.#configureElements(); this.#disableHotkeys(); - this.#clearSearchResultsWhenVisibilityChanged(); this.#listenForCommandF(); + this.#listenForEsc(); + this.#clearSearchResultsWhenVisibilityChanged(); }); return this.#instance; @@ -267,6 +263,16 @@ export class PdfViewer { }); } + #listenForEsc() { + this.#instance.UI.hotkeys.on('esc', e => { + e.preventDefault(); + if (this.#isElementActive('searchPanel')) { + this.deactivateSearch(); + this.#focusViewer(); + } + }); + } + #adjustPage(page: number) { if (this.isCompareMode()) { if (page % 2 === 1) { @@ -351,4 +357,9 @@ export class PdfViewer { input.select(); } } + + #focusViewer() { + this.instance.UI.iframeWindow.document.getElementById('SearchPanel__input').blur(); + this.instance.UI.iframeWindow.focus(); + } }