Enhancement: next / previous shortcuts for document list (#8309)

This commit is contained in:
shamoon 2024-11-18 11:05:00 -08:00 committed by GitHub
parent e4578b4589
commit f0e71330ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 66 additions and 2 deletions

View File

@ -7405,18 +7405,32 @@
<context context-type="linenumber">264</context>
</context-group>
</trans-unit>
<trans-unit id="3629960544875360046" datatype="html">
<source>Previous page</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-list.component.ts</context>
<context context-type="linenumber">280</context>
</context-group>
</trans-unit>
<trans-unit id="3337301694210287595" datatype="html">
<source>Next page</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-list.component.ts</context>
<context context-type="linenumber">292</context>
</context-group>
</trans-unit>
<trans-unit id="2155249406916744630" datatype="html">
<source>View &quot;<x id="PH" equiv-text="this.list.activeSavedViewTitle"/>&quot; saved successfully.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-list.component.ts</context>
<context context-type="linenumber">300</context>
<context context-type="linenumber">324</context>
</context-group>
</trans-unit>
<trans-unit id="6837554170707123455" datatype="html">
<source>View &quot;<x id="PH" equiv-text="savedView.name"/>&quot; created successfully.</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-list/document-list.component.ts</context>
<context context-type="linenumber">343</context>
<context context-type="linenumber">367</context>
</context-group>
</trans-unit>
<trans-unit id="739880801667335279" datatype="html">

View File

@ -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)
})
})

View File

@ -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() {