Merge branch 'RED-10148' into 'master'

RED-10148: fixed text selection; implemented key listener for shift.

See merge request redactmanager/red-ui!717
This commit is contained in:
Valentin-Gabriel Mihai 2024-11-21 17:14:30 +01:00
commit fc3258ad9a
4 changed files with 31 additions and 10 deletions

View File

@ -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<KeyboardEvent>(stopAndPrevent),
log('[PDF] Keyboard shortcut'),
);

View File

@ -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) {

View File

@ -87,3 +87,8 @@ export const DISABLED_HOTKEYS = [
export const AnnotationToolNames = {
AnnotationCreateRectangle: 'AnnotationCreateRectangle',
} as const;
export const SelectionModes = {
RECTANGULAR: 'rectangular',
STRUCTURAL: 'structural',
} as const;

View File

@ -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",