From cbd0d5ce266de6253224d8d07185ea160b0ca9a0 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Wed, 1 Nov 2023 15:46:10 +0200 Subject: [PATCH] RED-7605: changed the way selectedText is retrieved and updated pdftron --- .../pdf-viewer/services/pdf-viewer.service.ts | 28 +++++++++---------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 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 66a4de011..f6b3ad414 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 @@ -44,14 +44,14 @@ export class PdfViewer { totalPages$: Observable; searchOptions = { - caseSensitive: true, // match case - wholeWord: true, // match whole words only + caseSensitive: false, // match case + wholeWord: false, // match whole words only wildcard: false, // allow using '*' as a wildcard value regex: false, // string is treated as a regular expression searchUp: false, // search from the end of the document upwards ambientString: true, // return ambient string as part of the result }; - searchedWord?: string; + selectedText = ''; constructor( private readonly _logger: NGXLogger, @@ -170,6 +170,7 @@ export class PdfViewer { this.#setSelectionMode(); this.#configureElements(); this.#disableHotkeys(); + this.#getSelectedText(); this.#listenForCommandF(); this.#listenForEsc(); this.#clearSearchResultsWhenVisibilityChanged(); @@ -257,7 +258,7 @@ export class PdfViewer { } else { this.activateSearch(); } - if (this.documentViewer.getSelectedText()) { + if (this.selectedText.length) { this.#searchForSelectedText(); } setTimeout(() => this.#focusSearch(), 40); @@ -299,15 +300,14 @@ export class PdfViewer { } #searchForSelectedText() { - 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); + this.#instance.UI.searchTextFull(this.selectedText, this.searchOptions); + this.documentViewer.clearSelection(); + } + + #getSelectedText() { + this.documentViewer.addEventListener('textSelected', (_, selectedText) => { + this.selectedText = selectedText; + }); } #clearSearchResultsWhenVisibilityChanged() { @@ -374,7 +374,7 @@ export class PdfViewer { if (input) { input.focus(); } - if (input.value.length > 0) { + if (input?.value?.length > 0) { input.select(); } } diff --git a/package.json b/package.json index 02e0f702e..ac150793a 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@ngx-translate/core": "^14.0.0", "@ngx-translate/http-loader": "^7.0.0", "@nrwl/angular": "15.6.3", - "@pdftron/webviewer": "10.1.1", + "@pdftron/webviewer": "10.3.0", "chart.js": "4.4.0", "dayjs": "^1.11.5", "file-saver": "^2.0.5",