Merge branch 'RED-7605' into 'master'

RED-7605: fixed search for marked word.

See merge request redactmanager/red-ui!107
This commit is contained in:
Dan Percic 2023-09-25 14:16:40 +02:00
commit c862c761ff
2 changed files with 36 additions and 23 deletions

View File

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

View File

@ -24,7 +24,7 @@ import TextTool = Core.Tools.TextTool;
@Injectable()
export class PdfViewer {
private readonly _convertPath = inject(BASE_HREF_FN);
readonly #convertPath = inject(BASE_HREF_FN);
#instance: WebViewerInstance;
readonly #licenseKey = inject(LicenseService).activeLicenseKey;
readonly #config = getConfig<AppConfig>();
@ -32,11 +32,12 @@ export class PdfViewer {
readonly #isCompareMode$ = toObservable(this.#isCompareMode);
readonly #searchButton: IHeaderElement = {
type: 'actionButton',
img: this._convertPath('/assets/icons/general/pdftron-action-search.svg'),
img: this.#convertPath('/assets/icons/general/pdftron-action-search.svg'),
title: inject(TranslateService).instant(_('pdf-viewer.text-popup.actions.search')),
onClick: () => {
this.#instance.UI.openElements(['searchPanel']);
this.activateSearch();
setTimeout(() => this.#searchForSelectedText(), 250);
this.#focusSearch();
},
};
readonly #destroyRef = inject(DestroyRef);
@ -102,27 +103,19 @@ export class PdfViewer {
return page$.pipe(map(page => this.#adjustPage(page)));
}
get searchActive() {
return this.instance.UI.isElementOpen('searchPanel');
}
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.#logger.info('[PDF] Reset annotation actions');
@ -153,7 +146,7 @@ export class PdfViewer {
this.#instance = await this.#getInstance(htmlElement);
if (environment.production) {
this.#instance.Core.setCustomFontURL('https://' + window.location.host + this._convertPath('/assets/pdftron'));
this.#instance.Core.setCustomFontURL('https://' + window.location.host + this.#convertPath('/assets/pdftron'));
}
await this.runWithCleanup(async () => {
@ -264,13 +257,13 @@ export class PdfViewer {
#listenForCommandF() {
this.#instance.UI.hotkeys.on('command+f, ctrl+f', e => {
e.preventDefault();
if (!this.searchActive) {
if (!this.#isElementActive('searchPanel')) {
this.activateSearch();
this.focusSearch();
}
if (this.documentViewer.getSelectedText()) {
this.#searchForSelectedText();
}
setTimeout(() => this.#focusSearch(), 250);
});
}
@ -287,7 +280,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() {
@ -332,11 +326,29 @@ export class PdfViewer {
const options: WebViewerOptions = {
licenseKey: this.#licenseKey,
fullAPI: true,
path: this._convertPath('/assets/wv-resources'),
css: this._convertPath('/assets/pdftron/stylesheet.css'),
path: this.#convertPath('/assets/wv-resources'),
css: this.#convertPath('/assets/pdftron/stylesheet.css'),
backendType: 'ems',
};
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();
}
}
}