Merge branch 'RED-10563' into 'master'

RED-10563: fixed key actions not prevented when input is focused.

See merge request redactmanager/red-ui!735
This commit is contained in:
Valentin-Gabriel Mihai 2024-11-29 11:40:02 +01:00
commit 3be593f464
5 changed files with 26 additions and 23 deletions

View File

@ -16,6 +16,7 @@ import { HighlightsSeparatorComponent } from '../highlights-separator/highlights
import { AnnotationWrapperComponent } from '../annotation-wrapper/annotation-wrapper.component'; import { AnnotationWrapperComponent } from '../annotation-wrapper/annotation-wrapper.component';
import { AnnotationReferencesListComponent } from '../annotation-references-list/annotation-references-list.component'; import { AnnotationReferencesListComponent } from '../annotation-references-list/annotation-references-list.component';
import { Clipboard } from '@angular/cdk/clipboard'; import { Clipboard } from '@angular/cdk/clipboard';
import { isTargetInput } from '@utils/functions';
@Component({ @Component({
selector: 'redaction-annotations-list', selector: 'redaction-annotations-list',
@ -68,7 +69,7 @@ export class AnnotationsListComponent extends HasScrollbarDirective {
console.log('Selected Annotation:', annotation); console.log('Selected Annotation:', annotation);
} }
if (($event?.target as IqserEventTarget)?.localName === 'input') { if (isTargetInput($event)) {
return; return;
} }

View File

@ -50,6 +50,7 @@ import { ALL_HOTKEYS } from '../../utils/constants';
import { AnnotationDrawService } from '../../../pdf-viewer/services/annotation-draw.service'; import { AnnotationDrawService } from '../../../pdf-viewer/services/annotation-draw.service';
import { FileManagementService } from '@services/files/file-management.service'; import { FileManagementService } from '@services/files/file-management.service';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { isTargetInput, isTargetTextArea } from '@utils/functions';
@Component({ @Component({
selector: 'redaction-file-header', selector: 'redaction-file-header',
@ -178,7 +179,6 @@ export class FileHeaderComponent implements OnInit, AfterViewInit, OnDetach, OnD
this.fullScreen = false; this.fullScreen = false;
} }
} }
@Bind() @Bind()
handleKeyEvent($event: KeyboardEvent) { handleKeyEvent($event: KeyboardEvent) {
if (this._router.url.indexOf('/file/') < 0) { if (this._router.url.indexOf('/file/') < 0) {
@ -210,29 +210,26 @@ export class FileHeaderComponent implements OnInit, AfterViewInit, OnDetach, OnD
this._changeRef.markForCheck(); this._changeRef.markForCheck();
} }
if ($event.key === 'F5') {
window.location.reload();
}
if (isTargetInput($event) || isTargetTextArea($event)) {
return;
}
if (!$event.ctrlKey && !$event.metaKey && ['f', 'F'].includes($event.key)) { 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;
}
this.toggleFullScreen(); this.toggleFullScreen();
return; return;
} }
if (['h', 'H'].includes($event.key)) { if (['h', 'H'].includes($event.key)) {
if ($event.target instanceof HTMLInputElement || $event.target instanceof HTMLTextAreaElement) {
return;
}
this._ngZone.run(() => { this._ngZone.run(() => {
window.focus(); window.focus();
this._helpModeService.activateHelpMode(false); this._helpModeService.activateHelpMode(false);
}); });
return; return;
} }
if ($event.key === 'F5') {
window.location.reload();
}
} }
#openFullScreen() { #openFullScreen() {

View File

@ -59,7 +59,7 @@ import { PageExclusionComponent } from '../page-exclusion/page-exclusion.compone
import { PagesComponent } from '../pages/pages.component'; import { PagesComponent } from '../pages/pages.component';
import { ReadonlyBannerComponent } from '../readonly-banner/readonly-banner.component'; import { ReadonlyBannerComponent } from '../readonly-banner/readonly-banner.component';
import { DocumentInfoComponent } from '../document-info/document-info.component'; import { DocumentInfoComponent } from '../document-info/document-info.component';
import { getLast } from '@utils/functions'; import { getLast, isTargetInput } from '@utils/functions';
import { ALL_ANNOTATIONS_PAGE } from '../../utils/constants'; import { ALL_ANNOTATIONS_PAGE } from '../../utils/constants';
const COMMAND_KEY_ARRAY = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Escape']; const COMMAND_KEY_ARRAY = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Escape'];
@ -251,11 +251,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
handleKeyEvent($event: KeyboardEvent): void { handleKeyEvent($event: KeyboardEvent): void {
const multiSelectServiceInactive = untracked(this.multiSelectService.inactive); const multiSelectServiceInactive = untracked(this.multiSelectService.inactive);
if ( if (!ALL_HOTKEY_ARRAY.includes($event.key) || this._dialog.openDialogs.length || isTargetInput($event)) {
!ALL_HOTKEY_ARRAY.includes($event.key) ||
this._dialog.openDialogs.length ||
($event.target as IqserEventTarget).localName === 'input'
) {
return; return;
} }
@ -342,7 +338,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
} }
preventKeyDefault($event: KeyboardEvent): void { preventKeyDefault($event: KeyboardEvent): void {
if (COMMAND_KEY_ARRAY.includes($event.key) && !(($event.target as any).localName === 'input')) { if (COMMAND_KEY_ARRAY.includes($event.key) && !isTargetInput($event)) {
$event.preventDefault(); $event.preventDefault();
} }
} }

