Skip to content

Commit c0d113b

Browse files
committed
Normalize workspace zoom step to 5 percent
1 parent 60828e0 commit c0d113b

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

App.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const MIN_LOGGER_HEIGHT = 100;
5050
const PREVIEW_INITIAL_SCALE = 1;
5151
const PREVIEW_MIN_SCALE = 0.25;
5252
const PREVIEW_MAX_SCALE = 5;
53-
const PREVIEW_ZOOM_STEP = 0.25;
53+
const PREVIEW_ZOOM_STEP = 0.05;
5454

5555
const isElectron = !!window.electronAPI;
5656

@@ -263,17 +263,17 @@ export const MainApp: React.FC = () => {
263263

264264
const handlePreviewZoomIn = useCallback(() => {
265265
if (workspaceZoomTarget === 'preview') {
266-
setPreviewScale(prev => clampZoomScale(prev * (1 + PREVIEW_ZOOM_STEP)));
266+
setPreviewScale(prev => clampZoomScale(prev + PREVIEW_ZOOM_STEP));
267267
} else {
268-
setEditorScale(prev => clampZoomScale(prev * (1 + PREVIEW_ZOOM_STEP)));
268+
setEditorScale(prev => clampZoomScale(prev + PREVIEW_ZOOM_STEP));
269269
}
270270
}, [clampZoomScale, workspaceZoomTarget]);
271271

272272
const handlePreviewZoomOut = useCallback(() => {
273273
if (workspaceZoomTarget === 'preview') {
274-
setPreviewScale(prev => clampZoomScale(prev / (1 + PREVIEW_ZOOM_STEP)));
274+
setPreviewScale(prev => clampZoomScale(prev - PREVIEW_ZOOM_STEP));
275275
} else {
276-
setEditorScale(prev => clampZoomScale(prev / (1 + PREVIEW_ZOOM_STEP)));
276+
setEditorScale(prev => clampZoomScale(prev - PREVIEW_ZOOM_STEP));
277277
}
278278
}, [clampZoomScale, workspaceZoomTarget]);
279279

components/ZoomPanContainer.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const ZoomPanContainer = React.forwardRef<HTMLDivElement, ZoomPanContainerProps>
4343
minScale = 0.25,
4444
maxScale = 5,
4545
initialScale = 1,
46-
zoomStep = 0.25,
46+
zoomStep = 0.05,
4747
disableControls = false,
4848
disablePan = false,
4949
disableZoom = false,
@@ -119,10 +119,11 @@ const ZoomPanContainer = React.forwardRef<HTMLDivElement, ZoomPanContainerProps>
119119
}
120120
const direction = deltaY > 0 ? -1 : 1;
121121
const magnitude = Math.min(Math.abs(deltaY) / 300, 1.5);
122-
const factor = 1 + effectiveZoomStep * magnitude;
122+
const stepCount = Math.max(1, Math.round(magnitude));
123+
const deltaScale = effectiveZoomStep * stepCount;
123124
const nextScale = direction > 0
124-
? scaleRef.current * factor
125-
: scaleRef.current / factor;
125+
? scaleRef.current + deltaScale
126+
: scaleRef.current - deltaScale;
126127
setScale(nextScale);
127128
return;
128129
}
@@ -193,8 +194,8 @@ const ZoomPanContainer = React.forwardRef<HTMLDivElement, ZoomPanContainerProps>
193194
}
194195
event.preventDefault();
195196
const isZoomOut = event.shiftKey || event.altKey || event.button === 1;
196-
const factor = 1 + effectiveZoomStep;
197-
setScale(isZoomOut ? scaleRef.current / factor : scaleRef.current * factor);
197+
const deltaScale = effectiveZoomStep;
198+
setScale(isZoomOut ? scaleRef.current - deltaScale : scaleRef.current + deltaScale);
198199
}, [disableZoom, effectiveZoomStep, setScale]);
199200

200201
const handleResetView = useCallback(() => {
@@ -296,7 +297,7 @@ const ZoomPanContainer = React.forwardRef<HTMLDivElement, ZoomPanContainerProps>
296297
tooltip="Zoom out"
297298
variant="ghost"
298299
size="sm"
299-
onClick={() => setScale(scaleRef.current / (1 + zoomStep))}
300+
onClick={() => setScale(scaleRef.current - zoomStep)}
300301
className="text-text-secondary"
301302
>
302303
<MinusIcon className="w-4 h-4" />
@@ -308,7 +309,7 @@ const ZoomPanContainer = React.forwardRef<HTMLDivElement, ZoomPanContainerProps>
308309
tooltip="Zoom in"
309310
variant="ghost"
310311
size="sm"
311-
onClick={() => setScale(scaleRef.current * (1 + zoomStep))}
312+
onClick={() => setScale(scaleRef.current + zoomStep)}
312313
className="text-text-secondary"
313314
>
314315
<PlusIcon className="w-4 h-4" />

contexts/PreviewZoomContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const PreviewZoomProvider: React.FC<PreviewZoomProviderProps> = ({
3636
onScaleChange,
3737
minScale = 0.25,
3838
maxScale = 5,
39-
zoomStep = 0.25,
39+
zoomStep = 0.05,
4040
initialScale = 1,
4141
resetSignal,
4242
onAvailabilityChange,
@@ -52,11 +52,11 @@ export const PreviewZoomProvider: React.FC<PreviewZoomProviderProps> = ({
5252
}, [maxScale, minScale, onScaleChange]);
5353

5454
const zoomIn = useCallback(() => {
55-
setScale(clampedScale * (1 + zoomStep));
55+
setScale(clampedScale + zoomStep);
5656
}, [clampedScale, setScale, zoomStep]);
5757

5858
const zoomOut = useCallback(() => {
59-
setScale(clampedScale / (1 + zoomStep));
59+
setScale(clampedScale - zoomStep);
6060
}, [clampedScale, setScale, zoomStep]);
6161

6262
const reset = useCallback(() => {

0 commit comments

Comments
 (0)