RED-7605: changed the way selectedText is retrieved and updated pdftron

This commit is contained in:
Nicoleta Panaghiu 2023-11-01 15:46:10 +02:00
parent 8cd751fdf4
commit cbd0d5ce26
2 changed files with 15 additions and 15 deletions

View File

@ -44,14 +44,14 @@ export class PdfViewer {
totalPages$: Observable<number>;
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();
}
}

View File

@ -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",