View File

@ -14,6 +14,7 @@ import { PdfViewer } from './pdf-viewer.service';
import Color = Core.Annotations.Color; import Color = Core.Annotations.Color;
import DocumentViewer = Core.DocumentViewer; import DocumentViewer = Core.DocumentViewer;
import Quad = Core.Math.Quad; import Quad = Core.Math.Quad;
import { isTargetInput } from '@utils/functions';
@Injectable() @Injectable()
export class REDDocumentViewer { export class REDDocumentViewer {
@ -71,12 +72,12 @@ export class REDDocumentViewer {
return fromEvent<KeyboardEvent>(this.#document, 'keyUp').pipe( return fromEvent<KeyboardEvent>(this.#document, 'keyUp').pipe(
tap(stopAndPreventIfNotAllowed), tap(stopAndPreventIfNotAllowed),
filter($event => { filter($event => {
if (($event.target as HTMLElement)?.tagName?.toLowerCase() === 'input') { if (isTargetInput($event)) {
if ($event.key === 'Escape') { if ($event.key === 'Escape') {
return true; return true;
} }
} }
return ($event.target as HTMLElement)?.tagName?.toLowerCase() !== 'input'; return isTargetInput($event);
}), }),
filter($event => $event.key.startsWith('Arrow') || ['f', 'h', 'H', 'Escape', 'Shift'].includes($event.key)), filter($event => $event.key.startsWith('Arrow') || ['f', 'h', 'H', 'Escape', 'Shift'].includes($event.key)),
tap<KeyboardEvent>(stopAndPrevent), tap<KeyboardEvent>(stopAndPrevent),

View File

@ -1,5 +1,5 @@
import { ITrackable } from '@iqser/common-ui'; import { ITrackable } from '@iqser/common-ui';
import type { List } from '@iqser/common-ui/lib/utils'; import type { IqserEventTarget, List } from '@iqser/common-ui/lib/utils';
import type { AnnotationWrapper } from '@models/file/annotation.wrapper'; import type { AnnotationWrapper } from '@models/file/annotation.wrapper';
import { Dayjs } from 'dayjs'; import { Dayjs } from 'dayjs';
import { AbstractControl } from '@angular/forms'; import { AbstractControl } from '@angular/forms';
@ -149,3 +149,11 @@ export function urlFileId() {
export function formControlToSignal<T>(control: AbstractControl<T>) { export function formControlToSignal<T>(control: AbstractControl<T>) {
return toSignal(control.valueChanges, { initialValue: control.value }); return toSignal(control.valueChanges, { initialValue: control.value });
} }
export function isTargetInput(event: Event) {
return (event?.target as IqserEventTarget)?.localName === 'input';
}
export function isTargetTextArea(event: Event) {
return (event?.target as IqserEventTarget)?.localName === 'textarea';
}