Skip to content

Commit b861204

Browse files
committed
fix(mdviewer): prevent CM scroll jump from cursor activity feedback loop
Set _scrollFromCM flag for all CM-initiated viewer scrolls (both cursor-based and scroll-sync), not just fromScroll. This prevents the viewer's scroll event from sending mdviewrScrollSync back to CM during the 200ms suppression window. Reverts focus-based scroll blocking in favor of proper feedback loop prevention.
1 parent 9679c58 commit b861204

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src-mdviewer/src/bridge.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ function handleScrollToLine(data) {
935935
const viewer = document.getElementById("viewer-content");
936936
if (!viewer) return;
937937

938+
938939
const elements = viewer.querySelectorAll("[data-source-line]");
939940
let bestEl = null;
940941
let bestLine = -1;
@@ -953,18 +954,19 @@ function handleScrollToLine(data) {
953954
const containerRect = container.getBoundingClientRect();
954955
const elRect = bestEl.getBoundingClientRect();
955956

957+
// Suppress viewer→CM scroll feedback for any CM-initiated scroll
958+
_scrollFromCM = true;
956959
if (fromScroll) {
957960
// Sync scroll: always align to top, even if visible
958-
_scrollFromCM = true;
959961
bestEl.scrollIntoView({ behavior: "instant", block: "start" });
960-
setTimeout(() => { _scrollFromCM = false; }, 200);
961962
} else {
962963
// Cursor-based scroll: only scroll if not visible, center it
963964
const isVisible = elRect.top >= containerRect.top && elRect.bottom <= containerRect.bottom;
964965
if (!isVisible) {
965966
bestEl.scrollIntoView({ behavior: "instant", block: "center" });
966967
}
967968
}
969+
setTimeout(() => { _scrollFromCM = false; }, 200);
968970

969971
// Persistent highlight on the element corresponding to the CM cursor.
970972
// Only show when CM has focus (not when viewer has focus).

0 commit comments

Comments
 (0)