Skip to content

Commit

Permalink
Merge pull request #1225 from vivliostyle/fix/viewer-find
Browse files Browse the repository at this point in the history
fix(viewer): Current page should be kept after Find results in "Not Found"
  • Loading branch information
MurakamiShinyu authored Oct 3, 2023
2 parents 3e6957c + fb28b64 commit 780da2a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/viewer/src/viewmodels/find-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ class FindBox {
this.status(FindStatus.NotFound);
window.clearInterval(this.intervalID);
this.intervalID = 0;
return;
if (epage !== currentEPage) {
this.viewer.navigateToEPage(currentEPage);
}
}
}, 4);

Expand Down
1 change: 1 addition & 0 deletions packages/viewer/src/viewmodels/marks-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ export class MarksBox {

navigateToMark = (mark: Mark): void => {
const { spineIndex, offsetInItem } = mark.start;
window.history.pushState(null, null);
this.parent.viewer.navigateToPosition({ spineIndex, offsetInItem });
if (!this.pinned()) {
this.detailsElement.open = false;
Expand Down
7 changes: 5 additions & 2 deletions packages/viewer/src/viewmodels/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ class Navigation {
"vivliostyle-page-number",
) as HTMLInputElement;
pageNumberElem.value = pageNumber.toString();
window.history.pushState(null, null);
this.viewer.navigateToEPage(epageNav);

window.setTimeout(() => {
Expand Down Expand Up @@ -362,7 +363,7 @@ class Navigation {
if (this.viewerOptions.renderAllPages()) {
const pageNumber = Number(pageNumberText);
const epageNav = this.viewer.epageFromPageNumber(pageNumber);
this.viewer.navigateToEPage(epageNav, false);
this.viewer.navigateToEPage(epageNav);
} else {
const pageNumberElem = document.getElementById(
"vivliostyle-page-number",
Expand Down Expand Up @@ -416,6 +417,7 @@ class Navigation {

navigateToFirst = (): boolean => {
if (!this.isNavigateToFirstDisabled()) {
window.history.pushState(null, null);
this.viewer.navigateToFirst();
return true;
} else {
Expand All @@ -425,6 +427,7 @@ class Navigation {

navigateToLast = (): boolean => {
if (!this.isNavigateToLastDisabled()) {
window.history.pushState(null, null);
this.viewer.navigateToLast();
return true;
} else {
Expand Down Expand Up @@ -562,7 +565,7 @@ class Navigation {
) as HTMLInputElement;
const pageNumber = Number(pageNumberElem.value);
const epageNav = this.viewer.epageFromPageNumber(pageNumber);
this.viewer.navigateToEPage(epageNav, false);
this.viewer.navigateToEPage(epageNav);

return true;
};
Expand Down
10 changes: 2 additions & 8 deletions packages/viewer/src/viewmodels/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class Viewer {
});
this.coreViewer.addListener("hyperlink", (payload) => {
if (payload.internal) {
window.history.pushState(null, null);
this.navigateToInternalUrl(payload.href);

// When navigate from TOC, TOC box may or may not become hidden by autohide.
Expand Down Expand Up @@ -278,24 +279,18 @@ class Viewer {
}

navigateToFirst(): void {
window.history.pushState(null, null);
this.coreViewer.navigateToPage(Navigation.FIRST);
}

navigateToLast(): void {
window.history.pushState(null, null);
this.coreViewer.navigateToPage(Navigation.LAST);
}

navigateToEPage(epage: number, pushHistory?: boolean): void {
if (pushHistory === undefined || pushHistory) {
window.history.pushState(null, null);
}
navigateToEPage(epage: number): void {
this.coreViewer.navigateToPage(Navigation.EPAGE, epage);
}

navigateToInternalUrl(href: string): void {
window.history.pushState(null, null);
this.coreViewer.navigateToInternalUrl(href);
}

Expand All @@ -304,7 +299,6 @@ class Viewer {
pageIndex?: number;
offsetInItem?: number;
}): void {
window.history.pushState(null, null);
this.coreViewer.navigateToPosition(position);
}

Expand Down

1 comment on commit 780da2a

@vercel
Copy link

@vercel vercel bot commented on 780da2a Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vivliostyle – ./

vivliostyle-git-master-vivliostyle.vercel.app
vivliostyle-vivliostyle.vercel.app
vivliostyle.vercel.app

Please sign in to comment.