Skip to content

Commit

Permalink
EPUB/snapshot: Don't throw when navigating past end of nav stack
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek committed Sep 26, 2023
1 parent 6baeadc commit 90b09e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/dom/epub/epub-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,17 +910,21 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {

// This is like back/forward navigation in browsers. Try Cmd-ArrowLeft and Cmd-ArrowRight in PDF view
navigateBack() {
this.navigate({ pageNumber: this._navStack.popBack() }, {
skipNavStack: true,
behavior: 'auto',
});
if (this._navStack.canPopBack()) {
this.navigate({ pageNumber: this._navStack.popBack() }, {
skipNavStack: true,
behavior: 'auto',
});
}
}

navigateForward() {
this.navigate({ pageNumber: this._navStack.popForward() }, {
skipNavStack: true,
behavior: 'auto',
});
if (this._navStack.canPopForward()) {
this.navigate({ pageNumber: this._navStack.popForward() }, {
skipNavStack: true,
behavior: 'auto',
});
}
}

navigateToFirstPage() {
Expand Down
12 changes: 8 additions & 4 deletions src/dom/snapshot/snapshot-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,17 @@ class SnapshotView extends DOMView<SnapshotViewState, SnapshotViewData> {
}

navigateBack() {
this._iframeWindow.scrollTo(...this._navStack.popBack());
this._handleViewUpdate();
if (this._navStack.canPopBack()) {
this._iframeWindow.scrollTo(...this._navStack.popBack());
this._handleViewUpdate();
}
}

navigateForward() {
this._iframeWindow.scrollTo(...this._navStack.popForward());
this._handleViewUpdate();
if (this._navStack.canPopForward()) {
this._iframeWindow.scrollTo(...this._navStack.popForward());
this._handleViewUpdate();
}
}

// Still need to figure out how this is going to work
Expand Down

0 comments on commit 90b09e8

Please sign in to comment.