Skip to content

Commit 535b37d

Browse files
author
Eric Wheeler
committed
fix: pass through wheel events when content is not scrollable
Only apply special wheel event handling when the pre element actually has a scrollbar. Otherwise, let the browser handle default scrolling behavior. This ensures proper event bubbling when content is too small to need scrolling. Signed-off-by: Eric Wheeler <[email protected]>
1 parent e36cd6a commit 535b37d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,15 @@ const CodeBlock = memo(
507507
}
508508
if (!preRef.current) return
509509

510+
// Only handle wheel events if the inner container has a scrollbar,
511+
// otherwise let the browser handle the default scrolling
512+
const hasScrollbar = preRef.current.scrollHeight > preRef.current.clientHeight
513+
514+
// Pass through events if we don't need special handling
515+
if (!hasScrollbar) {
516+
return
517+
}
518+
510519
const scrollContainer = getScrollContainer()
511520
if (!scrollContainer) return
512521

@@ -515,11 +524,6 @@ const CodeBlock = memo(
515524
const isAtVeryBottom =
516525
Math.abs(preRef.current.scrollHeight - preRef.current.scrollTop - preRef.current.clientHeight) < 1
517526

518-
// No need to set userHasScrolled here anymore, the scroll listener handles it
519-
// if (e.deltaY < 0 && !isAtVeryTop) {
520-
// setUserHasScrolled(true)
521-
// }
522-
523527
// Handle scrolling at container boundaries
524528
if ((e.deltaY < 0 && isAtVeryTop) || (e.deltaY > 0 && isAtVeryBottom)) {
525529
// Prevent default to stop inner container from handling
@@ -537,15 +541,11 @@ const CodeBlock = memo(
537541

538542
// Add wheel event listener to inner container
539543
const preElement = preRef.current
540-
if (preElement) {
541-
preElement.addEventListener("wheel", handleWheel, { passive: false })
542-
}
544+
preElement.addEventListener("wheel", handleWheel, { passive: false })
543545

544546
// Clean up
545547
return () => {
546-
if (preElement) {
547-
preElement.removeEventListener("wheel", handleWheel)
548-
}
548+
preElement.removeEventListener("wheel", handleWheel)
549549

550550
// Cancel any ongoing animation
551551
if (animationFrameId) {

0 commit comments

Comments
 (0)