RED-6922 fix selected text delay
This commit is contained in:
parent
cea0b23b86
commit
1ab46577f3
@ -158,19 +158,6 @@ export class FilePreviewScreenComponent
|
||||
}
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
const selectedText = this._documentViewer.selectedText();
|
||||
console.log('selectedText', selectedText);
|
||||
const canPerformActions = this.pdfProxyService.canPerformActions();
|
||||
const isCurrentPageExcluded = this.state.file().isPageExcluded(this.pdf.currentPage());
|
||||
|
||||
if ((selectedText.length > 2 || this._isJapaneseString(selectedText)) && canPerformActions && !isCurrentPageExcluded) {
|
||||
this.pdf.enable(textActions);
|
||||
} else {
|
||||
this.pdf.disable(textActions);
|
||||
}
|
||||
});
|
||||
|
||||
effect(() => {
|
||||
if (this._viewModeService.viewMode()) {
|
||||
this.updateViewMode().then();
|
||||
@ -734,6 +721,20 @@ export class FilePreviewScreenComponent
|
||||
),
|
||||
)
|
||||
.subscribe();
|
||||
|
||||
const selectedTextEffect = this._documentViewer.selectedText$.pipe(
|
||||
tap(selectedText => {
|
||||
const canPerformActions = this.pdfProxyService.canPerformActions();
|
||||
const isCurrentPageExcluded = this.state.file().isPageExcluded(this.pdf.currentPage());
|
||||
|
||||
if ((selectedText.length > 2 || this._isJapaneseString(selectedText)) && canPerformActions && !isCurrentPageExcluded) {
|
||||
this.pdf.enable(textActions);
|
||||
} else {
|
||||
this.pdf.disable(textActions);
|
||||
}
|
||||
}),
|
||||
);
|
||||
this.addActiveScreenSubscription = selectedTextEffect.subscribe();
|
||||
}
|
||||
|
||||
#handleDeletedDossier(): void {
|
||||
|
||||
@ -186,14 +186,14 @@ export class PdfProxyService {
|
||||
|
||||
#addManualRedactionOfType(type: ManualRedactionEntryType) {
|
||||
const selectedQuads: Record<string, Quad[]> = this._pdf.documentViewer.getSelectedTextQuads();
|
||||
const text = this._documentViewer.selectedText();
|
||||
const text = this._documentViewer.selectedText;
|
||||
const manualRedactionEntry = this.#getManualRedaction(selectedQuads, text, true);
|
||||
this.manualAnnotationRequested$.next({ manualRedactionEntry, type });
|
||||
}
|
||||
|
||||
#redactText(type: ManualRedactionEntryType) {
|
||||
const selectedQuads: Record<string, Quad[]> = this._pdf.documentViewer.getSelectedTextQuads();
|
||||
const text = this._documentViewer.selectedText();
|
||||
const text = this._documentViewer.selectedText;
|
||||
const manualRedactionEntry = this.#getManualRedaction(selectedQuads, text, true);
|
||||
this.redactTextRequested$.next({ manualRedactionEntry, type });
|
||||
}
|
||||
@ -241,7 +241,7 @@ export class PdfProxyService {
|
||||
this._pdf.enable(TEXT_POPUPS_TO_TOGGLE);
|
||||
this._viewerHeaderService.enable(HEADER_ITEMS_TO_TOGGLE);
|
||||
|
||||
if (this._documentViewer.selectedText().length > 2) {
|
||||
if (this._documentViewer.selectedText.length > 2) {
|
||||
this._pdf.enable([TextPopups.REDACT_TEXT, TextPopups.ADD_HINT, TextPopups.ADD_FALSE_POSITIVE]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { effect, inject, Injectable, Signal, signal } from '@angular/core';
|
||||
import { Core } from '@pdftron/webviewer';
|
||||
import { NGXLogger } from 'ngx-logger';
|
||||
import { fromEvent, Observable } from 'rxjs';
|
||||
import { BehaviorSubject, fromEvent, Observable } from 'rxjs';
|
||||
import { filter, tap } from 'rxjs/operators';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { PdfViewer } from './pdf-viewer.service';
|
||||
@ -20,14 +20,13 @@ export class REDDocumentViewer {
|
||||
#document: DocumentViewer;
|
||||
readonly #loaded = signal(false);
|
||||
readonly #pageComplete = signal<unknown | undefined>(undefined);
|
||||
readonly #selectedText = signal('');
|
||||
readonly #logger = inject(NGXLogger);
|
||||
readonly #userPreferenceService = inject(UserPreferenceService);
|
||||
readonly #pdf = inject(PdfViewer);
|
||||
readonly #activatedRoute = inject(ActivatedRoute);
|
||||
readonly loaded$: Observable<boolean>;
|
||||
keyUp$: Observable<KeyboardEvent>;
|
||||
readonly selectedText: Signal<string>;
|
||||
readonly selectedText$ = new BehaviorSubject('');
|
||||
readonly loaded: Signal<boolean>;
|
||||
readonly pageComplete: Signal<unknown | undefined>;
|
||||
|
||||
@ -35,7 +34,6 @@ export class REDDocumentViewer {
|
||||
this.loaded = this.#loaded.asReadonly();
|
||||
this.loaded$ = toObservable(this.#loaded);
|
||||
this.pageComplete = this.#pageComplete.asReadonly();
|
||||
this.selectedText = this.#selectedText.asReadonly();
|
||||
|
||||
effect(() => {
|
||||
const viewerElement = document.getElementById('viewer');
|
||||
@ -53,6 +51,10 @@ export class REDDocumentViewer {
|
||||
});
|
||||
}
|
||||
|
||||
get selectedText() {
|
||||
return this.selectedText$.value;
|
||||
}
|
||||
|
||||
get PDFDoc() {
|
||||
return this.document?.getPDFDoc();
|
||||
}
|
||||
@ -156,7 +158,7 @@ export class REDDocumentViewer {
|
||||
|
||||
#listenForDocEvents() {
|
||||
this.#document.addEventListener('textSelected', (quads: Quad, selectedText: string, pageNumber: number) => {
|
||||
this.#selectedText.set(selectedText);
|
||||
this.selectedText$.next(selectedText);
|
||||
this.#disableTextPopupIfCompareMode(pageNumber);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user