Support opening selected document

This commit is contained in:
shamoon 2024-04-07 17:50:50 -07:00
parent 53e5f7289b
commit c7a1b5b514
2 changed files with 22 additions and 4 deletions

View File

@ -629,5 +629,13 @@ describe('DocumentListComponent', () => {
const detailSpy = jest.spyOn(component, 'openDocumentDetail') const detailSpy = jest.spyOn(component, 'openDocumentDetail')
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'o' })) document.dispatchEvent(new KeyboardEvent('keydown', { key: 'o' }))
expect(detailSpy).toHaveBeenCalledWith(docs[0]) expect(detailSpy).toHaveBeenCalledWith(docs[0])
jest.spyOn(documentListService, 'documents', 'get').mockReturnValue(docs)
jest
.spyOn(documentListService, 'selected', 'get')
.mockReturnValue(new Set([docs[1].id]))
fixture.detectChanges()
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'o' }))
expect(detailSpy).toHaveBeenCalledWith(docs[1].id)
}) })
}) })

View File

@ -216,11 +216,18 @@ export class DocumentListComponent
}) })
this.hotKeyService this.hotKeyService
.addShortcut({ keys: 'o', description: $localize`Open first document` }) .addShortcut({
keys: 'o',
description: $localize`Open first [selected] document`,
})
.pipe(takeUntil(this.unsubscribeNotifier)) .pipe(takeUntil(this.unsubscribeNotifier))
.subscribe(() => { .subscribe(() => {
if (this.list.documents.length > 0) { if (this.list.documents.length > 0) {
this.openDocumentDetail(this.list.documents[0]) if (this.list.selected.size > 0) {
this.openDocumentDetail(Array.from(this.list.selected)[0])
} else {
this.openDocumentDetail(this.list.documents[0])
}
} }
}) })
} }
@ -301,8 +308,11 @@ export class DocumentListComponent
}) })
} }
openDocumentDetail(document: Document) { openDocumentDetail(document: Document | number) {
this.router.navigate(['documents', document.id]) this.router.navigate([
'documents',
typeof document === 'number' ? document : document.id,
])
} }
toggleSelected(document: Document, event: MouseEvent): void { toggleSelected(document: Document, event: MouseEvent): void {