diff --git a/src/editor/core/controller.ts b/src/editor/core/controller.ts index 007358a495..818bb73cd6 100644 --- a/src/editor/core/controller.ts +++ b/src/editor/core/controller.ts @@ -1242,6 +1242,13 @@ export class EditorController implements SlotHost { return { path: slot.model.path, ...loc, ...(paneId ? { paneId } : {}) }; } + /** Records a click position in `slot` without moving its caret or focus (Markdown preview cross-file links). */ + recordClickedLine(slot: EditorSlot, line: number) { + if (this.navSuppress > 0 || slot.disposed) return; + const paneId = this.locateTab(slot.tabId)?.paneId; + this.nav.update({ path: slot.model.path, line, col: 0, ...(paneId ? { paneId } : {}) }, true); + } + /** `navigation`: the caret got here by a navigation (see NavigationHistory.update). */ private recordNav(slot: EditorSlot, navigation = false, preferCaret = false) { if (this.navSuppress > 0 || slot.disposed) return; diff --git a/src/features/viewers/markdown/MarkdownEditor.tsx b/src/features/viewers/markdown/MarkdownEditor.tsx index 93b0893ad3..5ab5869911 100644 --- a/src/features/viewers/markdown/MarkdownEditor.tsx +++ b/src/features/viewers/markdown/MarkdownEditor.tsx @@ -1545,7 +1545,10 @@ function MarkdownPreview({ else if (target.path === filePath && target.anchor) scrollTo(target.anchor); else void (async () => { - if (originLine !== null) recordPreviewLine(originLine, "select.pointer", false); + if (originLine !== null) { + if (sync && slot) editorController().recordClickedLine(slot, originLine); + else recordPreviewLine(originLine, "select.pointer", false); + } const docsTarget = isMdxPath(filePath) && rawHref.trim().startsWith("/") ? await resolveDocsRootDocLink(filePath, rawHref, allowedRoots)