RED-7605: fixed search for marked word.

This commit is contained in:
Nicoleta Panaghiu 2023-09-25 15:29:21 +03:00
parent 44515e9f23
commit 1b99ce9dfa
2 changed files with 34 additions and 13 deletions

View File

@ -358,11 +358,12 @@ export class FilePreviewScreenComponent
}
if (['Escape'].includes($event.key)) {
$event.preventDefault();
this.fullScreen = false;
this.closeFullScreen();
this.pdf.deactivateSearch();
this.pdf.focusViewer();
this._changeRef.markForCheck();
window.focus();
}
if (['f', 'F'].includes($event.key) && !$event.ctrlKey) {

View File

@ -102,23 +102,19 @@ export class PdfViewer {
return page$.pipe(map(page => this.#adjustPage(page)));
}
focusSearch() {
const iframeWindow = this.#instance.UI.iframeWindow;
const input = iframeWindow.document.getElementById('SearchPanel__input') as HTMLInputElement;
if (input) {
input.focus();
input.select();
}
}
activateSearch() {
this.#instance.UI.openElements(['searchPanel']);
}
deactivateSearch() {
this.#clearSearchResultsWhenVisibilityChanged();
this.#instance.UI.closeElements(['searchPanel']);
}
focusViewer() {
this.instance.UI.iframeWindow.focus();
}
resetAnnotationActions() {
if (this.#instance.UI.annotationPopup.getItems().length) {
this.#instance.UI.annotationPopup.update([]);
@ -258,7 +254,8 @@ export class PdfViewer {
}
#searchForSelectedText() {
this.#instance.UI.searchTextFull(this.documentViewer.getSelectedText(), SEARCH_OPTIONS);
const selected = [...new Set(this.documentViewer.getSelectedText().split('\n'))].join('\n');
this.#instance.UI.searchTextFull(selected, SEARCH_OPTIONS);
}
#clearSearchResultsWhenVisibilityChanged() {
@ -281,8 +278,13 @@ export class PdfViewer {
#listenForCommandF() {
this.#instance.UI.hotkeys.on('command+f, ctrl+f', e => {
e.preventDefault();
this.activateSearch();
this.focusSearch();
if (!this.#isElementActive('searchPanel')) {
this.activateSearch();
}
if (this.documentViewer.getSelectedText()) {
this.#searchForSelectedText();
}
setTimeout(() => this.#focusSearch(), 250);
});
}
@ -317,4 +319,22 @@ export class PdfViewer {
return WebViewer(options, htmlElement);
}
#isElementActive(element: string): boolean {
return this.#instance.UI.isElementOpen(element);
}
#focusSearch() {
if (this.#isElementActive('textPopup')) {
this.#instance.UI.closeElements(['textPopup']);
}
const iframeWindow = this.#instance.UI.iframeWindow;
const input = iframeWindow.document.getElementById('SearchPanel__input') as HTMLInputElement;
if (input) {
input.focus();
}
if (input.value.length > 0) {
input.select();
}
}
}