From c53713a469060ac474b21345194eb37a7d93f651 Mon Sep 17 00:00:00 2001 From: Guillaume Fontorbe Date: Wed, 21 Feb 2024 15:01:21 +0100 Subject: [PATCH] Fix zoom jump bug (#437) Signed-off-by: Guillaume Fontorbe --- packages/sprotty/src/features/viewport/zoom.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/sprotty/src/features/viewport/zoom.ts b/packages/sprotty/src/features/viewport/zoom.ts index 33cc6a1f..45851147 100644 --- a/packages/sprotty/src/features/viewport/zoom.ts +++ b/packages/sprotty/src/features/viewport/zoom.ts @@ -25,6 +25,7 @@ import { MouseListener } from '../../base/views/mouse-tool'; import { ViewerOptions } from '../../base/views/viewer-options'; import { getWindowScroll } from '../../utils/browser'; import { isViewport } from './model'; +import { limit } from '../../utils/geometry'; export function getZoom(label: SModelElementImpl) { let zoom = 1; @@ -71,7 +72,10 @@ export class ZoomMouseListener extends MouseListener { || zoomFactor < 1 && almostEquals(viewport.zoom, this.viewerOptions.zoomLimits.min)) { return; } - const zoom = viewport.zoom * zoomFactor; + + // 'limitViewport' used by 'SetViewportCommand' will set the zoom to the min max level + // so we need to do this here to to avoid 'jumps' of the diagram based on the viewport.scroll + const zoom = limit(viewport.zoom * zoomFactor, this.viewerOptions.zoomLimits); const viewportOffset = this.getViewportOffset(target.root, event); const offsetFactor = 1.0 / zoom - 1.0 / viewport.zoom; return {