From e08e34fb903e76025b9ae273a02f4bae8948347c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 7 Oct 2025 07:20:11 -0700 Subject: [PATCH] Fix: correct save hotkey action when no next document exists (#11027) --- .../document-detail.component.spec.ts | 19 +++++++++++++++---- .../document-detail.component.ts | 5 ++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts index 97dae19b7..752df3b21 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.spec.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.spec.ts @@ -1212,7 +1212,7 @@ describe('DocumentDetailComponent', () => { it('should support keyboard shortcuts', () => { initNormally() - jest.spyOn(component, 'hasNext').mockReturnValue(true) + const hasNextSpy = jest.spyOn(component, 'hasNext').mockReturnValue(true) const nextSpy = jest.spyOn(component, 'nextDoc') document.dispatchEvent( new KeyboardEvent('keydown', { key: 'arrowright', ctrlKey: true }) @@ -1226,21 +1226,32 @@ describe('DocumentDetailComponent', () => { ) expect(prevSpy).toHaveBeenCalled() - jest.spyOn(openDocumentsService, 'isDirty').mockReturnValue(true) + const isDirtySpy = jest + .spyOn(openDocumentsService, 'isDirty') + .mockReturnValue(true) const saveSpy = jest.spyOn(component, 'save') document.dispatchEvent( new KeyboardEvent('keydown', { key: 's', ctrlKey: true }) ) expect(saveSpy).toHaveBeenCalled() - jest.spyOn(openDocumentsService, 'isDirty').mockReturnValue(true) - jest.spyOn(component, 'hasNext').mockReturnValue(true) + hasNextSpy.mockReturnValue(true) const saveNextSpy = jest.spyOn(component, 'saveEditNext') document.dispatchEvent( new KeyboardEvent('keydown', { key: 's', ctrlKey: true, shiftKey: true }) ) expect(saveNextSpy).toHaveBeenCalled() + saveSpy.mockClear() + saveNextSpy.mockClear() + isDirtySpy.mockReturnValue(true) + hasNextSpy.mockReturnValue(false) + document.dispatchEvent( + new KeyboardEvent('keydown', { key: 's', ctrlKey: true, shiftKey: true }) + ) + expect(saveNextSpy).not.toHaveBeenCalled() + expect(saveSpy).toHaveBeenCalledWith(true) + const closeSpy = jest.spyOn(component, 'close') document.dispatchEvent(new KeyboardEvent('keydown', { key: 'escape' })) expect(closeSpy).toHaveBeenCalled() diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts index bea5577dc..c2780652a 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.ts +++ b/src-ui/src/app/components/document-detail/document-detail.component.ts @@ -615,7 +615,10 @@ export class DocumentDetailComponent }) .pipe(takeUntil(this.unsubscribeNotifier)) .subscribe(() => { - if (this.openDocumentService.isDirty(this.document)) this.saveEditNext() + if (this.openDocumentService.isDirty(this.document)) { + if (this.hasNext()) this.saveEditNext() + else this.save(true) + } }) }