Skip to content

Commit 02424d9

Browse files
benceruleanluDrJKL
authored andcommitted
Forward scroll unless focused
1 parent bbfada5 commit 02424d9

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/renderer/core/canvas/useCanvasInteractions.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,28 @@ export function useCanvasInteractions() {
2626
() => !(canvasStore.canvas?.read_only ?? false)
2727
)
2828

29+
/**
30+
* Returns true if the wheel event target is inside an element that should
31+
* capture wheel events AND that element (or a descendant) currently has focus.
32+
*
33+
* This allows two-finger panning to continue over inputs until the user has
34+
* actively focused the widget, at which point the widget can consume scroll.
35+
*/
36+
const wheelCapturedByFocusedElement = (event: WheelEvent): boolean => {
37+
const target = event.target as HTMLElement | null
38+
const captureElement = target?.closest('[data-capture-wheel="true"]')
39+
const active = document.activeElement as Element | null
40+
41+
return !!(captureElement && active && captureElement.contains(active))
42+
}
43+
2944
/**
3045
* Handles wheel events from UI components that should be forwarded to canvas
3146
* when appropriate (e.g., Ctrl+wheel for zoom in standard mode)
3247
*/
3348
const handleWheel = (event: WheelEvent) => {
34-
// Check if the wheel event is from an element that wants to capture wheel events
35-
const target = event.target as HTMLElement
36-
const captureElement = target?.closest('[data-capture-wheel="true"]')
37-
38-
if (captureElement) {
39-
// Element wants to capture wheel events, don't forward to canvas
40-
return
41-
}
49+
// If a wheel-capturing widget is focused, let it consume the wheel event
50+
if (wheelCapturedByFocusedElement(event)) return
4251

4352
// In standard mode, Ctrl+wheel should go to canvas for zoom
4453
if (isStandardNavMode.value && (event.ctrlKey || event.metaKey)) {
@@ -87,14 +96,9 @@ export function useCanvasInteractions() {
8796
const forwardEventToCanvas = (
8897
event: WheelEvent | PointerEvent | MouseEvent
8998
) => {
90-
// Check if the wheel event is from an element that wants to capture wheel events
91-
const target = event.target as HTMLElement
92-
const captureElement = target?.closest('[data-capture-wheel="true"]')
93-
94-
if (captureElement) {
95-
// Element wants to capture wheel events, don't forward to canvas
99+
// Honor wheel capture only when the element is focused
100+
if (event instanceof WheelEvent && wheelCapturedByFocusedElement(event))
96101
return
97-
}
98102

99103
const canvasEl = app.canvas?.canvas
100104
if (!canvasEl) return

0 commit comments

Comments
 (0)