Commit 338c211
committed
fix(live-preview): suppress md viewer ↔ CM scroll feedback loops
Selecting/clicking/editing in the md viewer caused the iframe to scroll
itself to a stale line, and undo/redo plus backspace caused visible
scroll jumps. Root cause was missing suppression on both sides of the
sync bridge:
- The iframe side: viewer-initiated events that can cause CM to scroll
(selection sync, cursor-line sync, click-to-focus) didn't mark the
iframe as the scroll origin, so CM's resulting scroll-handler echo
came back through MDVIEWR_SCROLL_TO_LINE and re-scrolled the iframe.
Centralize the flag in sendToParent for all such events, and drop the
editMode-only requirement from the guard so design mode is covered too.
- The CM side: cm.replaceRange (in _applyDiffToEditor), cm.scrollTo (in
_scrollCMToLine), and cm.undo()/cm.redo() can each trigger an async
CM scroll that echoes back to the iframe. Wrap each in
_scrollSyncFromIframe = true with a 200ms clear so CM's scroll handler
ignores them.1 parent 3a46cea commit 338c211
2 files changed
Lines changed: 41 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
513 | 514 | | |
514 | 515 | | |
515 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
516 | 522 | | |
517 | 523 | | |
518 | 524 | | |
| |||
1057 | 1063 | | |
1058 | 1064 | | |
1059 | 1065 | | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
1063 | 1069 | | |
1064 | 1070 | | |
1065 | 1071 | | |
| |||
1401 | 1407 | | |
1402 | 1408 | | |
1403 | 1409 | | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
1404 | 1420 | | |
1405 | 1421 | | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
1406 | 1427 | | |
1407 | 1428 | | |
1408 | 1429 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
581 | 586 | | |
582 | 587 | | |
| 588 | + | |
583 | 589 | | |
584 | 590 | | |
585 | 591 | | |
| |||
648 | 654 | | |
649 | 655 | | |
650 | 656 | | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
651 | 661 | | |
| 662 | + | |
652 | 663 | | |
653 | 664 | | |
654 | 665 | | |
| |||
663 | 674 | | |
664 | 675 | | |
665 | 676 | | |
| 677 | + | |
666 | 678 | | |
| 679 | + | |
667 | 680 | | |
668 | 681 | | |
669 | 682 | | |
| |||
862 | 875 | | |
863 | 876 | | |
864 | 877 | | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
865 | 881 | | |
| 882 | + | |
866 | 883 | | |
867 | 884 | | |
868 | 885 | | |
| |||
0 commit comments