char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
1.3 KiB48 linesraw
1/**
2 * Scroll container binding and navigation guard for the ChatScreen.
3 *
4 * Binds the `AutoScrollController` to `document.documentElement`, exposes
5 * the container for programmatic scrolling, and flags an `isNavigating`
6 * window during route changes so the controller can reset without its
7 * scroll handler seeing spurious events from layout shifts.
8 */
9
10import type { AutoScrollController } from './use-auto-scroll.svelte';
11import { afterNavigate, beforeNavigate } from '$app/navigation';
12
13export function useChatScreenScroll(autoScroll: AutoScrollController) {
14	let chatScrollContainer: HTMLElement | undefined = $state();
15	let isNavigating = $state(false);
16
17	function handleScroll(event: UIEvent) {
18		// Ignore scroll events caused by navigation layout changes or by our own
19		// programmatic scrolls so they don't accidentally disable auto-scroll.
20		if (isNavigating || !event.isTrusted) return;
21
22		autoScroll.handleScroll();
23	}
24
25	beforeNavigate(() => {
26		isNavigating = true;
27		autoScroll.resetScrollState();
28	});
29
30	afterNavigate(() => {
31		setTimeout(() => {
32			isNavigating = false;
33			autoScroll.resetScrollState();
34		}, 10);
35	});
36
37	$effect(() => {
38		chatScrollContainer = document.documentElement;
39		autoScroll.setContainer(chatScrollContainer);
40	});
41
42	return {
43		get chatScrollContainer() {
44			return chatScrollContainer;
45		},
46		handleScroll
47	};
48}