From 6dc94979c0fd8c51c0383c7f2ac55ead615379f0 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Fri, 13 Oct 2023 11:39:48 +0300 Subject: [PATCH] RED-7605: removed word duplicates. --- .../pdf-viewer/services/pdf-viewer.service.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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 b99aff4ee..66a4de011 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 @@ -51,6 +51,7 @@ export class PdfViewer { searchUp: false, // search from the end of the document upwards ambientString: true, // return ambient string as part of the result }; + searchedWord?: string; constructor( private readonly _logger: NGXLogger, @@ -251,14 +252,15 @@ export class PdfViewer { #listenForCommandF() { this.#instance.UI.hotkeys.on('command+f, ctrl+f', e => { e.preventDefault(); - if (!this.#isElementActive('searchPanel')) { + if (this.#isElementActive('searchPanel')) { + this.#updateSearchOptions(); + } else { this.activateSearch(); } if (this.documentViewer.getSelectedText()) { - this.#updateSearchOptions(); this.#searchForSelectedText(); } - setTimeout(() => this.#focusSearch(), 30); + setTimeout(() => this.#focusSearch(), 40); }); } @@ -297,7 +299,14 @@ export class PdfViewer { } #searchForSelectedText() { - const selected = [...new Set(this.documentViewer.getSelectedText().split('\n'))].join('\n'); + const uniqueText = [...new Set(this.documentViewer.getSelectedText().split('\n'))]; + const sameWord = new Set(uniqueText.map(text => text.toLowerCase())).size === 1; + if (uniqueText.length === 1 && sameWord) { + this.searchedWord = uniqueText.join('\n'); + } else if (!sameWord) { + this.searchedWord = this.documentViewer.getSelectedText(); + } + const selected = this.searchedWord; this.#instance.UI.searchTextFull(selected, this.searchOptions); }