RED-7605: changed the way selectedText is retrieved.
This commit is contained in:
parent
423059f11a
commit
5cfaaf70a5
@ -42,7 +42,6 @@ export class PdfViewer {
|
||||
},
|
||||
};
|
||||
readonly #destroyRef = inject(DestroyRef);
|
||||
readonly #logger = inject(NGXLogger);
|
||||
readonly #totalPages = signal<number>(0);
|
||||
readonly currentPage$ = inject(ActivatedRoute).queryParamMap.pipe(
|
||||
map(params => Number(params.get('page') ?? '1')),
|
||||
@ -57,14 +56,14 @@ export class PdfViewer {
|
||||
readonly totalPages: Signal<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,
|
||||
@ -168,6 +167,7 @@ export class PdfViewer {
|
||||
this.#setSelectionMode();
|
||||
this.#configureElements();
|
||||
this.#disableHotkeys();
|
||||
this.#getSelectedText();
|
||||
this.#listenForCommandF();
|
||||
this.#listenForEsc();
|
||||
this.#clearSearchResultsWhenVisibilityChanged();
|
||||
@ -264,7 +264,7 @@ export class PdfViewer {
|
||||
} else {
|
||||
this.activateSearch();
|
||||
}
|
||||
if (this.documentViewer.getSelectedText()) {
|
||||
if (this.selectedText.length) {
|
||||
this.#searchForSelectedText();
|
||||
}
|
||||
setTimeout(() => this.#focusSearch(), 40);
|
||||
@ -306,15 +306,14 @@ export class PdfViewer {
|
||||
}
|
||||
|
||||
#searchForSelectedText() {
|
||||
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 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', (q, selectedText) => {
|
||||
this.selectedText = selectedText;
|
||||
});
|
||||
}
|
||||
|
||||
#clearSearchResultsWhenVisibilityChanged() {
|
||||
@ -380,7 +379,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