Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Fix: correct save hotkey action when no next document exists (#11027)

shamoone08e34fb903e
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)
+ }
})
}