fix(双页跳转): 修复双页目录跳转错页
build.yaml / build (push) Successful in 47s

This commit is contained in:
xiaoqidun committed 2026-10-20 21:12:55 +08:00
1 parent 3227134bfc
commit 3f774056da
1 file changed
+49 -33
+49 -33
View File
@@ -117,6 +117,7 @@ const state = {
fontSyncing: false, fontSyncing: false,
doc: null, doc: null,
pageIndex: 0, pageIndex: 0,
pageNavigation: null,
scale: 1, scale: 1,
rotation: 0, rotation: 0,
panMode: false, panMode: false,
@@ -5632,6 +5633,7 @@ async function renderPage(index, options = {}) {
if (index < 0 || index >= pageCount) { if (index < 0 || index >= pageCount) {
return null; return null;
} }
if (options.navigation !== state.pageNavigation) state.pageNavigation = null;
if (!options.keepBusy && index !== state.pageIndex) { if (!options.keepBusy && index !== state.pageIndex) {
if (!await canvasEditor.commitNudge() || !await canvasEditor.commitText() || !await canvasEditor.commitCrop() || openSeq !== state.openSeq) return null; if (!await canvasEditor.commitNudge() || !await canvasEditor.commitText() || !await canvasEditor.commitCrop() || openSeq !== state.openSeq) return null;
} }
@@ -8980,6 +8982,7 @@ function renderPageFlow() {
} }
function resetPageFlow(keepCache = false) { function resetPageFlow(keepCache = false) {
state.pageNavigation = null;
if (!keepCache) { if (!keepCache) {
state.pageCache.clear(); state.pageCache.clear();
releasePageResources(); releasePageResources();
@@ -9613,40 +9616,48 @@ async function navigateDestination(dest, openAction) {
return; return;
} }
const seq = state.openSeq, scale = state.scale; const seq = state.openSeq, scale = state.scale;
await renderPage(index, { fit: false, scroll: false, openAction }); const navigation = state.pageNavigation = { openSeq: seq, index };
if (openAction && state.openActionTask !== openAction) return false; try {
if (seq !== state.openSeq || state.pageIndex !== index) return; await renderPage(index, { fit: false, scroll: false, openAction, navigation });
const page = state.doc.pages[index], size = pageViewSize(page), space = pageSpace(); if (openAction && state.openActionTask !== openAction) return false;
const width = el.viewerPanel.clientWidth - space * 2, height = el.viewerPanel.clientHeight - space * 2; if (seq !== state.openSeq || state.pageIndex !== index || state.pageNavigation !== navigation) return;
let left = dest.omitLeft ? 0 : (dest.left ?? 0); const page = state.doc.pages[index], size = pageViewSize(page), space = pageSpace();
let top = dest.omitTop ? 0 : (dest.top ?? 0); const width = el.viewerPanel.clientWidth - space * 2, height = el.viewerPanel.clientHeight - space * 2;
if (dest.type === "Fit") { let left = dest.omitLeft ? 0 : (dest.left ?? 0);
fitHeight(false); let top = dest.omitTop ? 0 : (dest.top ?? 0);
scrollToPage(index); if (dest.type === "Fit") {
return; fitHeight(false);
} else if (dest.type === "FitH") { scrollToPage(index);
setScale(fitWidthScale(page), false); return;
left = 0; } else if (dest.type === "FitH") {
} else if (dest.type === "FitV") { setScale(fitWidthScale(page), false);
setScale(height / (size.height * MM_TO_PX), false); left = 0;
top = 0; } else if (dest.type === "FitV") {
} else if (dest.type === "FitR") { setScale(height / (size.height * MM_TO_PX), false);
const a = destinationPoint(page, left, top), b = destinationPoint(page, dest.right, dest.bottom); top = 0;
if (dest.right <= left || dest.bottom <= top) return; } else if (dest.type === "FitR") {
setScale(Math.min(width / Math.abs(b.x - a.x), height / Math.abs(b.y - a.y)) / MM_TO_PX, false); const a = destinationPoint(page, left, top), b = destinationPoint(page, dest.right, dest.bottom);
} else { if (dest.right <= left || dest.bottom <= top) return;
setScale(!dest.omitZoom && dest.zoom > 0 ? dest.zoom : scale, false); setScale(Math.min(width / Math.abs(b.x - a.x), height / Math.abs(b.y - a.y)) / MM_TO_PX, false);
} else {
setScale(!dest.omitZoom && dest.zoom > 0 ? dest.zoom : scale, false);
}
const point = destinationPoint(page, left, top);
if (dest.type === "FitR") {
const bottom = destinationPoint(page, dest.right, dest.bottom);
point.x = Math.min(point.x, bottom.x);
point.y = Math.min(point.y, bottom.y);
}
if (state.pageWindow) syncPageWindow(state.pageWindow, state.pageWindow.offsets[index]);
const node = pageShell(index), shell = node.getBoundingClientRect(), viewer = el.viewerPanel.getBoundingClientRect();
el.viewerPanel.scrollLeft += shell.left + (node.clientLeft || 0) - viewer.left - (el.viewerPanel.clientLeft || 0) + point.x * MM_TO_PX * state.scale;
scrollViewerBy(shell.top + (node.clientTop || 0) - viewer.top - (el.viewerPanel.clientTop || 0) + point.y * MM_TO_PX * state.scale);
} finally {
if (state.pageNavigation === navigation) {
if (seq !== state.openSeq || index !== state.pageIndex) state.pageNavigation = null;
else Object.assign(navigation, { top: state.pageWindow ? pageWindowTop(state.pageWindow) : el.viewerPanel.scrollTop, left: el.viewerPanel.scrollLeft });
}
} }
const point = destinationPoint(page, left, top);
if (dest.type === "FitR") {
const bottom = destinationPoint(page, dest.right, dest.bottom);
point.x = Math.min(point.x, bottom.x);
point.y = Math.min(point.y, bottom.y);
}
if (state.pageWindow) syncPageWindow(state.pageWindow, state.pageWindow.offsets[index]);
const node = pageShell(index), shell = node.getBoundingClientRect(), viewer = el.viewerPanel.getBoundingClientRect();
el.viewerPanel.scrollLeft += shell.left + (node.clientLeft || 0) - viewer.left - (el.viewerPanel.clientLeft || 0) + point.x * MM_TO_PX * state.scale;
scrollViewerBy(shell.top + (node.clientTop || 0) - viewer.top - (el.viewerPanel.clientTop || 0) + point.y * MM_TO_PX * state.scale);
} }
function createTextLayer(text) { function createTextLayer(text) {
@@ -10006,6 +10017,11 @@ function schedulePageSync() {
function syncCurrentPageFromScroll() { function syncCurrentPageFromScroll() {
if (state.openActionTask?.navigating) return; if (state.openActionTask?.navigating) return;
syncPageWindow(state.pageWindow); syncPageWindow(state.pageWindow);
const navigation = state.pageNavigation;
const top = state.pageWindow ? pageWindowTop(state.pageWindow) : el.viewerPanel.scrollTop;
if (navigation?.openSeq === state.openSeq && navigation.index === state.pageIndex
&& (navigation.top === undefined || Math.abs(navigation.top - top) < 1 && Math.abs(navigation.left - el.viewerPanel.scrollLeft) < 1)) return;
state.pageNavigation = null;
if (canvasEditor.input || canvasEditor.drag || canvasEditor.crop) return; if (canvasEditor.input || canvasEditor.drag || canvasEditor.crop) return;
const shell = pageShellFromView(); const shell = pageShellFromView();
if (!shell) { if (!shell) {