Support opening selected document
This commit is contained in:
parent
53e5f7289b
commit
c7a1b5b514
@ -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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user