vizhub-core / vzcode

Mob Programming Code Editor
MIT License
55 stars 13 forks source link

Preserve Scroll Across Files #679

Closed curran closed 4 weeks ago

curran commented 1 month ago

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.

curran commented 4 weeks ago

Look through https://codemirror.net/docs/

curran commented 4 weeks ago

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.

curran commented 4 weeks ago

Maybe we store the scroll position when we call removeChild, then recall it when we call appendChild, based on fileId?

curran commented 4 weeks ago

This is a thing we could maybe use for this:

https://codemirror.net/docs/ref/#view.EditorViewConfig.scrollTo