|
5 | 5 | createSignal, |
6 | 6 | For, |
7 | 7 | Match, |
| 8 | + on, |
8 | 9 | onCleanup, |
9 | 10 | onMount, |
10 | 11 | ParentProps, |
@@ -275,12 +276,21 @@ export default function Layout(props: ParentProps) { |
275 | 276 | return bUpdated - aUpdated |
276 | 277 | } |
277 | 278 |
|
278 | | - function scrollToSession(sessionId: string) { |
| 279 | + const [scrollSessionKey, setScrollSessionKey] = createSignal<string | undefined>(undefined) |
| 280 | + |
| 281 | + function scrollToSession(sessionId: string, sessionKey: string) { |
279 | 282 | if (!scrollContainerRef) return |
| 283 | + if (scrollSessionKey() === sessionKey) return |
280 | 284 | const element = scrollContainerRef.querySelector(`[data-session-id="${sessionId}"]`) |
281 | | - if (element) { |
282 | | - element.scrollIntoView({ block: "nearest", behavior: "smooth" }) |
| 285 | + if (!element) return |
| 286 | + const containerRect = scrollContainerRef.getBoundingClientRect() |
| 287 | + const elementRect = element.getBoundingClientRect() |
| 288 | + if (elementRect.top >= containerRect.top && elementRect.bottom <= containerRect.bottom) { |
| 289 | + setScrollSessionKey(sessionKey) |
| 290 | + return |
283 | 291 | } |
| 292 | + setScrollSessionKey(sessionKey) |
| 293 | + element.scrollIntoView({ block: "nearest", behavior: "smooth" }) |
284 | 294 | } |
285 | 295 |
|
286 | 296 | const currentProject = createMemo(() => { |
@@ -325,9 +335,12 @@ export default function Layout(props: ParentProps) { |
325 | 335 | createEffect(() => { |
326 | 336 | if (!pageReady()) return |
327 | 337 | if (!layoutReady()) return |
| 338 | + const projects = layout.projects.list() |
328 | 339 | for (const [directory, expanded] of Object.entries(store.workspaceExpanded)) { |
329 | | - if (layout.sidebar.workspaces(directory)()) continue |
330 | 340 | if (!expanded) continue |
| 341 | + const project = projects.find((item) => item.worktree === directory || item.sandboxes?.includes(directory)) |
| 342 | + if (!project) continue |
| 343 | + if (layout.sidebar.workspaces(project.worktree)()) continue |
331 | 344 | setStore("workspaceExpanded", directory, false) |
332 | 345 | } |
333 | 346 | }) |
@@ -533,7 +546,7 @@ export default function Layout(props: ParentProps) { |
533 | 546 | }) |
534 | 547 | } |
535 | 548 | navigateToSession(session) |
536 | | - queueMicrotask(() => scrollToSession(session.id)) |
| 549 | + queueMicrotask(() => scrollToSession(session.id, `${session.directory}:${session.id}`)) |
537 | 550 | } |
538 | 551 |
|
539 | 552 | async function archiveSession(session: Session) { |
@@ -721,16 +734,23 @@ export default function Layout(props: ParentProps) { |
721 | 734 | } |
722 | 735 | } |
723 | 736 |
|
724 | | - createEffect(() => { |
725 | | - if (!pageReady()) return |
726 | | - if (!params.dir || !params.id) return |
727 | | - const directory = base64Decode(params.dir) |
728 | | - const id = params.id |
729 | | - setStore("lastSession", directory, id) |
730 | | - notification.session.markViewed(id) |
731 | | - untrack(() => setStore("workspaceExpanded", directory, (value) => value ?? true)) |
732 | | - requestAnimationFrame(() => scrollToSession(id)) |
733 | | - }) |
| 737 | + createEffect( |
| 738 | + on( |
| 739 | + () => ({ ready: pageReady(), dir: params.dir, id: params.id }), |
| 740 | + (value) => { |
| 741 | + if (!value.ready) return |
| 742 | + const dir = value.dir |
| 743 | + const id = value.id |
| 744 | + if (!dir || !id) return |
| 745 | + const directory = base64Decode(dir) |
| 746 | + setStore("lastSession", directory, id) |
| 747 | + notification.session.markViewed(id) |
| 748 | + untrack(() => setStore("workspaceExpanded", directory, (current) => current ?? true)) |
| 749 | + requestAnimationFrame(() => scrollToSession(id, `${directory}:${id}`)) |
| 750 | + }, |
| 751 | + { defer: true }, |
| 752 | + ), |
| 753 | + ) |
734 | 754 |
|
735 | 755 | createEffect(() => { |
736 | 756 | const project = currentProject() |
|
0 commit comments