@@ -15,6 +15,7 @@ let _lastReceivedSyncId = -1;
1515let _suppressContentChange = false ;
1616let _scrollFromCM = false ;
1717let _scrollFromViewer = false ;
18+ let _suppressScrollToLine = false ;
1819let _baseURL = "" ;
1920let _cursorPosBeforeEdit = null ; // cursor position before current edit batch
2021let _cursorPosDirty = false ; // true after content changes, reset when emitted
@@ -657,6 +658,11 @@ function handleSwitchFile(data) {
657658
658659 _suppressContentChange = true ;
659660
661+ // Suppress scroll-to-line from CM during file switch — the doc cache
662+ // restores the correct scroll position; CM cursor activity would override it.
663+ _suppressScrollToLine = true ;
664+ setTimeout ( ( ) => { _suppressScrollToLine = false ; } , 500 ) ;
665+
660666 // Edit mode is global for the md editor frame — preserve it across file switches
661667 const wasEditMode = getState ( ) . editMode ;
662668
@@ -975,6 +981,9 @@ function handleScrollToLine(data) {
975981 const { line, fromScroll, tableCol } = data ;
976982 if ( line == null ) return ;
977983
984+ // Suppress during file switch — doc cache restores the correct scroll
985+ if ( _suppressScrollToLine ) return ;
986+
978987 // In edit mode, ignore scroll-based sync that originated from the viewer
979988 // itself (feedback loop: viewer click → CM scroll → scroll sync back).
980989 if ( fromScroll && getState ( ) . editMode && _scrollFromViewer ) return ;
0 commit comments