Skip to content

Notes: Forward mouse wheel events from floating sidebar to editor canvas - #73655

Closed
t-hamano wants to merge 9 commits into
trunkfrom
notes/sidebar-scroll
Closed

t-hamano wants to merge 9 commits into
trunkfrom
notes/sidebar-scroll

Conversation

@t-hamano

@t-hamano t-hamano commented Nov 29, 2025 •

Copy link
Copy Markdown
Contributor

Trying one approach to solving #73653.

What?

This PR propagates mouse scroll events to the editor canvas, making it easier to bring overflowing floating note content into view.

Why?

Floating notes are auto-aligned to the block position, and even if they overflow, the note sidebar is not scrollable, so you have to move your mouse cursor to the editor canvas and scroll there, which is a bit tedious.

Testing Instructions

  • Insert many blocks and add notes to them.
  • Scroll your mouse over the floating notes sidebar.

Screencast

a3d14bd058fa3048c56c6845ab3e95ee.mp4

@t-hamano t-hamano added [Type] Enhancement A suggestion for improvement. [Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting labels Nov 29, 2025
@github-actions

github-actions Bot commented Nov 29, 2025 •

Copy link
Copy Markdown

Size Change: +242 B (0%)

Total Size: 8.44 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 465 kB +242 B (+0.05%)

compressed-size-action

@t-hamano
t-hamano marked this pull request as ready for review December 1, 2025 08:37
@t-hamano t-hamano changed the title [WIP] Notes: Forward mouse wheel events from floating sidebar to editor canvas Notes: Forward mouse wheel events from floating sidebar to editor canvas Dec 1, 2025
@github-actions

github-actions Bot commented Dec 1, 2025 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: draganescu <andraganescu@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: joedolson <joedolson@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

// Apply the scroll effect to the sidebar ref.
useEffect( () => {
if ( commentSidebarRef?.current ) {
return scrollToCanvasEffect( commentSidebarRef.current );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't how ref effects work; you should either attach events inside the effect or pass scrollToCanvasEffect as ref to the element.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made some changes based on your feedback in 71e0695. Is this approach correct?

@github-actions

github-actions Bot commented Dec 1, 2025 •

Copy link
Copy Markdown

Flaky tests detected in 4177a22.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27125351488
📝 Reported issues:

@t-hamano t-hamano self-assigned this Dec 22, 2025
@Mamaduka

Copy link
Copy Markdown
Member

Sorry, @t-hamano! Missed this when working on #77433. I think the new scroll sync resolved the problem.

@github-actions github-actions Bot added the [Package] Editor /packages/editor label Apr 24, 2026
…k selection

The floating comments sidebar forwards wheel events to the editor canvas,
but previously the canvas was looked up via the selected block. When no
block was selected, the lookup returned null and wheel forwarding stopped
working. Resolve the canvas from the first block in the editor so scroll
forwarding keeps working regardless of selection state.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@t-hamano

Copy link
Copy Markdown
Contributor Author

@Mamaduka Thanks for the reply!

Personally, I believe this PR is a good enhancement, despite the implementation of the new scroll sync logic.

The current floating note area does not accept mouse scrolling. Therefore, to view the notes below, we need to move the mouse pointer to the editor canvas and then scroll.

trunk

before.mp4

this PR

after.mp4

@Mamaduka

Copy link
Copy Markdown
Member

Thanks for the additional details, @t-hamano!

I think logic can be moved into the new useFloatingBoard hook; it already has similar logic, and wheel syncing can be part of it.

# Conflicts:
#	packages/editor/src/components/collab-sidebar/comments.js
@t-hamano

Copy link
Copy Markdown
Contributor Author

@Mamaduka Thanks for the review!

I think logic can be moved into the new useFloatingBoard hook; it already has similar logic, and wheel syncing can be part of it.

I think we could have achieved a similar outcome with significantly less code 👍

@Mamaduka

Copy link
Copy Markdown
Member

Thanks for the update, @t-hamano!

This generally works okay, but before we move forward, it would be nice to consider UX and whether it's worth hijacking native wheel behavior. Currently, there's no indicator for the user that this action will scroll the panel + content. cc @jameskoster

Some technical notes:

  • We need to account for internal scroll areas, for example, the reply textarea can have its own scrollable, and this should work as before.
  • TIL about event.deltaMode, which is different on Firefox + Wheel and produces janky scroll behavior, in my tests. Attaching info from AI below:
Info dump from AI

scrollBy(deltaX, deltaY) treats both args as CSS pixels. But WheelEvent.delta* values are only in pixels when event.deltaMode === DOM_DELTA_PIXEL (0). The other two modes mean the numbers are unit-less:

  • DOM_DELTA_LINE (1): deltaY is a line count, typically ±3 per notch.
  • DOM_DELTA_PAGE (2): deltaY is a page count, typically ±1.

Real-world example: Firefox on Windows/Linux with a classic notched mouse wheel emits deltaY: 3, deltaMode: 1 per notch. We pass 3 to scrollBy — the canvas moves 3 pixels. The browser's native wheel scroll on a real scroll container would have moved ~48–100px (line-height × 3, or whatever the OS "lines per scroll" setting is). So a Firefox-on-desktop user with a wheel mouse spins the wheel and the canvas crawls. Trackpad users (always pixel mode) don't see it, which is why it's easy to miss in dev.

Chrome/Safari normalize to pixel mode for most input, so they're fine — but Firefox is the canary here, and it's a supported browser.

@jameskoster

Copy link
Copy Markdown
Contributor

I agree that this is a nice enhancement. It certainly aligns with my UX expectation.

This generally works okay, but before we move forward, it would be nice to consider UX and whether it's worth hijacking native wheel behavior. Currently, there's no indicator for the user that this action will scroll the panel + content.

This sounds more like an accessibility question. cc @WordPress/accessibility.

@joedolson

Copy link
Copy Markdown
Contributor

From an accessibility perspective, I think that this is OK, for a couple of reasons:

  1. There's minimal visual affordance for any scrollable region that the region will scroll, so it's a relatively minor issue.
  2. As long any inner scrolling container behaves normally, it shouldn't have a lot of downside.

There may be side effects from this that we haven't anticipated; but personally, as soon as there's any part of the notes panel that's outside of the viewport, I expect to be able to scroll the notes panel using the mouse wheel, regardless of the lack of a scroll bar.

I wasn't able to view the videos; they don't seem to be present at the moment, and haven't run the PR. Is scrolling forwarded directly, so it's equal, or does it forward based on whether the current note is attached to a new block?

@Mamaduka

Mamaduka commented May 1, 2026

Copy link
Copy Markdown
Member

I wasn't able to view the videos; they don't seem to be present at the moment, and haven't run the PR. Is scrolling forwarded directly, so it's equal, or does it forward based on whether the current note is attached to a new block?

This change applies only to floating notes (All Notes sidebars have native scrolling), where each note is attached to a block. So I would say it's equal scroll - you scroll floating notes, and it also scrolls the canvas to show related blocks.

t-hamano and others added 2 commits May 4, 2026 17:44
…pixels

Lets a scrollable element inside the floating sidebar (e.g. a tall thread)
consume the wheel until it hits its edge, then resumes canvas scroll.
Also normalizes `WheelEvent.deltaY` by `deltaMode` so Firefox's
line/page-mode events scroll the canvas at native speeds instead of
crawling a few pixels per notch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@t-hamano

t-hamano commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

I made two changes:

  • Prioritize scrolling the element if it is vertically scrollable. Only scroll the canvas if the scroll reaches the edge.
  • Calculate the scroll pixel value based on the deltaMode value. This should allow for natural scrolling even in Firefox.

This is a video on Windows OS using Firefox. It seems to be working well.

Recording.2026-05-04.184042.mp4

@draganescu

draganescu commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Seems #77433 closed #73653 - do we still need this PR @t-hamano ?

Later edit - it seems we do :D because this is clearly an enhancement.

I think this is connected to my input and the PR about the background color in #74112 (comment)

As it is today it's extremely jarring that the canvas which is not separated in any way from the floating notes does not scroll if I hover over the floating note area.

@t-hamano

Copy link
Copy Markdown
Contributor Author

I believe this PR is still necessary to resolve some of the issues in #80449. See #80449 (comment)

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

📦 Bundle size

Size Change: +287 B (0%)

Total Size: 8.21 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 611 kB +287 B (+0.05%)

e365c16 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric e083f2c trunk % Change
timeToFirstByte 57 ms +4.47% -3.42% 61 ms +9.75% -3.52% -6.56%
largestContentfulPaint 92 ms +4.35% -4.35% 104 ms +3.85% -7.69% -11.54%
lcpMinusTtfb 34.8 ms +6.47% -4.74% 37.55 ms +21.84% -5.59% -7.32%
wpBeforeTemplate 27.94 ms +7.84% -1.04% 29.76 ms +19.05% -1.71% -6.12%
wpTemplate 24.06 ms +4.24% -2.87% 26.7 ms +2.28% -5.24% -9.89%
wpTotal 53.47 ms +4.54% -3.57% 57.24 ms +9.47% -3.67% -6.59%
wpMemoryUsage 7.56 MB +0% -0% 7.53 MB +0% -0% 0.46%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric e083f2c trunk % Change
timeToFirstByte 46.5 ms +6.67% -0.86% 49.85 ms +6.42% -1.5% -6.72%
largestContentfulPaint 102 ms +3.92% -1.96% 108 ms +1.85% -3.7% -5.56%
lcpMinusTtfb 54.2 ms +4.8% -0.74% 55.75 ms +4.22% -1.52% -2.78%
wpBeforeTemplate 25.96 ms +6.16% -1.39% 27.35 ms +4.72% -1.06% -5.08%
wpTemplate 17.68 ms +2.26% -0.68% 19.22 ms +6.92% -3.17% -8.01%
wpTotal 43.5 ms +7.17% -0.55% 46.62 ms +7.1% -1.52% -6.69%
wpMemoryUsage 6.18 MB +0% -0% 6.15 MB +0% -0% 0.58%
wpDbQueries 14 +0% -0% 14 +0% -0% 0%

media-processing

Metric e083f2c trunk % Change
mediaProcessingJpeg 399.25 ms +0.63% -1.24% 398.55 ms +2.22% -0.78% 0.18%
mediaProcessingAvif 6082.68 ms +0.35% -0.37% 6082.4 ms +0.2% -0.21% 0%
mediaProcessingJpegToAvif 4182.95 ms +0.11% -0.2% 4228.08 ms +0.21% -0.25% -1.07%

media-upload

Metric e083f2c trunk % Change
jpegUploadProcessing 1717.47 ms +13.9% -16.93% 1424.72 ms +0.33% -0.6% 20.55%
pngUploadProcessing 214.8 ms +2.42% -1.81% 229.6 ms +2.91% -6.96% -6.45%
largeJpegUploadProcessing 1422.39 ms +0.4% -0.6% 1421.41 ms +0.36% -0.67% 0.07%
multipleImageUploadProcessing 1595.6 ms +9.2% -1.08% 1627.91 ms +30.35% -2.09% -1.98%

post-editor

Metric e083f2c trunk % Change
serverResponse 263.74 ms +6.17% -6.4% 278.87 ms +0.33% -7.03% -5.43%
firstPaint 158.95 ms +14.18% -15.02% 154.78 ms +16.6% -11.13% 2.69%
domContentLoaded 738.24 ms +2.21% -7.57% 695.27 ms +0.98% -4.19% 6.18%
loaded 739.22 ms +2.25% -7.55% 696.36 ms +0.98% -4.18% 6.15%
firstContentfulPaint 320.25 ms +6.32% -7.2% 296.71 ms +3.55% -4.37% 7.93%
firstBlock 2093.18 ms +4.59% -3.26% 2020.93 ms +1.11% -1.5% 3.58%
type 18.01 ms +5.5% -5.33% 17.38 ms +1.32% -3.16% 3.62%
typeWithoutInspector 16.31 ms +4.84% -1.16% 15.9 ms +3.14% -4.65% 2.58%
typeWithTopToolbar 21.08 ms +5.5% -7.59% 20.7 ms +12.03% -5.56% 1.84%
typeContainer 7.17 ms +1.95% -7.95% 6.95 ms +8.63% -7.34% 3.17%
focus 52.32 ms +2.52% -15.88% 46.49 ms +4.22% -6.02% 12.54%
firstFocus 129.06 ms +0% -0% 119.85 ms +0% -0% 7.68%
selectAll 303.73 ms +12.24% -4.94% 316.75 ms +0.5% -0.52% -4.11%
listViewOpen 42.04 ms +5.4% -11.44% 44.47 ms +5.13% -15.13% -5.46%
inserterOpen 17.64 ms +10.54% -7.43% 17.77 ms +5.74% -14.24% -0.73%
inserterHover 2.16 ms +17.13% -7.87% 2.33 ms +5.58% -11.16% -7.3%
inserterSearch 6.19 ms +5.17% -2.58% 6.22 ms +9.65% -1.45% -0.48%
loadPatterns 428.01 ms +4.29% -5.22% 442.55 ms +8.12% -3.27% -3.29%
wpTotal 256.55 ms +6.45% -6.45% 271.74 ms +0.32% -7.08% -5.59%
wpMemoryUsage 13.09 MB +0% -0% 13.05 MB +0% -0% 0.28%
wpDbQueries 54 +0% -0% 54 +0% -0% 0%

site-editor

Metric e083f2c trunk % Change
serverResponse 393.14 ms +5.44% -6.96% 393.8 ms +3.28% -5.01% -0.17%
firstPaint 235.72 ms +88.86% -9.66% 221.58 ms +100.26% -8.69% 6.38%
domContentLoaded 1105.03 ms +0.69% -1.5% 1090.14 ms +1.73% -0.68% 1.37%
loaded 1106.16 ms +0.71% -1.5% 1091.23 ms +1.74% -0.68% 1.37%
firstContentfulPaint 448.35 ms +1.51% -1.54% 442.68 ms +0.53% -1.57% 1.28%
firstBlock 3929.43 ms +3.62% -0.79% 3896.69 ms +4.47% -0.27% 0.84%
type 20.7 ms +7.34% -5.8% 19.89 ms +5.68% -2.66% 4.07%
navigate 117.16 ms +5.33% -13.7% 116.59 ms +3.08% -4.03% 0.49%
loadPatterns 1297.14 ms +15.46% -10.62% 1368.66 ms +6.27% -17.5% -5.23%
loadPages 1090.55 ms +1.46% -1.68% 1074.73 ms +9.28% -1.26% 1.47%
wpTotal 382.56 ms +5.58% -7.28% 382.8 ms +3.38% -5.01% -0.06%
wpMemoryUsage 12.05 MB +0% -0% 12.02 MB +0% -0% 0.31%
wpDbQueries 43 +2.33% -0% 43 +2.33% -0% 0%

e365c16 Run

@draganescu draganescu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if its a me problem but on Chrome 152.0.7977.84 (Official Build) (arm64) on macos I get this weird sluggins scroll if I scroll while hovering the notes float area

scroll-slow.mp4

@draganescu draganescu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a theme issue - themes that fiddle with scroll behavior should not interfere with this work.

canvas,
panel.ownerDocument.defaultView
);
canvas.scrollBy( 0, deltaYInPixels );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
canvas.scrollBy( 0, deltaYInPixels );
canvas.scrollBy( { top: deltaYInPixels, behavior: 'instant' } );

This makes it so that themes that set html { scroll-behavior: smooth } do not interfere with this behavior.

@draganescu

Copy link
Copy Markdown
Contributor

Also #79864 kinda resolves this - except for scrolling over a card.

Mamaduka added a commit that referenced this pull request Oct 2, 2026
The floating panel becomes a real scroller mirrored with the canvas, and
the canvas root gets a min-height so it can scroll to the lowest thread.
Wheel, keys, Tab and scrollIntoView() work natively.

Fixes #80449. Supersedes #73655.

Co-authored-by: Aki Hamano <t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@t-hamano

t-hamano commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Cllosing this in favor of #83852

@t-hamano t-hamano closed this Oct 5, 2026
@Mamaduka
Mamaduka deleted the notes/sidebar-scroll branch October 5, 2026 05:52
Mamaduka added a commit that referenced this pull request Oct 5, 2026
The floating panel becomes a real scroller mirrored with the canvas, and
the canvas root gets a min-height so it can scroll to the lowest thread.
Wheel, keys, Tab and scrollIntoView() work natively.

Fixes #80449. Supersedes #73655.

Co-authored-by: Aki Hamano <t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting [Package] Editor /packages/editor [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants