Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: add a Scroll while generating setting (Auto-scroll or Manual) (#12110)

Michael Hane7a5b4972791
diff --git a/studio/frontend/src/components/assistant-ui/use-intent-aware-autoscroll.tsx b/studio/frontend/src/components/assistant-ui/use-intent-aware-autoscroll.tsx
index 8ac3cd6b4e9..7d4c3b23913 100644
--- a/studio/frontend/src/components/assistant-ui/use-intent-aware-autoscroll.tsx
+++ b/studio/frontend/src/components/assistant-ui/use-intent-aware-autoscroll.tsx
@@ -3,7 +3,8 @@
"use client";
-import { useAuiEvent } from "@assistant-ui/react";
+import { useChatPreferencesStore } from "@/features/chat/stores/chat-preferences-store";
+import { useAui, useAuiEvent } from "@assistant-ui/react";
import {
type ReactNode,
type RefCallback,
@@ -140,10 +141,14 @@ export function useIntentAwareAutoScroll(): {
ref: RefCallback<HTMLElement>;
context: AutoScrollContextValue;
} {
+ const aui = useAui();
const cleanupRef = useRef<(() => void) | null>(null);
const userDetachedRef = useRef(false);
const followUntilRef = useRef(0);
+ const runStartedHereRef = useRef(false);
+ // runEnd fires before the last chunk commits, so the hold outlives it briefly.
+ const runEndAtRef = useRef(Number.NEGATIVE_INFINITY);
const isAtBottomRef = useRef(true);
const listenersRef = useRef<Set<() => void>>(new Set());
@@ -178,6 +183,7 @@ export function useIntentAwareAutoScroll(): {
}, []);
const scrollToBottom = useCallback<ScrollToBottom>((behavior) => {
+ runStartedHereRef.current = false;
scrollImplRef.current(behavior);
}, []);
@@ -263,6 +269,37 @@ export function useIntentAwareAutoScroll(): {
followUntilRef.current = performance.now() + FOLLOW_SETTLE_MS;
};
+ const holdStill = (): boolean =>
+ runStartedHereRef.current &&
+ !useChatPreferencesStore.getState().autoScrollWhileGenerating &&
+ (aui.thread().getState().isRunning ||
+ performance.now() - runEndAtRef.current < FOLLOW_SETTLE_MS);
+
+ const holdCeiling = (): number | null => {
+ const rows = el.querySelectorAll<HTMLElement>("[data-role]");
+ let reply: HTMLElement | null = null;
+ let user: HTMLElement | null = null;
+ for (let i = rows.length - 1; i >= 0 && !user; i--) {
+ if (rows[i].dataset.role === "user") {
+ user = rows[i];
+ } else if (rows[i].dataset.role === "assistant") {
+ reply = rows[i];
+ }
+ }
+ if (!user || !reply) {
+ return null;
+ }
+ const origin =
+ el.getBoundingClientRect().top -
+ el.scrollTop +
+ (Number.parseFloat(getComputedStyle(el).paddingTop) || 0);
+ return Math.max(
+ 0,
+ user.getBoundingClientRect().top - origin,
+ reply.getBoundingClientRect().top - origin - el.clientHeight / 2,
+ );
+ };
+
const clearSettleCheck = (): void => {
if (settleTimer !== null) {
clearTimeout(settleTimer);
@@ -271,7 +308,10 @@ export function useIntentAwareAutoScroll(): {
settleCheckDue = false;
};
+ let parked = false;
+
const detach = (): void => {
+ parked = false;
userDetachedRef.current = true;
followUntilRef.current = 0;
// Hygiene, not correctness: `following` checks userDetached before `settling`, so a
@@ -284,6 +324,20 @@ export function useIntentAwareAutoScroll(): {
maxContentHeight = el.scrollHeight;
};
+ const parkIfHeld = (): boolean => {
+ if (userDetachedRef.current || !holdStill()) {
+ return false;
+ }
+ const ceiling = holdCeiling();
+ if (ceiling === null || el.scrollHeight - el.clientHeight < ceiling) {
+ return false;
+ }
+ el.scrollTo({ top: ceiling, behavior: "instant" });
+ detach();
+ parked = true;
+ return true;
+ };
+
const requestTick = (): void => {
if (rafId === null) {
rafId = requestAnimationFrame(tick);
@@ -319,6 +373,8 @@ export function useIntentAwareAutoScroll(): {
rafId = null;
const settling = settleCheckDue;
settleCheckDue = false;
+ // Park first so a frame without an observer record can't overshoot.
+ parkIfHeld();
const following =
!userDetachedRef.current &&
(settling || performance.now() < followUntilRef.current);
@@ -342,6 +398,7 @@ export function useIntentAwareAutoScroll(): {
};
scrollImplRef.current = (behavior = "auto") => {
+ parked = false;
userDetachedRef.current = false;
followUntilRef.current = performance.now() + FOLLOW_SETTLE_MS;
if (el.scrollHeight > el.clientHeight) {
@@ -440,7 +497,8 @@ export function useIntentAwareAutoScroll(): {
upwardAccumulator = 0;
if (
userDetachedRef.current &&
- distanceNow <= RE_ATTACH_THRESHOLD_PX
+ distanceNow <= RE_ATTACH_THRESHOLD_PX &&
+ !holdStill()
) {
userDetachedRef.current = false;
extendFollow();
@@ -536,7 +594,9 @@ export function useIntentAwareAutoScroll(): {
// pinning so we scroll to the post-adjustment scrollHeight.
const onLayoutChange = (): void => {
layoutChanged = true;
- extendFollow();
+ if (!parkIfHeld()) {
+ extendFollow();
+ }
const scrollHeight = stabilize();
pinIfFollowing(scrollHeight);
requestTick();
@@ -592,7 +652,25 @@ export function useIntentAwareAutoScroll(): {
// viewport shrinks without the element's clientHeight changing.
window.visualViewport?.addEventListener("resize", onViewportResize);
+ const unsubscribePreferences = useChatPreferencesStore.subscribe(
+ (state, prev) => {
+ if (
+ !parked ||
+ !state.autoScrollWhileGenerating ||
+ prev.autoScrollWhileGenerating ||
+ !aui.thread().getState().isRunning
+ ) {
+ return;
+ }
+ parked = false;
+ userDetachedRef.current = false;
+ extendFollow();
+ requestTick();
+ },
+ );
+
return () => {
+ unsubscribePreferences();
if (rafId !== null) {
cancelAnimationFrame(rafId);
rafId = null;
@@ -616,7 +694,7 @@ export function useIntentAwareAutoScroll(): {
};
};
},
- [setIsAtBottom],
+ [aui, setIsAtBottom],
);
// Thread lifecycle moments that always pin, regardless of detach state.
@@ -627,9 +705,22 @@ export function useIntentAwareAutoScroll(): {
scrollImplRef.current(behavior);
}, []);
- useAuiEvent("thread.runStart", () => pinToBottom("auto"));
- useAuiEvent("thread.initialize", () => pinToBottom("instant"));
- useAuiEvent("threadListItem.switchedTo", () => pinToBottom("instant"));
+ useAuiEvent("thread.runStart", () => {
+ runStartedHereRef.current = true;
+ runEndAtRef.current = Number.NEGATIVE_INFINITY;
+ pinToBottom("auto");
+ });
+ useAuiEvent("thread.runEnd", () => {
+ runEndAtRef.current = performance.now();
+ });
+ useAuiEvent("thread.initialize", () => {
+ runStartedHereRef.current = false;
+ pinToBottom("instant");
+ });
+ useAuiEvent("threadListItem.switchedTo", () => {
+ runStartedHereRef.current = false;
+ pinToBottom("instant");
+ });
const lastElRef = useRef<HTMLElement | null>(null);
const ref = useCallback<RefCallback<HTMLElement>>(
diff --git a/studio/frontend/src/features/chat/stores/chat-preferences-store.ts b/studio/frontend/src/features/chat/stores/chat-preferences-store.ts
index b1f2c7af07a..7d15a96ccec 100644
--- a/studio/frontend/src/features/chat/stores/chat-preferences-store.ts
+++ b/studio/frontend/src/features/chat/stores/chat-preferences-store.ts
@@ -57,6 +57,8 @@ export interface ChatPreferencesState {
setFoldToolActivityIntoThinking: (value: boolean) => void;
pastedTextMinChars: number;
setPastedTextMinChars: (value: number) => void;
+ autoScrollWhileGenerating: boolean;
+ setAutoScrollWhileGenerating: (value: boolean) => void;
}
// A stale stored value would leave the dropdown blank and unfixable.
@@ -107,6 +109,9 @@ export const useChatPreferencesStore = create<ChatPreferencesState>()(
pastedTextMinChars: PASTED_TEXT_DEFAULT_MIN_CHARS,
setPastedTextMinChars: (pastedTextMinChars) =>
set({ pastedTextMinChars }),
+ autoScrollWhileGenerating: true,
+ setAutoScrollWhileGenerating: (autoScrollWhileGenerating) =>
+ set({ autoScrollWhileGenerating }),
}),
{
name: "unsloth_chat_preferences",
@@ -143,6 +148,7 @@ export const useChatPreferencesStore = create<ChatPreferencesState>()(
pastedTextMinChars: normalisePastedTextMinChars(
saved?.pastedTextMinChars,
),
+ autoScrollWhileGenerating: saved?.autoScrollWhileGenerating ?? true,
};
},
},
diff --git a/studio/frontend/src/features/settings/settings-search.ts b/studio/frontend/src/features/settings/settings-search.ts
index 656144872a2..27860abd330 100644
--- a/studio/frontend/src/features/settings/settings-search.ts
+++ b/studio/frontend/src/features/settings/settings-search.ts
@@ -124,6 +124,7 @@ export const SETTINGS_SEARCH_INDEX: Record<SettingsTab, TranslationKey[]> = {
"settings.chat.projectAttachments",
"settings.chat.rememberParamsPerModel",
"settings.chat.autoCompact",
+ "settings.chat.autoScroll",
"settings.profile.greetingSloth",
"settings.chat.thinking.visibility",
"settings.chat.tools.visibility",
@@ -368,4 +369,5 @@ export const SETTINGS_SEARCH_KEYWORDS: Partial<
"settings.chat.thinking.visibility": "settings.chat.visibilityKeywords",
"settings.chat.tools.visibility": "settings.chat.visibilityKeywords",
"settings.chat.tools.foldIntoThinking": "settings.chat.visibilityKeywords",
+ "settings.chat.autoScroll": "settings.chat.autoScrollKeywords",
};
diff --git a/studio/frontend/src/features/settings/tabs/chat-tab.tsx b/studio/frontend/src/features/settings/tabs/chat-tab.tsx
index a57ae231381..b0a275452df 100644
--- a/studio/frontend/src/features/settings/tabs/chat-tab.tsx
+++ b/studio/frontend/src/features/settings/tabs/chat-tab.tsx
@@ -27,6 +27,7 @@ import { formatBindingLabel, isMacPlatform } from "../lib/keyboard-shortcuts";
import { useUserProfileStore } from "@/features/profile";
import { type TranslationKey, useT } from "@/i18n";
import { toast } from "@/lib/toast";
+import { cn } from "@/lib/utils";
import {
Bookmark02Icon,
Download01Icon,
@@ -248,6 +249,12 @@ export function ChatTab() {
const setShowResponseModel = useChatPreferencesStore(
(state) => state.setShowResponseModel,
);
+ const autoScrollWhileGenerating = useChatPreferencesStore(
+ (state) => state.autoScrollWhileGenerating,
+ );
+ const setAutoScrollWhileGenerating = useChatPreferencesStore(
+ (state) => state.setAutoScrollWhileGenerating,
+ );
const thinkingVisibility = useChatPreferencesStore(
(state) => state.thinkingVisibility,
);
@@ -392,6 +399,37 @@ export function ChatTab() {
onCheckedChange={setAutoCompactEnabled}
/>
</SettingsRow>
+ <SettingsRow
+ label={t("settings.chat.autoScroll")}
+ description={t("settings.chat.autoScrollDescription")}
+ >
+ <div
+ className="hub-tab-toggle inline-flex h-8 items-center rounded-full"
+ role="group"
+ aria-label={t("settings.chat.autoScroll")}
+ >
+ {([true, false] as const).map((follow) => (
+ <button
+ key={String(follow)}
+ type="button"
+ aria-pressed={autoScrollWhileGenerating === follow}
+ onClick={() => setAutoScrollWhileGenerating(follow)}
+ className={cn(
+ "inline-flex h-8 cursor-pointer items-center rounded-full px-3.5 text-ui-12 font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
+ autoScrollWhileGenerating === follow
+ ? "hub-tab-toggle-pill text-foreground"
+ : "text-muted-foreground hover:text-foreground",
+ )}
+ >
+ {t(
+ follow
+ ? "settings.chat.autoScrollAuto"
+ : "settings.chat.autoScrollManual",
+ )}
+ </button>
+ ))}
+ </div>
+ </SettingsRow>
</SettingsSection>
<SettingsSection title={t("settings.chat.groups.conversations.title")}>
diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.ts
index 0487311f1c6..477418a7db2 100644
--- a/studio/frontend/src/i18n/locales/ar.ts
+++ b/studio/frontend/src/i18n/locales/ar.ts
@@ -1808,6 +1808,13 @@ export const ar = {
pastedTextThresholdDescription:
"اضغط {shortcut} للصق مباشرة في مربع الرسالة.",
pastedTextThresholdOff: "إيقاف",
+ autoScroll: "التمرير أثناء الإنشاء",
+ autoScrollDescription:
+ "التمرير التلقائي يُبقي النص الجديد ظاهرًا. اليدوي يثبت لتقرأ من البداية.",
+ autoScrollAuto: "تمرير تلقائي",
+ autoScrollManual: "يدوي",
+ autoScrollKeywords:
+ "تمرير تلقائي متابعة أسفل قفز بث إنشاء تثبيت scroll autoscroll follow",
showResponseModel: "إظهار نموذج الاستجابة",
showResponseModelDescription:
"إظهار البيانات الوصفية للنموذج في ردود المساعد.",
diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.ts
index c5f391d0c35..55b982bc712 100644
--- a/studio/frontend/src/i18n/locales/de.ts
+++ b/studio/frontend/src/i18n/locales/de.ts
@@ -1846,6 +1846,13 @@ export const de = {
pastedTextThresholdDescription:
"Mit {shortcut} direkt in das Nachrichtenfeld einfügen.",
pastedTextThresholdOff: "Aus",
+ autoScroll: "Scrollen beim Generieren",
+ autoScrollDescription:
+ "Automatisch scrollen hält neuen Text im Blick. Manuell bleibt stehen, um von Anfang an zu lesen.",
+ autoScrollAuto: "Automatisch scrollen",
+ autoScrollManual: "Manuell",
+ autoScrollKeywords:
+ "scrollen automatisch mitscrollen folgen unten springen Streaming generieren Ansicht sperren scroll autoscroll follow",
showResponseModel: "Antwortmodell anzeigen",
showResponseModelDescription:
"Modellmetadaten in Antworten des Assistenten anzeigen.",
diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.ts
index 5a968343885..581a1c82c2d 100644
--- a/studio/frontend/src/i18n/locales/en.ts
+++ b/studio/frontend/src/i18n/locales/en.ts
@@ -1804,6 +1804,13 @@ export const en = {
pastedTextThreshold: "Condense long pastes",
pastedTextThresholdDescription: "Press {shortcut} to paste directly into the message box.",
pastedTextThresholdOff: "Off",
+ autoScroll: "Scroll while generating",
+ autoScrollDescription:
+ "Auto-scroll keeps new text in view. Manual stays put so you can read from the start.",
+ autoScrollAuto: "Auto-scroll",
+ autoScrollManual: "Manual",
+ autoScrollKeywords:
+ "scroll autoscroll auto-scroll follow stick bottom jump streaming generating viewport lock hold auto manual",
showResponseModel: "Response model",
showResponseModelDescription:
"Show model details in assistant responses.",
diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.ts
index 3b220d993ce..842f47109e2 100644
--- a/studio/frontend/src/i18n/locales/es.ts
+++ b/studio/frontend/src/i18n/locales/es.ts
@@ -1837,6 +1837,13 @@ export const es = {
pastedTextThresholdDescription:
"Pulsa {shortcut} para pegar directamente en el cuadro de mensaje.",
pastedTextThresholdOff: "Desactivado",
+ autoScroll: "Desplazamiento al generar",
+ autoScrollDescription:
+ "El desplazamiento automático mantiene visible el texto nuevo. Manual se queda quieto para leer desde el principio.",
+ autoScrollAuto: "Desplazamiento automático",
+ autoScrollManual: "Manual",
+ autoScrollKeywords:
+ "desplazamiento desplazar automático seguir abajo saltar transmisión generar vista bloquear scroll autoscroll follow",
showResponseModel: "Mostrar el modelo de respuesta",
showResponseModelDescription:
"Muestra los metadatos del modelo en las respuestas del asistente.",
diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.ts
index a0483a70345..d64fde032db 100644
--- a/studio/frontend/src/i18n/locales/fr.ts
+++ b/studio/frontend/src/i18n/locales/fr.ts
@@ -1843,6 +1843,13 @@ export const fr = {
pastedTextThresholdDescription:
"Appuyez sur {shortcut} pour coller directement dans le champ de message.",
pastedTextThresholdOff: "Désactivé",
+ autoScroll: "Défilement pendant la génération",
+ autoScrollDescription:
+ "Le défilement auto garde le nouveau texte visible. Manuel reste en place pour lire depuis le début.",
+ autoScrollAuto: "Défilement auto",
+ autoScrollManual: "Manuel",
+ autoScrollKeywords:
+ "défilement défiler automatique suivre bas sauter diffusion génération vue verrouiller scroll autoscroll follow",
showResponseModel: "Afficher le modèle de réponse",
showResponseModelDescription:
"Afficher les métadonnées du modèle dans les réponses de l’assistant.",
diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.ts
index 06bcae0dd48..b79ac454e08 100644
--- a/studio/frontend/src/i18n/locales/hi.ts
+++ b/studio/frontend/src/i18n/locales/hi.ts
@@ -1814,6 +1814,13 @@ export const hi = {
pastedTextThresholdDescription:
"सीधे संदेश बॉक्स में पेस्ट करने के लिए {shortcut} दबाएँ।",
pastedTextThresholdOff: "बंद",
+ autoScroll: "जनरेट करते समय स्क्रॉल",
+ autoScrollDescription:
+ "ऑटो-स्क्रॉल नया टेक्स्ट दिखाता रहता है। मैन्युअल में पेज रुका रहता है ताकि आप शुरू से पढ़ सकें।",
+ autoScrollAuto: "ऑटो-स्क्रॉल",
+ autoScrollManual: "मैन्युअल",
+ autoScrollKeywords:
+ "स्क्रॉल ऑटो-स्क्रॉल फ़ॉलो नीचे स्ट्रीमिंग जनरेट लॉक scroll autoscroll follow",
showResponseModel: "जवाब देने वाला मॉडल दिखाएँ",
showResponseModelDescription:
"असिस्टेंट के जवाबों में मॉडल का मेटाडेटा दिखाएँ।",
diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.ts
index 6d6b02b9745..dfe0528d1ad 100644
--- a/studio/frontend/src/i18n/locales/it.ts
+++ b/studio/frontend/src/i18n/locales/it.ts
@@ -1807,6 +1807,13 @@ export const it = {
pastedTextThresholdDescription:
"Premi {shortcut} per incollare direttamente nel campo del messaggio.",
pastedTextThresholdOff: "Disattivato",
+ autoScroll: "Scorrimento durante la generazione",
+ autoScrollDescription:
+ "Lo scorrimento automatico mantiene visibile il nuovo testo. Manuale resta fermo per leggere dall'inizio.",
+ autoScrollAuto: "Scorrimento automatico",
+ autoScrollManual: "Manuale",
+ autoScrollKeywords:
+ "scorrimento scorrere automatico seguire fondo saltare streaming generazione vista bloccare scroll autoscroll follow",
showResponseModel: "Mostra il modello della risposta",
showResponseModelDescription:
"Mostra i metadati del modello nelle risposte dell'assistente.",
diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.ts
index 6eb4a0c99e5..578276c3c43 100644
--- a/studio/frontend/src/i18n/locales/ja.ts
+++ b/studio/frontend/src/i18n/locales/ja.ts
@@ -1793,6 +1793,13 @@ export const ja = {
pastedTextThresholdDescription:
"{shortcut} を押すと、入力欄に直接貼り付けられます。",
pastedTextThresholdOff: "オフ",
+ autoScroll: "生成中のスクロール",
+ autoScrollDescription:
+ "自動スクロールは新しいテキストを表示し続けます。手動は位置を保ち、最初から読めます。",
+ autoScrollAuto: "自動スクロール",
+ autoScrollManual: "手動",
+ autoScrollKeywords:
+ "スクロール 自動スクロール 追従 下 ジャンプ ストリーミング 生成 固定 scroll autoscroll follow",
showResponseModel: "応答モデルを表示",
showResponseModelDescription:
"アシスタントの応答にモデルのメタデータを表示します。",
diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.ts
index 6c7d0a24759..99625a0ed7c 100644
--- a/studio/frontend/src/i18n/locales/ko.ts
+++ b/studio/frontend/src/i18n/locales/ko.ts
@@ -1803,6 +1803,13 @@ export const ko = {
pastedTextThresholdDescription:
"{shortcut} 키를 누르면 입력창에 바로 붙여넣습니다.",
pastedTextThresholdOff: "끄기",
+ autoScroll: "생성 중 스크롤",
+ autoScrollDescription:
+ "자동 스크롤은 새 텍스트를 계속 보여 줍니다. 수동은 위치를 유지해 처음부터 읽을 수 있습니다.",
+ autoScrollAuto: "자동 스크롤",
+ autoScrollManual: "수동",
+ autoScrollKeywords:
+ "스크롤 자동 스크롤 따라가기 아래 이동 스트리밍 생성 고정 scroll autoscroll follow",
showResponseModel: "응답 모델 표시",
showResponseModelDescription:
"어시스턴트 응답에 모델 메타데이터를 표시합니다.",
diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.ts
index 162b5c1727c..b3851d55d67 100644
--- a/studio/frontend/src/i18n/locales/pt-br.ts
+++ b/studio/frontend/src/i18n/locales/pt-br.ts
@@ -1824,6 +1824,13 @@ export const ptBR = {
pastedTextThresholdDescription:
"Pressione {shortcut} para colar diretamente na caixa de mensagem.",
pastedTextThresholdOff: "Desativado",
+ autoScroll: "Rolagem durante a geração",
+ autoScrollDescription:
+ "A rolagem automática mantém o texto novo à vista. Manual fica parado para ler desde o início.",
+ autoScrollAuto: "Rolagem automática",
+ autoScrollManual: "Manual",
+ autoScrollKeywords:
+ "rolagem rolar automática acompanhar fim pular streaming gerar visualização travar scroll autoscroll follow",
showResponseModel: "Mostrar o modelo da resposta",
showResponseModelDescription:
"Mostra os metadados do modelo nas respostas do assistente.",
diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.ts
index ddc2b882d1c..c1d4e87f777 100644
--- a/studio/frontend/src/i18n/locales/ru.ts
+++ b/studio/frontend/src/i18n/locales/ru.ts
@@ -1820,6 +1820,13 @@ export const ru = {
pastedTextThresholdDescription:
"Нажмите {shortcut}, чтобы вставить текст прямо в поле сообщения.",
pastedTextThresholdOff: "Выкл.",
+ autoScroll: "Прокрутка при генерации",
+ autoScrollDescription:
+ "Автопрокрутка держит новый текст на виду. Вручную страница стоит на месте, чтобы читать с начала.",
+ autoScrollAuto: "Автопрокрутка",
+ autoScrollManual: "Вручную",
+ autoScrollKeywords:
+ "прокрутка автопрокрутка следовать вниз низ поток генерация зафиксировать scroll autoscroll follow",
showResponseModel: "Показывать модель в ответах",
showResponseModelDescription:
"Показывать метаданные модели в ответах ассистента.",
diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.ts
index 80fcf710d3c..446ace57398 100644
--- a/studio/frontend/src/i18n/locales/zh-CN.ts
+++ b/studio/frontend/src/i18n/locales/zh-CN.ts
@@ -1769,6 +1769,13 @@ export const zhCN = {
pastedTextThresholdDescription:
"按 {shortcut} 直接粘贴到消息输入框。",
pastedTextThresholdOff: "关闭",
+ autoScroll: "生成时滚动",
+ autoScrollDescription:
+ "自动滚动让新文本保持可见。手动保持不动,方便从头阅读。",
+ autoScrollAuto: "自动滚动",
+ autoScrollManual: "手动",
+ autoScrollKeywords:
+ "滚动 自动滚动 跟随 底部 跳转 流式 生成 锁定 scroll autoscroll follow",
showResponseModel: "显示回复模型",
showResponseModelDescription: "在助手回复中显示模型元数据。",
inlineReadAloud: "在回复上显示朗读",
diff --git a/studio/frontend/tests/chat-autoscroll-preference.test.ts b/studio/frontend/tests/chat-autoscroll-preference.test.ts
new file mode 100644
index 00000000000..70e492d57dd
--- /dev/null
+++ b/studio/frontend/tests/chat-autoscroll-preference.test.ts
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+// The hook is .tsx, which node's type stripping cannot import, so its shape is pinned from source.
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { readSrc, registerBundlerResolver } from "./helpers/kit.ts";
+
+registerBundlerResolver();
+const { useChatPreferencesStore } =
+ await import("../src/features/chat/stores/chat-preferences-store.ts");
+
+const HOOK = readSrc("components/assistant-ui/use-intent-aware-autoscroll.tsx");
+const STORE = readSrc("features/chat/stores/chat-preferences-store.ts");
+
+function body(signature: string): string {
+ const start = HOOK.indexOf(signature);
+ assert.notEqual(start, -1, `${signature} is gone; this test needs rewriting`);
+ return HOOK.slice(start, HOOK.indexOf("\n };", start));
+}
+
+test("auto-scroll follows by default, including installs that never saw the setting", () => {
+ assert.equal(
+ useChatPreferencesStore.getInitialState().autoScrollWhileGenerating,
+ true,
+ );
+ assert.match(
+ STORE,
+ /autoScrollWhileGenerating: saved\?\.autoScrollWhileGenerating \?\? true/,
+ );
+});
+
+test("the setting is an Auto / Manual pill selector, not a switch", () => {
+ const TAB = readSrc("features/settings/tabs/chat-tab.tsx");
+ const at = TAB.indexOf('label={t("settings.chat.autoScroll")}');
+ assert.notEqual(at, -1);
+ const row = TAB.slice(at, TAB.indexOf("</SettingsRow>", at));
+ assert.match(row, /hub-tab-toggle/);
+ assert.match(row, /settings\.chat\.autoScrollAuto/);
+ assert.match(row, /settings\.chat\.autoScrollManual/);
+ assert.ok(!row.includes("<Switch"));
+});
+
+test("the setting is read per call, so flipping it mid-run applies at once", () => {
+ const holdStill = body("const holdStill = (): boolean =>");
+ assert.match(
+ holdStill,
+ /useChatPreferencesStore\.getState\(\)\.autoScrollWhileGenerating/,
+ );
+ assert.match(holdStill, /aui\.thread\(\)\.getState\(\)\.isRunning/);
+});
+
+test("only a run started on screen holds still, not one already streaming when opened", () => {
+ const holdStill = body("const holdStill = (): boolean =>");
+ assert.match(holdStill, /runStartedHereRef\.current &&/);
+ for (const event of ["thread.initialize", "threadListItem.switchedTo"]) {
+ const at = HOOK.indexOf(`useAuiEvent("${event}"`);
+ assert.notEqual(at, -1, event);
+ assert.match(
+ HOOK.slice(at, HOOK.indexOf("});", at)),
+ /runStartedHereRef\.current = false;/,
+ );
+ }
+ const runStart = HOOK.indexOf('useAuiEvent("thread.runStart"');
+ assert.match(
+ HOOK.slice(runStart, HOOK.indexOf("});", runStart)),
+ /runStartedHereRef\.current = true;/,
+ );
+});
+
+test("a held run follows until its turn reaches the top, then parks", () => {
+ const onLayoutChange = body("const onLayoutChange = (): void => {");
+ assert.match(onLayoutChange, /if \(!parkIfHeld\(\)\) \{\s*extendFollow\(\);/);
+ const park = body("const parkIfHeld = (): boolean => {");
+ assert.match(park, /!holdStill\(\)/);
+ assert.match(park, /holdCeiling\(\)/);
+ assert.match(
+ park,
+ /el\.scrollTo\(\{ top: ceiling, behavior: "instant" \}\);\s*detach\(\);/,
+ );
+ const ceiling = body("const holdCeiling = (): number | null => {");
+ assert.match(ceiling, /querySelectorAll<HTMLElement>\("\[data-role\]"\)/);
+ const tick = body("const tick = (): void => {");
+ assert.ok(tick.indexOf("parkIfHeld();") < tick.indexOf("const following"));
+});
+
+test("the scroll-to-bottom button ends the hold for the rest of the run", () => {
+ const at = HOOK.indexOf("const scrollToBottom = useCallback<ScrollToBottom>");
+ assert.notEqual(at, -1);
+ assert.match(
+ HOOK.slice(at, HOOK.indexOf("}, []);", at)),
+ /runStartedHereRef\.current = false;/,
+ );
+});
+
+test("reaching the bottom by hand does not re-attach while holding still", () => {
+ const onScroll = body("const onScroll = () => {");
+ assert.match(
+ onScroll,
+ /distanceNow <= RE_ATTACH_THRESHOLD_PX &&\s*!holdStill\(\)/,
+ );
+});
+
+test("the hold outlives runEnd briefly, so the last chunk still parks", () => {
+ const holdStill = body("const holdStill = (): boolean =>");
+ assert.match(
+ holdStill,
+ /performance\.now\(\) - runEndAtRef\.current < FOLLOW_SETTLE_MS/,
+ );
+ const runEnd = HOOK.indexOf('useAuiEvent("thread.runEnd"');
+ assert.notEqual(runEnd, -1);
+ assert.match(
+ HOOK.slice(runEnd, HOOK.indexOf("});", runEnd)),
+ /runEndAtRef\.current = performance\.now\(\);/,
+ );
+});
+
+test("turning auto-scroll on mid-run releases a park", () => {
+ const park = body("const parkIfHeld = (): boolean => {");
+ assert.match(park, /detach\(\);\s*parked = true;/);
+ const at = HOOK.indexOf("useChatPreferencesStore.subscribe(");
+ assert.notEqual(at, -1);
+ const listener = HOOK.slice(at, HOOK.indexOf("\n );", at));
+ assert.match(listener, /!parked \|\|/);
+ assert.match(listener, /prev\.autoScrollWhileGenerating/);
+ assert.match(
+ listener,
+ /userDetachedRef\.current = false;\s*extendFollow\(\);/,
+ );
+ assert.match(HOOK, /unsubscribePreferences\(\);/);
+});