Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(frontend:files): ignore keyboard events from inactive viewers
johaven40fa2622e417
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.tsindex bbc6159e..f2ee9737 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts@@ -126,6 +126,10 @@ export abstract class FilesViewerEditableBase implements OnDestroy {return !document.activeElement?.closest('.files-viewer-search')}+ protected isActiveDialog(): boolean {+ return this.layout.isDialogActive(this.file().id)+ }+protected async onClose() {if (this.isSaving()) returnif (!this.isReadonly()) {diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.tsindex bb94dcaf..09d22b1d 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts@@ -179,6 +179,7 @@ export class FilesViewerMarkdownComponent extends FilesViewerEditableBase implem@HostListener('document:keydown', ['$event'])onKeyDown(event: KeyboardEvent) {+ if (!this.isActiveDialog()) returnif (event.key === 'Escape' || event.key === 'Esc') {event.preventDefault()event.stopPropagation()diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.tsindex a4b9c214..2aa3b39d 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts@@ -75,6 +75,7 @@ export class FilesViewerTextComponent extends FilesViewerEditableBase implements@HostListener('document:keydown', ['$event'])onKeyDown(event: KeyboardEvent) {+ if (!this.isActiveDialog()) return// ESCif (event.key === 'Escape' || event.key === 'Esc') {event.preventDefault()diff --git a/frontend/src/app/layout/layout.service.ts b/frontend/src/app/layout/layout.service.tsindex 78f2fe23..6fdb4146 100644--- a/frontend/src/app/layout/layout.service.ts+++ b/frontend/src/app/layout/layout.service.ts@@ -67,6 +67,7 @@ export class LayoutService {private readonly screenMediumSize = 767 // pxprivate readonly screenSmallSize = 576 // pxprivate collapseRSideBarTimeoutId: ReturnType<typeof setTimeout> | null = null+ private escapeCloseInProgress = false// Network eventsprivate _networkIsOnline = new BehaviorSubject<boolean>(navigator.onLine)public networkIsOnline: Observable<boolean> = this._networkIsOnline@@ -181,6 +182,10 @@ export class LayoutService {return modal}+ isDialogActive(id: number | string): boolean {+ return this.getLastOpenDialogId() === id+ }+closeDialog(delay: number | null = null, id: number | string = null, all = false) {if (all) {this.bsModal.hide()@@ -189,14 +194,9 @@ export class LayoutService {return}if (!id) {- let last: string | number- const minimizedIds: (string | number)[] = this.windows.getValue().map((w) => w.id)- for (const value of this.modalRefs.keys()) {- if (minimizedIds.indexOf(value) > -1) continue- last = value- }- if (last !== undefined) {- id = last+ const lastOpenDialogId = this.getLastOpenDialogId()+ if (lastOpenDialogId !== null) {+ id = lastOpenDialogId} else {console.warn('Last modal id not found')return@@ -336,8 +336,14 @@ export class LayoutService {}return Promise.reject('blocked-by-interceptor')} else if (reason === 'esc') {- // Manual closing to keep `modalIds` up to date- this.closeDialog()+ // Each modal listens to Escape. Closing one updates the modal count synchronously,+ // which can make the same event close the next modal as it continues propagating.+ if (!this.escapeCloseInProgress && this.atLeastOneModalOpen()) {+ this.escapeCloseInProgress = true+ queueMicrotask(() => (this.escapeCloseInProgress = false))+ // Manual closing to keep `modalRefs` up to date+ this.closeDialog()+ }return Promise.reject('blocked-by-interceptor')} else {// Allow closing in all other cases@@ -355,6 +361,17 @@ export class LayoutService {return null}+ private getLastOpenDialogId(): number | string | null {+ let lastOpenDialogId: number | string | null = null+ const minimizedIds = new Set(this.windows.getValue().map((window) => window.id))+ for (const id of this.modalRefs.keys()) {+ if (!minimizedIds.has(id)) {+ lastOpenDialogId = id+ }+ }+ return lastOpenDialogId+ }+private atLeastOneModalOpen(): boolean {return this.modalRefs.size - this.windows.getValue().length > 0}