Available controls
The preview panel header provides four main controls:Color picker
Change thecurrentColor value to see how your SVG adapts:
- Icon: Paint palette with color swatch
- Function: Opens a color picker to set the
currentColorreplacement value - Location: Rightmost button in the header
- Default: Uses
betterSvg.defaultColorsetting (default:#ffffff)
The color picker immediately updates the preview as you select different colors. Changes are not persisted to the file.
Dark background toggle
Switch between transparent and dark backgrounds:- Icon: Half-moon circle (toggles between outline and filled)
- Function: Toggles between checkerboard pattern and dark solid background
- Shortcut: Click the icon or use the toggle button
- Default: Starts with checkerboard pattern
- Transparent background with light checkerboard pattern
- Helps identify transparent areas in your SVG
- Uses
--vscode-editorWidget-backgroundcolor
- Solid dark background (
rgba(0, 0, 0, 0.7)) - Better for viewing light-colored SVGs
- No pattern, pure background color
Center button
Reset zoom and pan to default:- Icon: Target/crosshair circle
- Function: Resets
scaleto 1.0 andtranslateX/translateYto 0 - Trigger: Click the center icon
- Effect: Immediately resets all viewport transformations
Optimize button
Trigger SVGO optimization:- Icon: Lightning bolt ⚡
- Function: Optimizes the current SVG using SVGO
- Trigger: Click the lightning icon
- Effect: Applies optimization and shows size reduction notification
The optimize button is documented in detail on the optimization page.
Zoom controls
Click to zoom in
Click anywhere on the preview to zoom in:- Trigger: Left-click on the SVG or preview area
- Increment: +0.5 (50% increase)
- Range: 10% to 1000% (0.1 to 10.0 scale)
- Cursor: Shows
zoom-incursor
Alt + click to zoom out
Hold Alt and click to zoom out:- Trigger: Alt + left-click on the preview
- Decrement: -0.2 (20% decrease)
- Range: 10% to 1000%
- Cursor: Shows
zoom-outcursor when Alt is held
Scroll wheel zoom
Use the scroll wheel while holding Alt:- Trigger: Alt + scroll wheel
- Increment: ±0.1 per scroll tick
- Direction: Scroll down to zoom out, scroll up to zoom in
- Range: 10% to 1000%
- Behavior: Prevents page scroll while Alt is held
Pan controls
Pan (move) the SVG when zoomed in:Drag to pan
- Trigger: Click and drag on the preview area when
scale > 1 - Cursor: Changes to
grabbingwhile panning - Constraint: Only works when zoomed in (scale > 100%)
- Range: Unlimited - you can pan in any direction
Pan behavior
- Mouse down: Starts panning, stores initial cursor position
- Mouse move: Updates translation based on cursor delta
- Mouse up: Stops panning, releases grab cursor
- Click detection: Sets
wasPanningflag to prevent zoom on drag
Zoom level indicator
The header displays the current zoom level:- Format: Percentage rounded to nearest integer
- Location: Header title, next to “SVG Preview”
- Update: Real-time as you zoom
- Calculation:
Math.round(scale * 100) + '%'
File size indicator
The header also shows the current file size:- Format: Kilobytes with 1 decimal place
- Location: After zoom level in header
- Update: When SVG content changes
- Calculation:
(byteSize / 1024).toFixed(1) + ' KB'
File size is calculated using
getHTML().length, which measures the rendered SVG HTML size.Transform implementation
Viewport transformations use CSS transforms:- Origin:
center center- scales from the center point - Transition:
0.1s ease-outfor smooth updates - Apply to:
.preview-svg-wrapperelement - State: Maintained across preview updates, reset on file switch
Keyboard interactions
The extension tracks keyboard state for zoom controls:Alt key tracking
Cursor states
The preview area shows different cursors based on interaction state:zoom-in- Default cursor, click to zoom inzoom-out- Alt is held, click to zoom outgrabbing- Panning in progress- Default - No zoom or pan available (not interacting with SVG)
Preview update behavior
When the SVG content updates:Maintained state
- Zoom level (scale)
- Pan position (translateX, translateY)
- Background mode (checkerboard vs. dark)
- Current color setting
Reset state
- Zoom and pan reset when switching to a different SVG file
- File size updates to reflect new content
- SVG width is re-calculated if needed
Technical details
Viewport controls are implemented inmain.js:37-240:
State variables
Update function
Reset function
Best practices
- Use click zoom for quick magnification changes
- Use scroll zoom for fine-grained control (Alt + scroll)
- Pan to inspect details after zooming in on large SVGs
- Center frequently to reset view when disoriented
- Toggle dark mode to test SVG on different backgrounds
- Check the zoom indicator to know your current scale
Accessibility
Viewport controls support both mouse and keyboard:- Click-based zoom for mouse users
- Scroll wheel zoom for precision control
- Keyboard modifiers (Alt) for mode switching
- Visual cursor feedback for current mode
- Click targets are at least 18×18px for easy interaction