Merge pull request #13212 from Snuffleupagus/BaseTreeViewer-init-checks
Check that the correct `pdfDocument` is still active, before rendering the outline/attachments/layers
This commit is contained in:
commit
86374d4f75
@ -1383,14 +1383,23 @@ const PDFViewerApplication = {
|
||||
|
||||
onePageRendered.then(() => {
|
||||
pdfDocument.getOutline().then(outline => {
|
||||
if (pdfDocument !== this.pdfDocument) {
|
||||
return; // The document was closed while the outline resolved.
|
||||
}
|
||||
this.pdfOutlineViewer.render({ outline, pdfDocument });
|
||||
});
|
||||
pdfDocument.getAttachments().then(attachments => {
|
||||
if (pdfDocument !== this.pdfDocument) {
|
||||
return; // The document was closed while the attachments resolved.
|
||||
}
|
||||
this.pdfAttachmentViewer.render({ attachments });
|
||||
});
|
||||
// Ensure that the layers accurately reflects the current state in the
|
||||
// viewer itself, rather than the default state provided by the API.
|
||||
pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => {
|
||||
if (pdfDocument !== this.pdfDocument) {
|
||||
return; // The document was closed while the layers resolved.
|
||||
}
|
||||
this.pdfLayerViewer.render({ optionalContentConfig, pdfDocument });
|
||||
});
|
||||
if (
|
||||
|
@ -53,6 +53,15 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
||||
});
|
||||
this.eventBus._on("pagesloaded", evt => {
|
||||
this._isPagesLoaded = !!evt.pagesCount;
|
||||
|
||||
// If the capability is still pending, note the `_dispatchEvent`-method,
|
||||
// we know that the `currentOutlineItem`-button should be enabled here.
|
||||
if (
|
||||
this._currentOutlineItemCapability &&
|
||||
!this._currentOutlineItemCapability.settled
|
||||
) {
|
||||
this._currentOutlineItemCapability.resolve(/* enabled = */ true);
|
||||
}
|
||||
});
|
||||
this.eventBus._on("sidebarviewchanged", evt => {
|
||||
this._sidebarView = evt.view;
|
||||
@ -66,17 +75,32 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
||||
this._pageNumberToDestHashCapability = null;
|
||||
this._currentPageNumber = 1;
|
||||
this._isPagesLoaded = false;
|
||||
|
||||
if (
|
||||
this._currentOutlineItemCapability &&
|
||||
!this._currentOutlineItemCapability.settled
|
||||
) {
|
||||
this._currentOutlineItemCapability.resolve(/* enabled = */ false);
|
||||
}
|
||||
this._currentOutlineItemCapability = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_dispatchEvent(outlineCount) {
|
||||
this._currentOutlineItemCapability = createPromiseCapability();
|
||||
if (
|
||||
outlineCount === 0 ||
|
||||
this._pdfDocument?.loadingParams.disableAutoFetch
|
||||
) {
|
||||
this._currentOutlineItemCapability.resolve(/* enabled = */ false);
|
||||
}
|
||||
|
||||
this.eventBus.dispatch("outlineloaded", {
|
||||
source: this,
|
||||
outlineCount,
|
||||
enableCurrentOutlineItemButton:
|
||||
outlineCount > 0 && !this._pdfDocument?.loadingParams.disableAutoFetch,
|
||||
currentOutlineItemPromise: this._currentOutlineItemCapability.promise,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -425,11 +425,12 @@ class PDFSidebar {
|
||||
this.eventBus._on("outlineloaded", evt => {
|
||||
onTreeLoaded(evt.outlineCount, this.outlineButton, SidebarView.OUTLINE);
|
||||
|
||||
if (evt.enableCurrentOutlineItemButton) {
|
||||
this.pdfViewer.pagesPromise.then(() => {
|
||||
this._currentOutlineItemButton.disabled = !this.isInitialViewSet;
|
||||
});
|
||||
}
|
||||
evt.currentOutlineItemPromise.then(enabled => {
|
||||
if (!this.isInitialViewSet) {
|
||||
return;
|
||||
}
|
||||
this._currentOutlineItemButton.disabled = !enabled;
|
||||
});
|
||||
});
|
||||
|
||||
this.eventBus._on("attachmentsloaded", evt => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user