Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/routes/tutorial/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@
history.pushState({}, '', `?${q}`);
}
}

/** @type {HTMLElement} */
let sidebar;

/** @type {import('./$types').Snapshot<number>} */
export const snapshot = {
capture: () => {
const scroll = sidebar.scrollTop;
sidebar.scrollTop = 0;
return scroll;
},
restore: (scroll) => {
sidebar.scrollTop = scroll;
}
};
</script>

<svelte:head>
Expand Down Expand Up @@ -164,6 +179,7 @@
<SplitPane id="main" type="horizontal" min="360px" max="50%" pos="33%">
<section slot="a" class="content">
<Sidebar
bind:sidebar
index={data.index}
exercise={data.exercise}
on:select={(e) => {
Expand Down
14 changes: 3 additions & 11 deletions src/routes/tutorial/[slug]/Sidebar.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import { createEventDispatcher } from 'svelte';
import { afterNavigate } from '$app/navigation';
import Modal from '$lib/components/Modal.svelte';
import Menu from './Menu.svelte';

Expand All @@ -10,22 +9,15 @@
/** @type {import('$lib/types').Exercise} */
export let exercise;

/** @type {HTMLElement} */
export let sidebar;

const dispatch = createEventDispatcher();

const namespace = 'learn.svelte.dev';
const copy_enabled = `${namespace}:copy_enabled`;

/** @type {HTMLElement} */
let sidebar;

let show_modal = false;

afterNavigate(async () => {
// TODO ideally we would associate scroll state with
// history. That's a little tricky to do right now,
// so for now just always reset sidebar scroll
sidebar.scrollTop = 0;
});
</script>

<Menu {index} current={exercise} />
Expand Down