Closed curran closed 4 weeks ago
Look through https://codemirror.net/docs/
Look in src/client/CodeEditor/index.tsx
lines 109-122.
// Every time the active file switches from one file to another,
// the editor corresponding to the old file is removed from the DOM,
// and the editor corresponding to the new file is added to the DOM.
useLayoutEffect(() => {
// Guard against cases where page is still loading.
if (!ref.current) return;
if (!content) return;
// Add the editor to the DOM.
ref.current.appendChild(editorCacheValue.editor.dom);
return () => {
// Remove the old editor from the DOM.
// This happens every time `activeFileId` changes.
ref.current.removeChild(editorCacheValue.editor.dom);
};
}, [shareDBDoc, editorCacheValue]);
This is the code that runs when you switch between files.
Maybe we store the scroll position when we call removeChild
, then recall it when we call appendChild
, based on fileId
?
This is a thing we could maybe use for this:
https://codemirror.net/docs/ref/#view.EditorViewConfig.scrollTo
As a VZCode user editing multiple files, I want to be able to
Current behavior: scroll is always reset to the top of the file, causing frustration when switching between files.