@@ -4,7 +4,7 @@ local BOX_BORDER = 4
44local BOX_PADDING = 5
55
66function Editor :max_preview_size ()
7- local preview_size = Preferences .getPreviewSize and Preferences .getPreviewSize () or 128
7+ local preview_size = self . zoom_size or ( Preferences .getPreviewSize and Preferences .getPreviewSize () ) or 128
88 return math.max (1 , preview_size )
99end
1010
@@ -15,10 +15,10 @@ function Editor:preview_dimensions()
1515
1616 local max_preview_size = self :max_preview_size ()
1717 local longest = math.max (self .dmi .width , self .dmi .height )
18- if longest <= max_preview_size then
18+ -- Only scale up beyond native size if the user explicitly zoomed
19+ if not self .zoom_size and longest <= max_preview_size then
1920 return self .dmi .width , self .dmi .height
2021 end
21-
2222 local scale = max_preview_size / longest
2323 return math.max (1 , math.floor (self .dmi .width * scale + 0.5 )), math.max (1 , math.floor (self .dmi .height * scale + 0.5 ))
2424end
364364--- @param ev MouseEvent The mouse event object.
365365function Editor :onmousedown (ev )
366366 if self .closed then return end
367- if ev .button == MouseButton .LEFT then
367+ if ev .button == MouseButton .MIDDLE then
368+ -- Middle click: reset zoom to 1x (native size)
369+ if self .zoom_size then
370+ self .zoom_size = nil
371+ self .scroll = 0
372+ self :repaint_states ()
373+ end
374+ return
375+ elseif ev .button == MouseButton .LEFT then
368376 -- Don't set this until after selection behaivor is handled
369377 self .focused_widget = nil
370378
@@ -631,19 +639,23 @@ end
631639function Editor :onwheel (ev )
632640 if self .closed or not self .dmi then return end
633641
634- -- Ctrl+wheel: zoom preview size
642+ -- Ctrl+wheel: zoom preview size (per-editor)
635643 if ev .ctrlKey then
636- local current = Preferences .getPreviewSize ()
637- local step = ev .deltaY > 0 and - 16 or 16
638- local newSize = math.max (16 , math.min (512 , current + step ))
639- -- Check if the visual preview actually changes at this size
640- local longest = math.max (self .dmi .width , self .dmi .height )
641- if step > 0 and current >= longest then
642- return -- Already showing at native size, no point zooming further
644+ -- On first zoom, seed from current visual size
645+ if not self .zoom_size then
646+ local pw , ph = self :preview_dimensions ()
647+ self .zoom_size = math.max (pw , ph )
643648 end
644- newSize = math.min (newSize , math.max (longest , 16 ))
649+ local current = self .zoom_size
650+ local step
651+ if current < 64 then step = 8
652+ elseif current < 128 then step = 16
653+ elseif current < 256 then step = 32
654+ else step = 64 end
655+ local newSize = current + (ev .deltaY > 0 and - step or step )
656+ newSize = math.max (8 , math.min (512 , newSize ))
645657 if newSize ~= current then
646- Preferences . plugin . preferences . preview_size = newSize
658+ self . zoom_size = newSize
647659 self .scroll = 0
648660 self :repaint_states ()
649661 end
0 commit comments