|
@@ -1,6 +1,6 @@
|
|
|
/**
|
|
/**
|
|
|
- * The file tree's view state: which directories are expanded, and what each
|
|
|
|
|
- * loaded level contains.
|
|
|
|
|
|
|
+ * The file tree's view state: which directories are expanded, what each
|
|
|
|
|
+ * loaded level contains, and where the body is scrolled to.
|
|
|
*
|
|
*
|
|
|
* The tree is not one resource. A directory listing per level, expanded lazily,
|
|
* The tree is not one resource. A directory listing per level, expanded lazily,
|
|
|
* is state the type owns — so it lives in a Slot-standard exclusive store
|
|
* is state the type owns — so it lives in a Slot-standard exclusive store
|
|
@@ -47,6 +47,8 @@ export interface FilesTabState {
|
|
|
levels: Record<string, LevelState>
|
|
levels: Record<string, LevelState>
|
|
|
/** Expanded absolute directory paths, root included. */
|
|
/** Expanded absolute directory paths, root included. */
|
|
|
expanded: string[]
|
|
expanded: string[]
|
|
|
|
|
+ /** The body's scroll offset in px, so a remounted tree comes back where the reader was. */
|
|
|
|
|
+ scrollTop: number
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** Every tab's tree, keyed by tab id. */
|
|
/** Every tab's tree, keyed by tab id. */
|
|
@@ -74,6 +76,7 @@ type FilesActions = {
|
|
|
loaded: (draft: FilesState, tabId: TabId, path: string, level: DirLevel) => void
|
|
loaded: (draft: FilesState, tabId: TabId, path: string, level: DirLevel) => void
|
|
|
failed: (draft: FilesState, tabId: TabId, path: string, failure: RemoteFailure) => void
|
|
failed: (draft: FilesState, tabId: TabId, path: string, failure: RemoteFailure) => void
|
|
|
toggled: (draft: FilesState, tabId: TabId, path: string) => void
|
|
toggled: (draft: FilesState, tabId: TabId, path: string) => void
|
|
|
|
|
+ scrolled: (draft: FilesState, tabId: TabId, scrollTop: number) => void
|
|
|
reset: (draft: FilesState, tabId: TabId) => void
|
|
reset: (draft: FilesState, tabId: TabId) => void
|
|
|
forget: (draft: FilesState, tabId: TabId) => void
|
|
forget: (draft: FilesState, tabId: TabId) => void
|
|
|
}
|
|
}
|
|
@@ -96,7 +99,7 @@ export function createFilesStore(): EngineStoreHandle<FilesState, FilesActions>
|
|
|
* @param root - absolute path of the workspace root.
|
|
* @param root - absolute path of the workspace root.
|
|
|
*/
|
|
*/
|
|
|
start: (d, tabId: TabId, root: string) => {
|
|
start: (d, tabId: TabId, root: string) => {
|
|
|
- d.byTab[tabId] = { root, levels: {}, expanded: [root] }
|
|
|
|
|
|
|
+ d.byTab[tabId] = { root, levels: {}, expanded: [root], scrollTop: 0 }
|
|
|
},
|
|
},
|
|
|
/**
|
|
/**
|
|
|
* Mark one directory as being listed.
|
|
* Mark one directory as being listed.
|
|
@@ -141,6 +144,15 @@ export function createFilesStore(): EngineStoreHandle<FilesState, FilesActions>
|
|
|
if (at >= 0) state.expanded.splice(at, 1)
|
|
if (at >= 0) state.expanded.splice(at, 1)
|
|
|
else state.expanded.push(path)
|
|
else state.expanded.push(path)
|
|
|
},
|
|
},
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Record where one tab's body is scrolled to.
|
|
|
|
|
+ * @param d - draft state.
|
|
|
|
|
+ * @param tabId - the tab being drawn.
|
|
|
|
|
+ * @param scrollTop - the body's scroll offset, in px.
|
|
|
|
|
+ */
|
|
|
|
|
+ scrolled: (d, tabId: TabId, scrollTop: number) => {
|
|
|
|
|
+ bucket(d, tabId).scrollTop = scrollTop
|
|
|
|
|
+ },
|
|
|
/**
|
|
/**
|
|
|
* Drop every loaded level, keeping what is expanded.
|
|
* Drop every loaded level, keeping what is expanded.
|
|
|
*
|
|
*
|