From 2632675cbecf3efc76687db902b6c926f2295d05 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Thu, 21 Nov 2024 18:12:45 +0200 Subject: [PATCH] RED-10148: fixed text selection; implemented key listener for shift. --- .../services/document-viewer.service.ts | 2 +- .../pdf-viewer/services/pdf-viewer.service.ts | 30 ++++++++++++++----- .../app/modules/pdf-viewer/utils/constants.ts | 5 ++++ apps/red-ui/src/assets/config/config.json | 4 +-- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts index fc85b35ce..88fbff253 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts @@ -78,7 +78,7 @@ export class REDDocumentViewer { } return ($event.target as HTMLElement)?.tagName?.toLowerCase() !== 'input'; }), - filter($event => $event.key.startsWith('Arrow') || ['f', 'h', 'H', 'Escape'].includes($event.key)), + filter($event => $event.key.startsWith('Arrow') || ['f', 'h', 'H', 'Escape', 'Shift'].includes($event.key)), tap(stopAndPrevent), log('[PDF] Keyboard shortcut'), ); 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 8f234d5d8..5be425c50 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, USELESS_ELEMENTS } from '../utils/constants'; +import { DISABLED_HOTKEYS, DOCUMENT_LOADING_ERROR, SelectionModes, USELESS_ELEMENTS } from '../utils/constants'; import { asList } from '../utils/functions'; import { Rgb } from '../utils/types'; import { REDAnnotationManager } from './annotation-manager.service'; @@ -160,12 +160,13 @@ export class PdfViewer { this.pageChanged$ = this.#pageChanged$.pipe(shareDistinctLast()); this.#totalPages$.pipe(takeUntilDestroyed(this.#destroyRef)).subscribe(pages => this.#totalPages.set(pages)); - this.#setSelectionMode(); + this.#setSelectionMode(this.#config.SELECTION_MODE); this.#configureElements(); this.#disableHotkeys(); this.#getSelectedText(); this.#listenForCommandF(); this.#listenForEsc(); + this.#listenForShift(); this.#clearSearchResultsWhenVisibilityChanged(); }); @@ -258,7 +259,7 @@ export class PdfViewer { } #listenForCommandF() { - this.#instance.UI.hotkeys.on('command+f, ctrl+f', e => { + this.#instance.UI.hotkeys.on('command+f, ctrl+f', (e: KeyboardEvent) => { e.preventDefault(); if (this.#isElementActive('searchPanel')) { this.#updateSearchOptions(); @@ -274,11 +275,11 @@ export class PdfViewer { #listenForEsc() { this.#instance.UI.hotkeys.on('esc', { - keydown: e => { + keydown: (e: KeyboardEvent) => { e.preventDefault(); this.#clickSelectToolButton(); }, - keyup: e => { + keyup: (e: KeyboardEvent) => { e.preventDefault(); if (this.#isElementActive('searchPanel') && !this._annotationManager.resizingAnnotationId) { this.#focusViewer(); @@ -289,6 +290,21 @@ export class PdfViewer { }); } + #listenForShift() { + this.#instance.UI.iframeWindow.addEventListener('keydown', e => { + e.preventDefault(); + if (e.key === 'Shift') { + this.#setSelectionMode(SelectionModes.RECTANGULAR); + } + }); + this.#instance.UI.iframeWindow.addEventListener('keyup', e => { + e.preventDefault(); + if (e.key === 'Shift') { + this.#setSelectionMode(SelectionModes.STRUCTURAL); + } + }); + } + #getSearchOption(optionId: string): boolean { const iframeWindow = this.#instance.UI.iframeWindow; const checkbox = iframeWindow.document.getElementById(optionId) as HTMLInputElement; @@ -350,9 +366,9 @@ export class PdfViewer { this.#instance.UI.disableElements(USELESS_ELEMENTS); } - #setSelectionMode(): void { + #setSelectionMode(selectionMode: string): void { const textTool = this.#instance.Core.Tools.TextTool as unknown as TextTool; - textTool.SELECTION_MODE = this.#config.SELECTION_MODE; + textTool.SELECTION_MODE = selectionMode; } #getInstance(htmlElement: HTMLElement) { 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 6479fd377..9e679d063 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 @@ -87,3 +87,8 @@ export const DISABLED_HOTKEYS = [ export const AnnotationToolNames = { AnnotationCreateRectangle: 'AnnotationCreateRectangle', } as const; + +export const SelectionModes = { + RECTANGULAR: 'rectangular', + STRUCTURAL: 'structural', +} as const; diff --git a/apps/red-ui/src/assets/config/config.json b/apps/red-ui/src/assets/config/config.json index 202f3b9b8..deb14e6da 100644 --- a/apps/red-ui/src/assets/config/config.json +++ b/apps/red-ui/src/assets/config/config.json @@ -1,7 +1,7 @@ { "ADMIN_CONTACT_NAME": null, "ADMIN_CONTACT_URL": null, - "API_URL": "https://maverick2.iqser.cloud", + "API_URL": "https://dan1.iqser.cloud", "APP_NAME": "RedactManager", "IS_DOCUMINE": false, "RULE_EDITOR_DEV_ONLY": false, @@ -13,7 +13,7 @@ "MAX_RETRIES_ON_SERVER_ERROR": 3, "OAUTH_CLIENT_ID": "redaction", "OAUTH_IDP_HINT": null, - "OAUTH_URL": "https://maverick2.iqser.cloud/auth", + "OAUTH_URL": "https://dan1.iqser.cloud/auth", "RECENT_PERIOD_IN_HOURS": 24, "SELECTION_MODE": "structural", "MANUAL_BASE_URL": "https://docs.redactmanager.com/preview",