Skip to content

Commit ad40dba

Browse files
committed
refactor zoom controls
1 parent 4cdae05 commit ad40dba

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
lines changed

webview-ui/src/components/common/IconButton.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
interface IconButtonProps {
22
icon: string
3-
onClick: (e: React.MouseEvent) => void
3+
onClick?: (e: React.MouseEvent) => void
4+
onMouseDown?: (e: React.MouseEvent) => void
5+
onMouseUp?: (e: React.MouseEvent) => void
6+
onMouseLeave?: (e: React.MouseEvent) => void
47
title?: string
58
size?: "small" | "medium"
69
variant?: "default" | "transparent"
710
}
811

9-
export function IconButton({ icon, onClick, title, size = "medium", variant = "default" }: IconButtonProps) {
12+
export function IconButton({
13+
icon,
14+
onClick,
15+
onMouseDown,
16+
onMouseUp,
17+
onMouseLeave,
18+
title,
19+
size = "medium",
20+
variant = "default",
21+
}: IconButtonProps) {
1022
const sizeClasses = {
1123
small: "w-6 h-6",
1224
medium: "w-7 h-7",
@@ -17,10 +29,15 @@ export function IconButton({ icon, onClick, title, size = "medium", variant = "d
1729
transparent: "bg-transparent hover:bg-vscode-toolbar-hoverBackground",
1830
}
1931

32+
const handleClick = onClick || ((_event: React.MouseEvent) => {})
33+
2034
return (
2135
<button
2236
className={`${sizeClasses[size]} flex items-center justify-center border-none text-vscode-editor-foreground cursor-pointer rounded-[3px] ${variantClasses[variant]}`}
23-
onClick={onClick}
37+
onClick={handleClick}
38+
onMouseDown={onMouseDown}
39+
onMouseUp={onMouseUp}
40+
onMouseLeave={onMouseLeave}
2441
title={title}>
2542
<span className={`codicon codicon-${icon}`}></span>
2643
</button>

webview-ui/src/components/common/MermaidButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function MermaidButton({ containerRef, code, isLoading, svgToPng, childre
8484

8585
// Determine zoom direction and amount
8686
// Negative deltaY means scrolling up (zoom in), positive means scrolling down (zoom out)
87-
const delta = e.deltaY > 0 ? -0.25 : 0.25
87+
const delta = e.deltaY > 0 ? -0.2 : 0.2
8888
adjustZoom(delta)
8989
}, [])
9090

webview-ui/src/components/common/ZoomControls.tsx

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -65,41 +65,27 @@ export function ZoomControls({
6565
}
6666
}, [])
6767

68-
// If using continuous zoom, render buttons with mouse down/up handlers
69-
if (useContinuousZoom && adjustZoom) {
70-
return (
71-
<div className="flex items-center gap-2">
72-
<button
73-
className="w-7 h-7 flex items-center justify-center border-none text-vscode-editor-foreground cursor-pointer rounded-[3px] bg-transparent hover:bg-vscode-toolbar-hoverBackground"
74-
onMouseDown={() => startContinuousZoom(zoomOutStep)}
75-
onMouseUp={stopContinuousZoom}
76-
onMouseLeave={stopContinuousZoom}
77-
title={zoomOutTitle}>
78-
<span className="codicon codicon-zoom-out"></span>
79-
</button>
80-
<div className="text-sm text-vscode-editor-foreground min-w-[50px] text-center">
81-
{Math.round(zoomLevel * 100)}%
82-
</div>
83-
<button
84-
className="w-7 h-7 flex items-center justify-center border-none text-vscode-editor-foreground cursor-pointer rounded-[3px] bg-transparent hover:bg-vscode-toolbar-hoverBackground"
85-
onMouseDown={() => startContinuousZoom(zoomInStep)}
86-
onMouseUp={stopContinuousZoom}
87-
onMouseLeave={stopContinuousZoom}
88-
title={zoomInTitle}>
89-
<span className="codicon codicon-zoom-in"></span>
90-
</button>
91-
</div>
92-
)
93-
}
94-
95-
// Default rendering with simple click handlers
9668
return (
9769
<div className="flex items-center gap-2">
98-
<IconButton icon="zoom-out" onClick={onZoomOut || (() => adjustZoom?.(zoomOutStep))} title={zoomOutTitle} />
70+
<IconButton
71+
icon="zoom-out"
72+
title={zoomOutTitle}
73+
onClick={!useContinuousZoom ? onZoomOut || (() => adjustZoom?.(zoomOutStep)) : undefined}
74+
onMouseDown={useContinuousZoom && adjustZoom ? () => startContinuousZoom(zoomOutStep) : undefined}
75+
onMouseUp={useContinuousZoom && adjustZoom ? stopContinuousZoom : undefined}
76+
onMouseLeave={useContinuousZoom && adjustZoom ? stopContinuousZoom : undefined}
77+
/>
9978
<div className="text-sm text-vscode-editor-foreground min-w-[50px] text-center">
10079
{Math.round(zoomLevel * 100)}%
10180
</div>
102-
<IconButton icon="zoom-in" onClick={onZoomIn || (() => adjustZoom?.(zoomInStep))} title={zoomInTitle} />
81+
<IconButton
82+
icon="zoom-in"
83+
title={zoomInTitle}
84+
onClick={!useContinuousZoom ? onZoomIn || (() => adjustZoom?.(zoomInStep)) : undefined}
85+
onMouseDown={useContinuousZoom && adjustZoom ? () => startContinuousZoom(zoomInStep) : undefined}
86+
onMouseUp={useContinuousZoom && adjustZoom ? stopContinuousZoom : undefined}
87+
onMouseLeave={useContinuousZoom && adjustZoom ? stopContinuousZoom : undefined}
88+
/>
10389
</div>
10490
)
10591
}

0 commit comments

Comments
 (0)