Skip to content

Commit 27dc990

Browse files
committed
fix(mdviewer): clear sync highlights when cursor sync is toggled off
When the user disables cursor sync via the toolbar button, any existing highlights on both sides should be cleared: - Viewer: clear .cursor-sync-highlight element (paragraph class, br-line span, or code-line overlay) and reset _lastHighlight tracking - CM: remove the cm-cursor-sync-highlight line class
1 parent 11f2a8c commit 27dc990

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src-mdviewer/src/bridge.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,15 @@ export function initBridge() {
537537

538538
// Cursor sync toggle
539539
on("toggle:cursorSync", ({ enabled }) => {
540+
// Clear any existing highlights when cursor sync is disabled
541+
if (!enabled) {
542+
const viewer = document.getElementById("viewer-content");
543+
if (viewer) {
544+
_removeCursorHighlight(viewer);
545+
}
546+
_lastHighlightSourceLine = null;
547+
_lastHighlightTargetLine = null;
548+
}
540549
sendToParent("mdviewrCursorSyncToggle", { enabled });
541550
});
542551

src/extensionsIntegrated/Phoenix-live-preview/MarkdownSync.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ define(function (require, exports, module) {
131131
break;
132132
case "mdviewrCursorSyncToggle":
133133
_cursorSyncEnabled = !!data.enabled;
134+
// Clear CM line highlight when cursor sync is disabled
135+
if (!_cursorSyncEnabled) {
136+
const cm = _getCM();
137+
if (cm && _highlightLineHandle) {
138+
cm.removeLineClass(_highlightLineHandle, "background", "cm-cursor-sync-highlight");
139+
_highlightLineHandle = null;
140+
}
141+
}
134142
break;
135143
case "mdviewrThemeToggle":
136144
sendThemeOverride(data.theme);

0 commit comments

Comments
 (0)