fix(editor): scope Mermaid diagram scroll position per pane (#34983)

Key MermaidViewer's scroll cache with the pane-scoped editorViewStateKey,
matching IpynbViewer, so split panes showing the same .mmd file no longer
overwrite each other's saved diagram position.

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-28 17:26:47 -07:00
committed by GitHub
co-authored by OrcaWin
parent 2f3cdbab78
commit b2feed0e92
2 changed files with 7 additions and 6 deletions
@@ -274,7 +274,11 @@ export function EditorEditFileSurface({
monacoEditor={monacoEditor}
/>
) : isMermaid && mdViewMode === 'rich' ? (
<MermaidViewer key={activeFile.id} content={currentContent} filePath={activeFile.filePath} />
<MermaidViewer
key={activeFile.id}
content={currentContent}
scrollCacheKey={`${editorViewStateKey}:mermaid-diagram`}
/>
) : isCsv && mdViewMode === 'rich' ? (
<CsvViewer
key={activeFile.id}
@@ -5,20 +5,17 @@ import { useDocumentDarkTheme } from '@/hooks/use-document-dark-theme'
type MermaidViewerProps = {
content: string
filePath: string
scrollCacheKey: string
}
// Render full .mmd/.mermaid files directly as diagram source.
export default function MermaidViewer({
content,
filePath
scrollCacheKey
}: MermaidViewerProps): React.JSX.Element {
const rootRef = useRef<HTMLDivElement>(null)
const isDark = useDocumentDarkTheme()
// Source and diagram heights differ; keep their scroll positions separate.
const scrollCacheKey = `${filePath}:mermaid-diagram`
useLayoutEffect(() => {
const container = rootRef.current
if (!container) {