From 1e69609ce46f22ae981eb611473b975244dc7c5e Mon Sep 17 00:00:00 2001 From: zsviczian Date: Mon, 31 Oct 2022 06:23:05 +0100 Subject: [PATCH] fix: consistent use of ZOOM_STEP (#5801) introduce MIN_ZOOM, consistent use of ZOOM_STEP --- src/actions/actionCanvas.tsx | 4 ++-- src/components/App.tsx | 3 ++- src/constants.ts | 1 + src/scene/zoom.ts | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index e8062355..3e1bd5f3 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -2,7 +2,7 @@ import { ColorPicker } from "../components/ColorPicker"; import { eraser, zoomIn, zoomOut } from "../components/icons"; import { ToolButton } from "../components/ToolButton"; import { DarkModeToggle } from "../components/DarkModeToggle"; -import { THEME, ZOOM_STEP } from "../constants"; +import { MIN_ZOOM, THEME, ZOOM_STEP } from "../constants"; import { getCommonBounds, getNonDeletedElements } from "../element"; import { ExcalidrawElement } from "../element/types"; import { t } from "../i18n"; @@ -206,7 +206,7 @@ const zoomValueToFitBoundsOnViewport = ( const zoomAdjustedToSteps = Math.floor(smallestZoomValue / ZOOM_STEP) * ZOOM_STEP; const clampedZoomValueToFitElements = Math.min( - Math.max(zoomAdjustedToSteps, ZOOM_STEP), + Math.max(zoomAdjustedToSteps, MIN_ZOOM), 1, ); return clampedZoomValueToFitElements as NormalizedZoomValue; diff --git a/src/components/App.tsx b/src/components/App.tsx index a357a9b0..b8128459 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -76,6 +76,7 @@ import { THEME, TOUCH_CTX_MENU_TIMEOUT, VERTICAL_ALIGN, + ZOOM_STEP, } from "../constants"; import { loadFromBlob } from "../data"; import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library"; @@ -6097,7 +6098,7 @@ class App extends React.Component { // note that event.ctrlKey is necessary to handle pinch zooming if (event.metaKey || event.ctrlKey) { const sign = Math.sign(deltaY); - const MAX_STEP = 10; + const MAX_STEP = ZOOM_STEP * 100; const absDelta = Math.abs(deltaY); let delta = deltaY; if (absDelta > MAX_STEP) { diff --git a/src/constants.ts b/src/constants.ts index 87ffa9c8..dab82771 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -122,6 +122,7 @@ export const TITLE_TIMEOUT = 10000; export const VERSION_TIMEOUT = 30000; export const SCROLL_TIMEOUT = 100; export const ZOOM_STEP = 0.1; +export const MIN_ZOOM = 0.1; export const HYPERLINK_TOOLTIP_DELAY = 300; // Report a user inactive after IDLE_THRESHOLD milliseconds diff --git a/src/scene/zoom.ts b/src/scene/zoom.ts index 9c0a933a..59b6afe1 100644 --- a/src/scene/zoom.ts +++ b/src/scene/zoom.ts @@ -1,7 +1,8 @@ +import { MIN_ZOOM } from "../constants"; import { AppState, NormalizedZoomValue } from "../types"; export const getNormalizedZoom = (zoom: number): NormalizedZoomValue => { - return Math.max(0.1, Math.min(zoom, 30)) as NormalizedZoomValue; + return Math.max(MIN_ZOOM, Math.min(zoom, 30)) as NormalizedZoomValue; }; export const getStateForZoom = (