RED-7605: removed word duplicates.

This commit is contained in:
Nicoleta Panaghiu 2023-10-13 11:39:48 +03:00
parent e048169a5b
commit 6dc94979c0

View File

@ -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);
}