Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): prevent docx preview zoom from skipping a level (#17323)

Try everything4a3b20a8896b
diff --git a/web/src/components/document-preview/hooks.ts b/web/src/components/document-preview/hooks.ts
index c9de96234a..3caa7b2d16 100644
--- a/web/src/components/document-preview/hooks.ts
+++ b/web/src/components/document-preview/hooks.ts
@@ -363,23 +363,30 @@ export const useCatchDocumentError = (url: string) => {
const ZOOM_STEPS = [25, 50, 75, 100, 125, 150, 175, 200] as const;
const clampZoom = (scale: number, direction: 1 | -1): number => {
- let idx = ZOOM_STEPS.indexOf(scale as (typeof ZOOM_STEPS)[number]);
- if (idx < 0) {
- if (direction > 0) {
- idx = ZOOM_STEPS.findIndex((v) => v > scale);
- } else {
- for (let i = ZOOM_STEPS.length - 1; i >= 0; i--) {
- if (ZOOM_STEPS[i] < scale) {
- idx = i;
- break;
- }
+ const exactIdx = ZOOM_STEPS.indexOf(scale as (typeof ZOOM_STEPS)[number]);
+ let idx: number;
+
+ if (exactIdx >= 0) {
+ // Already on a predefined step: move one step in the zoom direction.
+ idx = exactIdx + direction;
+ } else if (direction > 0) {
+ // Between steps and zooming in: snap up to the next higher step. This
+ // index is already the target, so it must not be advanced again.
+ const next = ZOOM_STEPS.findIndex((v) => v > scale);
+ idx = next < 0 ? ZOOM_STEPS.length - 1 : next;
+ } else {
+ // Between steps and zooming out: snap down to the next lower step.
+ let prev = 0;
+ for (let i = ZOOM_STEPS.length - 1; i >= 0; i--) {
+ if (ZOOM_STEPS[i] < scale) {
+ prev = i;
+ break;
}
}
+ idx = prev;
}
- idx = Math.max(
- 0,
- Math.min(ZOOM_STEPS.length - 1, idx < 0 ? 0 : idx + direction),
- );
+
+ idx = Math.max(0, Math.min(ZOOM_STEPS.length - 1, idx));
return ZOOM_STEPS[idx] ?? scale;
};