mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Enhancement: next / previous shortcuts for document list (#8309)
This commit is contained in:
@@ -698,5 +698,31 @@ describe('DocumentListComponent', () => {
|
||||
fixture.detectChanges()
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'o' }))
|
||||
expect(detailSpy).toHaveBeenCalledWith(docs[1].id)
|
||||
|
||||
const lotsOfDocs: Document[] = Array.from({ length: 100 }, (_, i) => ({
|
||||
id: i + 1,
|
||||
title: `Doc${i + 1}`,
|
||||
notes: [],
|
||||
tags$: new Subject(),
|
||||
content: `document content ${i + 1}`,
|
||||
}))
|
||||
jest
|
||||
.spyOn(documentListService, 'documents', 'get')
|
||||
.mockReturnValue(lotsOfDocs)
|
||||
jest
|
||||
.spyOn(documentService, 'listAllFilteredIds')
|
||||
.mockReturnValue(of(lotsOfDocs.map((d) => d.id)))
|
||||
jest.spyOn(documentListService, 'getLastPage').mockReturnValue(4)
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(component.list.currentPage).toEqual(1)
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 'ArrowRight', ctrlKey: true })
|
||||
)
|
||||
expect(component.list.currentPage).toEqual(2)
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 'ArrowLeft', ctrlKey: true })
|
||||
)
|
||||
expect(component.list.currentPage).toEqual(1)
|
||||
})
|
||||
})
|
||||
|
@@ -273,6 +273,30 @@ export class DocumentListComponent
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.hotKeyService
|
||||
.addShortcut({
|
||||
keys: 'control.arrowleft',
|
||||
description: $localize`Previous page`,
|
||||
})
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
if (this.list.currentPage > 1) {
|
||||
this.list.currentPage--
|
||||
}
|
||||
})
|
||||
|
||||
this.hotKeyService
|
||||
.addShortcut({
|
||||
keys: 'control.arrowright',
|
||||
description: $localize`Next page`,
|
||||
})
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
if (this.list.currentPage < this.list.getLastPage()) {
|
||||
this.list.currentPage++
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
|
Reference in New Issue
Block a user