RED-7605: fixed search again.

This commit is contained in:
Nicoleta Panaghiu 2023-10-04 15:14:38 +03:00
parent 8bf0fd0cef
commit 9d41274ff5
3 changed files with 30 additions and 16 deletions

View File

@ -400,7 +400,7 @@ export class FilePreviewScreenComponent
this._changeRef.markForCheck(); this._changeRef.markForCheck();
} }
if (['f', 'F'].includes($event.key) && !$event.ctrlKey) { if (!$event.ctrlKey && !$event.metaKey && ['f', 'F'].includes($event.key)) {
// if you type in an input, don't toggle full-screen // if you type in an input, don't toggle full-screen
if ($event.target instanceof HTMLInputElement || $event.target instanceof HTMLTextAreaElement) { if ($event.target instanceof HTMLInputElement || $event.target instanceof HTMLTextAreaElement) {
return; return;

View File

@ -13,7 +13,7 @@ import { UserPreferenceService } from '@users/user-preference.service';
import { NGXLogger } from 'ngx-logger'; import { NGXLogger } from 'ngx-logger';
import { combineLatest, fromEvent, Observable } from 'rxjs'; import { combineLatest, fromEvent, Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators'; import { map, startWith } from 'rxjs/operators';
import { DISABLED_HOTKEYS, DOCUMENT_LOADING_ERROR, SEARCH_OPTIONS, USELESS_ELEMENTS } from '../utils/constants'; import { DISABLED_HOTKEYS, DOCUMENT_LOADING_ERROR, USELESS_ELEMENTS } from '../utils/constants';
import { asList } from '../utils/functions'; import { asList } from '../utils/functions';
import { Rgb } from '../utils/types'; import { Rgb } from '../utils/types';
import Annotation = Core.Annotations.Annotation; import Annotation = Core.Annotations.Annotation;
@ -35,7 +35,6 @@ export class PdfViewer {
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')), title: inject(TranslateService).instant(_('pdf-viewer.text-popup.actions.search')),
onClick: () => { onClick: () => {
this.activateSearch();
setTimeout(() => this.#searchForSelectedText(), 250); setTimeout(() => this.#searchForSelectedText(), 250);
this.#focusSearch(); this.#focusSearch();
}, },
@ -55,6 +54,15 @@ export class PdfViewer {
readonly isCompareMode: Signal<boolean>; readonly isCompareMode: Signal<boolean>;
readonly totalPages: Signal<number>; readonly totalPages: Signal<number>;
searchOptions = {
caseSensitive: true, // match case
wholeWord: true, // 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
};
constructor( constructor(
private readonly _logger: NGXLogger, private readonly _logger: NGXLogger,
private readonly _errorService: ErrorService, private readonly _errorService: ErrorService,
@ -104,10 +112,12 @@ export class PdfViewer {
} }
activateSearch() { activateSearch() {
this.#instance.UI.openElements(['searchPanel']); this.#instance.UI.searchTextFull('', this.searchOptions);
} }
deactivateSearch() { deactivateSearch() {
this.instance.UI.iframeWindow.document.getElementById('SearchPanel__input').blur();
this.#updateSearchOptions();
this.#instance.UI.closeElements(['searchPanel']); this.#instance.UI.closeElements(['searchPanel']);
} }
@ -257,9 +267,10 @@ export class PdfViewer {
this.activateSearch(); this.activateSearch();
} }
if (this.documentViewer.getSelectedText()) { if (this.documentViewer.getSelectedText()) {
this.#updateSearchOptions();
this.#searchForSelectedText(); this.#searchForSelectedText();
} }
setTimeout(() => this.#focusSearch(), 250); setTimeout(() => this.#focusSearch(), 30);
}); });
} }
@ -267,12 +278,24 @@ export class PdfViewer {
this.#instance.UI.hotkeys.on('esc', e => { this.#instance.UI.hotkeys.on('esc', e => {
e.preventDefault(); e.preventDefault();
if (this.#isElementActive('searchPanel')) { if (this.#isElementActive('searchPanel')) {
this.deactivateSearch();
this.#focusViewer(); this.#focusViewer();
this.deactivateSearch();
} }
}); });
} }
#getSearchOption(optionId: string): boolean {
const iframeWindow = this.#instance.UI.iframeWindow;
const checkbox = iframeWindow.document.getElementById(optionId) as HTMLInputElement;
return checkbox.checked;
}
#updateSearchOptions() {
const wholeWord = this.#getSearchOption('whole-word-option');
const caseSensitive = this.#getSearchOption('case-sensitive-option');
this.searchOptions = { ...this.searchOptions, wholeWord: wholeWord, caseSensitive: caseSensitive };
}
#adjustPage(page: number) { #adjustPage(page: number) {
if (this.isCompareMode()) { if (this.isCompareMode()) {
if (page % 2 === 1) { if (page % 2 === 1) {
@ -287,7 +310,7 @@ export class PdfViewer {
#searchForSelectedText() { #searchForSelectedText() {
const selected = [...new Set(this.documentViewer.getSelectedText().split('\n'))].join('\n'); const selected = [...new Set(this.documentViewer.getSelectedText().split('\n'))].join('\n');
this.#instance.UI.searchTextFull(selected, SEARCH_OPTIONS); this.#instance.UI.searchTextFull(selected, this.searchOptions);
} }
#clearSearchResultsWhenVisibilityChanged() { #clearSearchResultsWhenVisibilityChanged() {

View File

@ -21,15 +21,6 @@ export const ALLOWED_KEYBOARD_SHORTCUTS: List = ['+', '-', 'p', 'r', 'Escape'] a
export const DOCUMENT_LOADING_ERROR = new CustomError(_('error.file-preview.label'), _('error.file-preview.action'), 'iqser:refresh'); export const DOCUMENT_LOADING_ERROR = new CustomError(_('error.file-preview.label'), _('error.file-preview.action'), 'iqser:refresh');
export const SEARCH_OPTIONS = {
caseSensitive: true, // match case
wholeWord: true, // 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
};
export const ViewerEvents = { export const ViewerEvents = {
LOAD_ALL_ANNOTATIONS: 'LOAD_ALL_ANNOTATIONS', LOAD_ALL_ANNOTATIONS: 'LOAD_ALL_ANNOTATIONS',
} as const; } as const;