From e318ca2b3d239281cfdb6ff1717cfc64873e9570 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Wed, 20 Sep 2023 11:51:38 +0300 Subject: [PATCH] RED-7605: Fixed search. --- .../file-preview/file-preview-screen.component.ts | 3 ++- .../pdf-viewer/services/pdf-viewer.service.ts | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 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 5e1619616..5230dfddc 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 @@ -382,7 +382,7 @@ export class FilePreviewScreenComponent } } - @HostListener('window:keyup', ['$event']) + @HostListener('document:keyup', ['$event']) handleKeyEvent($event: KeyboardEvent) { if (this._router.url.indexOf('/file/') < 0) { return; @@ -396,6 +396,7 @@ export class FilePreviewScreenComponent this.fullScreen = false; this.closeFullScreen(); this.pdf.deactivateSearch(); + window.focus(); 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 c892bec91..a6113cfc9 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 @@ -102,6 +102,10 @@ export class PdfViewer { return page$.pipe(map(page => this.#adjustPage(page))); } + get searchActive() { + return this.instance.UI.isElementOpen('searchPanel'); + } + focusSearch() { const iframeWindow = this.#instance.UI.iframeWindow; const input = iframeWindow.document.getElementById('SearchPanel__input') as HTMLInputElement; @@ -260,8 +264,13 @@ export class PdfViewer { #listenForCommandF() { this.#instance.UI.hotkeys.on('command+f, ctrl+f', e => { e.preventDefault(); - this.activateSearch(); - this.focusSearch(); + if (!this.searchActive) { + this.activateSearch(); + this.focusSearch(); + } + if (this.documentViewer.getSelectedText()) { + this.#searchForSelectedText(); + } }); }