RED-7605: removed word duplicates.
This commit is contained in:
parent
bac940d4b9
commit
8c307501fa
@ -35,8 +35,10 @@ export class PdfViewer {
|
||||
img: this.#convertPath('/assets/icons/general/pdftron-action-search.svg'),
|
||||
title: inject(TranslateService).instant(_('pdf-viewer.text-popup.actions.search')),
|
||||
onClick: () => {
|
||||
setTimeout(() => this.#searchForSelectedText(), 250);
|
||||
this.#focusSearch();
|
||||
setTimeout(() => {
|
||||
this.#searchForSelectedText();
|
||||
this.#focusSearch();
|
||||
}, 250);
|
||||
},
|
||||
};
|
||||
readonly #destroyRef = inject(DestroyRef);
|
||||
@ -62,6 +64,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,
|
||||
@ -263,14 +266,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);
|
||||
});
|
||||
}
|
||||
|
||||
@ -309,7 +313,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()))].length === 1;
|
||||
if (uniqueText.length === 1 && sameWord) {
|
||||
this.searchedWord = uniqueText.join('\n');
|
||||
} else {
|
||||
this.searchedWord = this.documentViewer.getSelectedText();
|
||||
}
|
||||
const selected = this.searchedWord ?? uniqueText.join('\n');
|
||||
this.#instance.UI.searchTextFull(selected, this.searchOptions);
|
||||
}
|
||||
|
||||
@ -376,7 +387,7 @@ export class PdfViewer {
|
||||
if (input) {
|
||||
input.focus();
|
||||
}
|
||||
if (input.value.length > 0) {
|
||||
if (input?.value.length > 0) {
|
||||
input.select();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user