Commit ab30a36
authored
fix(editor): prevent scroll-to-top when clicking toolbar buttons (#2236)
* fix(editor): prevent scroll-to-top when clicking toolbar buttons (SD-1780)
Toolbar buttons had tabindex="0" but no mousedown prevention, so
clicking them caused the browser to transfer focus away from the
hidden ProseMirror editor. The subsequent refocus triggered
ProseMirror's selectionToDOM, and the browser asynchronously scrolled
to make the DOM selection visible inside the hidden editor at
position:fixed top:0. This only manifested when the window was the
scroll container (not a div with overflow:auto).
Two fixes applied:
1. Toolbar mousedown preventDefault for non-input elements. This is
the standard pattern used by ProseMirror's example editor, Tiptap,
and most WYSIWYG editors. It keeps the PM editor focused throughout
toolbar interactions.
2. requestAnimationFrame safety net in wrapHiddenEditorFocus. After
the synchronous scroll restoration, a RAF callback catches any
async browser scroll caused by layout reflow post-focus.
* fix(editor): cancel focus-scroll RAF on intentional scroll
Store the RAF handle from wrapHiddenEditorFocus on the instance and
cancel it when scrollToPosition is called. Prevents the safety net
from undoing intentional scrolls like search navigation.
* test(editor): exercise RAF scroll-restore callback in focus wrapping test
The previous test only verified that requestAnimationFrame was
scheduled but never invoked the callback. Now we capture the RAF
callback, simulate async scroll drift (scrollY changing between
focus call and RAF execution), and verify scrollTo is called to
restore the original position.1 parent e000efd commit ab30a36
3 files changed
Lines changed: 102 additions & 1 deletion
File tree
- packages/super-editor/src
- components/toolbar
- core/presentation-editor
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
80 | 95 | | |
81 | 96 | | |
82 | 97 | | |
83 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
84 | 106 | | |
85 | 107 | | |
86 | 108 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| 289 | + | |
289 | 290 | | |
290 | 291 | | |
291 | 292 | | |
| |||
775 | 776 | | |
776 | 777 | | |
777 | 778 | | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
778 | 794 | | |
779 | 795 | | |
780 | 796 | | |
| |||
2148 | 2164 | | |
2149 | 2165 | | |
2150 | 2166 | | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
2151 | 2175 | | |
2152 | 2176 | | |
2153 | 2177 | | |
| |||
2523 | 2547 | | |
2524 | 2548 | | |
2525 | 2549 | | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
2526 | 2559 | | |
2527 | 2560 | | |
2528 | 2561 | | |
| |||
Lines changed: 46 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
358 | 404 | | |
359 | 405 | | |
360 | 406 | | |
| |||
0 commit comments