diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index ad962f246..aea549eb4 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -400,7 +400,7 @@ export class FilePreviewScreenComponent 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 ($event.target instanceof HTMLInputElement || $event.target instanceof HTMLTextAreaElement) { return; diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/pdf-viewer.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/pdf-viewer.service.ts index 2890bbf32..5b346e840 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/pdf-viewer.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/pdf-viewer.service.ts @@ -13,7 +13,7 @@ import { UserPreferenceService } from '@users/user-preference.service'; import { NGXLogger } from 'ngx-logger'; import { combineLatest, fromEvent, Observable } from 'rxjs'; 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 { Rgb } from '../utils/types'; import Annotation = Core.Annotations.Annotation; @@ -35,7 +35,6 @@ export class PdfViewer { img: this.#convertPath('/assets/icons/general/pdftron-action-search.svg'), title: inject(TranslateService).instant(_('pdf-viewer.text-popup.actions.search')), onClick: () => { - this.activateSearch(); setTimeout(() => this.#searchForSelectedText(), 250); this.#focusSearch(); }, @@ -55,6 +54,15 @@ export class PdfViewer { readonly isCompareMode: Signal; readonly totalPages: Signal; + 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( private readonly _logger: NGXLogger, private readonly _errorService: ErrorService, @@ -104,10 +112,12 @@ export class PdfViewer { } activateSearch() { - this.#instance.UI.openElements(['searchPanel']); + this.#instance.UI.searchTextFull('', this.searchOptions); } deactivateSearch() { + this.instance.UI.iframeWindow.document.getElementById('SearchPanel__input').blur(); + this.#updateSearchOptions(); this.#instance.UI.closeElements(['searchPanel']); } @@ -257,9 +267,10 @@ export class PdfViewer { this.activateSearch(); } if (this.documentViewer.getSelectedText()) { + this.#updateSearchOptions(); this.#searchForSelectedText(); } - setTimeout(() => this.#focusSearch(), 250); + setTimeout(() => this.#focusSearch(), 30); }); } @@ -267,12 +278,24 @@ export class PdfViewer { this.#instance.UI.hotkeys.on('esc', e => { e.preventDefault(); if (this.#isElementActive('searchPanel')) { - this.deactivateSearch(); 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) { if (this.isCompareMode()) { if (page % 2 === 1) { @@ -287,7 +310,7 @@ export class PdfViewer { #searchForSelectedText() { 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() { diff --git a/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts b/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts index 3d69a1dbb..33ed36234 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts @@ -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 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 = { LOAD_ALL_ANNOTATIONS: 'LOAD_ALL_ANNOTATIONS', } as const;