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: make the paste-to-attachment threshold a chat setting (#8963)

Michael Hanaa3f3c2799ae
diff --git a/studio/frontend/src/components/assistant-ui/attachment.tsx b/studio/frontend/src/components/assistant-ui/attachment.tsx
index b508d244833..ff5e7282c6c 100644
--- a/studio/frontend/src/components/assistant-ui/attachment.tsx
+++ b/studio/frontend/src/components/assistant-ui/attachment.tsx
@@ -251,9 +251,9 @@ const PastedTextPreviewDialog: FC<
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild={true}>{children}</DialogTrigger>
- <DialogContent className="aui-pasted-text-dialog flex max-h-[80dvh] w-[min(46rem,92vw)] max-w-none flex-col gap-3 overflow-hidden">
+ <DialogContent className="aui-pasted-text-dialog flex max-h-[88dvh] w-[min(68rem,94vw)] max-w-none flex-col gap-3 overflow-hidden">
<DialogTitle className="truncate pr-8 text-sm">{name}</DialogTitle>
- <pre className="aui-pasted-text-dialog-body max-h-[64dvh] overflow-auto whitespace-pre-wrap break-words rounded-lg border bg-muted/40 p-3 text-left font-mono text-xs leading-relaxed">
+ <pre className="aui-pasted-text-dialog-body max-h-[72dvh] overflow-auto whitespace-pre-wrap break-words rounded-lg border bg-muted/40 p-3 text-left font-mono text-xs leading-relaxed">
{preview?.text ?? "Loading…"}
</pre>
{preview && preview.remaining > 0 ? (
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 75176a19c99..c744032c389 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -2122,6 +2122,9 @@ const Composer: FC<{
const setPendingImageEditReference = useChatRuntimeStore(
(s) => s.setPendingImageEditReference,
);
+ const pastedTextMinChars = useChatPreferencesStore(
+ (state) => state.pastedTextMinChars,
+ );
const { inputProps, isComposing, isComposingRef } =
useImeComposerInputHandlers({ submitOnEnter: true });
// A pasted YouTube link offers a transcript attachment above the composer.
@@ -2159,6 +2162,7 @@ const Composer: FC<{
toast.error("Could not attach the pasted text.", {
description: "Paste it again, or paste it in smaller pieces.",
}),
+ pastedTextMinChars,
);
if (attachedPastedText) return;
pasteClipboardFiles(
@@ -2174,7 +2178,7 @@ const Composer: FC<{
}),
);
},
- [aui, overlay],
+ [aui, overlay, pastedTextMinChars],
);
const composerText = useAuiState(({ composer }) => composer.text);
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 9871de0f0ae..0df6d15395c 100644
--- a/studio/frontend/src/features/chat/stores/chat-preferences-store.ts
+++ b/studio/frontend/src/features/chat/stores/chat-preferences-store.ts
@@ -3,6 +3,10 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
+import {
+ PASTED_TEXT_DEFAULT_MIN_CHARS,
+ PASTED_TEXT_THRESHOLD_CHOICES,
+} from "../utils/pasted-text";
// Client-side chat UI prefs kept in localStorage, not the chat DB.
// confirmDeleteChats: when off, deleting a chat skips the confirm dialog.
@@ -12,6 +16,7 @@ import { persist } from "zustand/middleware";
// showResponseModel: when on, assistant responses show the producing model.
// collapseThinkingByDefault: when on, thinking stays collapsed instead of
// streaming open.
+// pastedTextMinChars: paste length that becomes a .txt attachment. 0 is off.
export interface ChatPreferencesState {
confirmDeleteChats: boolean;
setConfirmDeleteChats: (value: boolean) => void;
@@ -23,6 +28,17 @@ export interface ChatPreferencesState {
setShowResponseModel: (value: boolean) => void;
collapseThinkingByDefault: boolean;
setCollapseThinkingByDefault: (value: boolean) => void;
+ pastedTextMinChars: number;
+ setPastedTextMinChars: (value: number) => void;
+}
+
+// A stale stored value would leave the dropdown blank and unfixable.
+function normalisePastedTextMinChars(value: unknown): number {
+ return PASTED_TEXT_THRESHOLD_CHOICES.includes(
+ value as (typeof PASTED_TEXT_THRESHOLD_CHOICES)[number],
+ )
+ ? (value as number)
+ : PASTED_TEXT_DEFAULT_MIN_CHARS;
}
export const useChatPreferencesStore = create<ChatPreferencesState>()(
@@ -39,11 +55,13 @@ export const useChatPreferencesStore = create<ChatPreferencesState>()(
setShowModelDisclaimer: (showModelDisclaimer) =>
set({ showModelDisclaimer }),
showResponseModel: false,
- setShowResponseModel: (showResponseModel) =>
- set({ showResponseModel }),
+ setShowResponseModel: (showResponseModel) => set({ showResponseModel }),
collapseThinkingByDefault: false,
setCollapseThinkingByDefault: (collapseThinkingByDefault) =>
set({ collapseThinkingByDefault }),
+ pastedTextMinChars: PASTED_TEXT_DEFAULT_MIN_CHARS,
+ setPastedTextMinChars: (pastedTextMinChars) =>
+ set({ pastedTextMinChars }),
}),
{
name: "unsloth_chat_preferences",
@@ -56,6 +74,9 @@ export const useChatPreferencesStore = create<ChatPreferencesState>()(
showModelDisclaimer: saved?.showModelDisclaimer ?? true,
showResponseModel: saved?.showResponseModel ?? false,
collapseThinkingByDefault: saved?.collapseThinkingByDefault ?? false,
+ pastedTextMinChars: normalisePastedTextMinChars(
+ saved?.pastedTextMinChars,
+ ),
};
},
},
diff --git a/studio/frontend/src/features/chat/utils/pasted-text.ts b/studio/frontend/src/features/chat/utils/pasted-text.ts
index d07f4aa8409..779a0f73059 100644
--- a/studio/frontend/src/features/chat/utils/pasted-text.ts
+++ b/studio/frontend/src/features/chat/utils/pasted-text.ts
@@ -10,8 +10,16 @@ import {
} from "./clipboard-payload.ts";
const PASTED_TEXT_MIME = "text/plain";
-export const PASTED_TEXT_MIN_CHARS = 2000;
-export const PASTED_TEXT_MIN_LINES = 40;
+// Threshold the user picks in Settings > Chat. 0 keeps every paste inline.
+export const PASTED_TEXT_THRESHOLD_OFF = 0;
+export const PASTED_TEXT_DEFAULT_MIN_CHARS = 4000;
+export const PASTED_TEXT_THRESHOLD_CHOICES = [
+ PASTED_TEXT_THRESHOLD_OFF,
+ 2000,
+ PASTED_TEXT_DEFAULT_MIN_CHARS,
+ 8000,
+ 16000,
+] as const;
const PASTED_TEXT_NAME_MAX_CHARS = 32;
// Enough for the name after whitespace collapses, without copying a line.
const PASTED_TEXT_NAME_SCAN_CHARS = 256;
@@ -38,22 +46,15 @@ const pastedTextFiles = new WeakSet<File>();
// The text as pasted, so draft autosave never re-reads the File on a keystroke.
const pastedTextByFile = new WeakMap<File, string>();
-function countLines(text: string): number {
- let lines = 1;
- for (let index = 0; index < text.length; index += 1) {
- if (text[index] === "\n") lines += 1;
- }
- return lines;
-}
-
-// No upper bound, and whitespace is not exempt: the bigger the paste, the
+// Length alone decides. Whitespace is not exempt: the bigger the paste, the
// worse it is inline.
-export function shouldAttachPastedText(text: string): boolean {
+export function shouldAttachPastedText(
+ text: string,
+ minChars: number = PASTED_TEXT_DEFAULT_MIN_CHARS,
+): boolean {
if (text.length === 0) return false;
- return (
- text.length >= PASTED_TEXT_MIN_CHARS ||
- countLines(text) >= PASTED_TEXT_MIN_LINES
- );
+ if (minChars <= PASTED_TEXT_THRESHOLD_OFF) return false;
+ return text.length >= minChars;
}
// Splitting a multi-megabyte paste to read one line allocates every other
@@ -269,6 +270,7 @@ export function pasteLongTextAsFile(
event: ClipboardTextPasteEvent,
addFile: (file: File) => void | Promise<void>,
onError?: () => void,
+ minChars?: number,
): boolean {
if (event.defaultPrevented) return false;
const { clipboardData } = event;
@@ -278,7 +280,7 @@ export function pasteLongTextAsFile(
if (clipboardAdvertisesFiles(clipboardData)) return false;
const text = clipboardText(clipboardData);
- if (!shouldAttachPastedText(text)) return false;
+ if (!shouldAttachPastedText(text, minChars)) return false;
// Build the file first: if that throws, the browser can still paste.
let file: File;
diff --git a/studio/frontend/src/features/settings/tabs/chat-tab.tsx b/studio/frontend/src/features/settings/tabs/chat-tab.tsx
index 931f8944c7e..8fd1b7da53c 100644
--- a/studio/frontend/src/features/settings/tabs/chat-tab.tsx
+++ b/studio/frontend/src/features/settings/tabs/chat-tab.tsx
@@ -1,6 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
import { Switch } from "@/components/ui/switch";
import {
type PlusMenuItemId,
@@ -9,6 +16,7 @@ import {
usePlusMenuPrefsStore,
useSidebarOrganizationStore,
} from "@/features/chat";
+import { PASTED_TEXT_THRESHOLD_CHOICES } from "@/features/chat/utils/pasted-text";
import { useUserProfileStore } from "@/features/profile";
import { type TranslationKey, useT } from "@/i18n";
import {
@@ -182,6 +190,12 @@ export function ChatTab() {
const setCollapseThinkingByDefault = useChatPreferencesStore(
(state) => state.setCollapseThinkingByDefault,
);
+ const pastedTextMinChars = useChatPreferencesStore(
+ (state) => state.pastedTextMinChars,
+ );
+ const setPastedTextMinChars = useChatPreferencesStore(
+ (state) => state.setPastedTextMinChars,
+ );
useEffect(() => {
void hydratePersistedSettings();
@@ -289,6 +303,31 @@ export function ChatTab() {
>
<Switch checked={autoTitle} onCheckedChange={setAutoTitle} />
</SettingsRow>
+ <SettingsRow
+ label={t("settings.chat.pastedTextThreshold")}
+ description={t("settings.chat.pastedTextThresholdDescription")}
+ >
+ <Select
+ value={String(pastedTextMinChars)}
+ onValueChange={(value) => setPastedTextMinChars(Number(value))}
+ >
+ <SelectTrigger
+ className="w-36"
+ aria-label={t("settings.chat.pastedTextThreshold")}
+ >
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ {PASTED_TEXT_THRESHOLD_CHOICES.map((choice) => (
+ <SelectItem key={choice} value={String(choice)}>
+ {choice === 0
+ ? t("settings.chat.pastedTextThresholdOff")
+ : choice.toLocaleString()}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ </SettingsRow>
<SettingsRow
label={t("settings.profile.greetingSloth")}
description={t("settings.profile.greetingSlothDescription")}
diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.ts
index 80f522fb15e..683a4b882d6 100644
--- a/studio/frontend/src/i18n/locales/ar.ts
+++ b/studio/frontend/src/i18n/locales/ar.ts
@@ -1003,6 +1003,9 @@ export const ar = {
compareChat: "مقارنة المحادثات",
exportChat: "تصدير المحادثة",
},
+ pastedTextThreshold: "ضغط النصوص الملصقة الطويلة",
+ pastedTextThresholdDescription: "النص الملصق الأطول من هذا الحد يصبح مرفق \u200e.txt بدلاً من ملء مربع الرسالة.",
+ pastedTextThresholdOff: "إيقاف",
showResponseModel: "إظهار نموذج الاستجابة",
showResponseModelDescription:
"إظهار البيانات الوصفية للنموذج في ردود المساعد.",
diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.ts
index e3ef379d15c..5ab914f8646 100644
--- a/studio/frontend/src/i18n/locales/de.ts
+++ b/studio/frontend/src/i18n/locales/de.ts
@@ -1038,6 +1038,9 @@ export const de = {
compareChat: "Chats vergleichen",
exportChat: "Chat exportieren",
},
+ pastedTextThreshold: "Lange Einfügungen verdichten",
+ pastedTextThresholdDescription: "Eingefügter Text, der länger ist, wird zu einem .txt-Anhang, statt das Nachrichtenfeld zu füllen.",
+ pastedTextThresholdOff: "Aus",
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 6b30ec93a4e..69f06b71a95 100644
--- a/studio/frontend/src/i18n/locales/en.ts
+++ b/studio/frontend/src/i18n/locales/en.ts
@@ -999,6 +999,9 @@ export const en = {
compareChat: "Compare chat",
exportChat: "Export chat",
},
+ pastedTextThreshold: "Condense long pastes",
+ pastedTextThresholdDescription: "Pasted text longer than this becomes a .txt attachment instead of filling the message box.",
+ pastedTextThresholdOff: "Off",
showResponseModel: "Show response model",
showResponseModelDescription:
"Show model metadata in assistant responses.",
diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.ts
index daeeca4d132..3c6e9592a7a 100644
--- a/studio/frontend/src/i18n/locales/es.ts
+++ b/studio/frontend/src/i18n/locales/es.ts
@@ -1029,6 +1029,9 @@ export const es = {
compareChat: "Comparar chats",
exportChat: "Exportar chat",
},
+ pastedTextThreshold: "Condensar pegados largos",
+ pastedTextThresholdDescription: "El texto pegado más largo que esto se convierte en un adjunto .txt en lugar de llenar el cuadro de mensaje.",
+ pastedTextThresholdOff: "Desactivado",
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 8caddadb47f..1ae1d4dde1a 100644
--- a/studio/frontend/src/i18n/locales/fr.ts
+++ b/studio/frontend/src/i18n/locales/fr.ts
@@ -1035,6 +1035,9 @@ export const fr = {
compareChat: "Comparer le chat",
exportChat: "Exporter le chat",
},
+ pastedTextThreshold: "Condenser les collages longs",
+ pastedTextThresholdDescription: "Le texte collé plus long que cette valeur devient une pièce jointe .txt au lieu de remplir le champ de message.",
+ pastedTextThresholdOff: "Désactivé",
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 1655f41c716..fa0d0a805a5 100644
--- a/studio/frontend/src/i18n/locales/hi.ts
+++ b/studio/frontend/src/i18n/locales/hi.ts
@@ -1009,6 +1009,9 @@ export const hi = {
compareChat: "चैट की तुलना करें",
exportChat: "चैट एक्सपोर्ट करें",
},
+ pastedTextThreshold: "लंबे पेस्ट को संक्षिप्त करें",
+ pastedTextThresholdDescription: "इससे लंबा चिपकाया गया टेक्स्ट संदेश बॉक्स भरने के बजाय .txt अटैचमेंट बन जाता है।",
+ pastedTextThresholdOff: "बंद",
showResponseModel: "जवाब देने वाला मॉडल दिखाएँ",
showResponseModelDescription:
"असिस्टेंट के जवाबों में मॉडल का मेटाडेटा दिखाएँ।",
diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.ts
index 38a4d47b3b2..690eec2afda 100644
--- a/studio/frontend/src/i18n/locales/it.ts
+++ b/studio/frontend/src/i18n/locales/it.ts
@@ -1003,6 +1003,9 @@ export const it = {
compareChat: "Confronta chat",
exportChat: "Esporta chat",
},
+ pastedTextThreshold: "Condensa incolla lunghi",
+ pastedTextThresholdDescription: "Il testo incollato più lungo di questo valore diventa un allegato .txt invece di riempire il campo del messaggio.",
+ pastedTextThresholdOff: "Disattivato",
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 61fbed697aa..2db819fb98b 100644
--- a/studio/frontend/src/i18n/locales/ja.ts
+++ b/studio/frontend/src/i18n/locales/ja.ts
@@ -992,6 +992,9 @@ export const ja = {
compareChat: "チャットを比較",
exportChat: "チャットをエクスポート",
},
+ pastedTextThreshold: "長い貼り付けを圧縮",
+ pastedTextThresholdDescription: "この長さを超える貼り付けテキストは、入力欄を埋める代わりに .txt 添付ファイルになります。",
+ pastedTextThresholdOff: "オフ",
showResponseModel: "応答モデルを表示",
showResponseModelDescription:
"アシスタントの応答にモデルのメタデータを表示します。",
diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.ts
index 17f6ffac921..1013b257955 100644
--- a/studio/frontend/src/i18n/locales/ko.ts
+++ b/studio/frontend/src/i18n/locales/ko.ts
@@ -1001,6 +1001,9 @@ export const ko = {
compareChat: "채팅 비교",
exportChat: "채팅 내보내기",
},
+ pastedTextThreshold: "긴 붙여넣기 압축",
+ pastedTextThresholdDescription: "이 길이를 초과한 붙여넣기 텍스트는 입력창을 채우는 대신 .txt 첨부 파일이 됩니다.",
+ pastedTextThresholdOff: "끄기",
showResponseModel: "응답 모델 표시",
showResponseModelDescription:
"어시스턴트 응답에 모델 메타데이터를 표시합니다.",
diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.ts
index ffa911820a5..ba95cdb1592 100644
--- a/studio/frontend/src/i18n/locales/pt-br.ts
+++ b/studio/frontend/src/i18n/locales/pt-br.ts
@@ -1017,6 +1017,9 @@ export const ptBR = {
compareChat: "Comparar chats",
exportChat: "Exportar chat",
},
+ pastedTextThreshold: "Condensar colagens longas",
+ pastedTextThresholdDescription: "Texto colado maior que isso vira um anexo .txt em vez de encher a caixa de mensagem.",
+ pastedTextThresholdOff: "Desativado",
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 461ca38e10c..39729fed76b 100644
--- a/studio/frontend/src/i18n/locales/ru.ts
+++ b/studio/frontend/src/i18n/locales/ru.ts
@@ -1014,6 +1014,9 @@ export const ru = {
compareChat: "Сравнить чаты",
exportChat: "Экспортировать чат",
},
+ pastedTextThreshold: "Сворачивать длинные вставки",
+ pastedTextThresholdDescription: "Вставленный текст длиннее этого значения станет вложением .txt вместо заполнения поля сообщения.",
+ pastedTextThresholdOff: "Выкл.",
showResponseModel: "Показывать модель в ответах",
showResponseModelDescription:
"Показывать метаданные модели в ответах ассистента.",
diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.ts
index 5ee67cbf4d5..7431ca26f4e 100644
--- a/studio/frontend/src/i18n/locales/zh-CN.ts
+++ b/studio/frontend/src/i18n/locales/zh-CN.ts
@@ -979,6 +979,9 @@ export const zhCN = {
compareChat: "对比聊天",
exportChat: "导出聊天",
},
+ pastedTextThreshold: "压缩长粘贴内容",
+ pastedTextThresholdDescription: "超过此长度的粘贴文本将变为 .txt 附件,而不会填满消息输入框。",
+ pastedTextThresholdOff: "关闭",
showResponseModel: "显示回复模型",
showResponseModelDescription: "在助手回复中显示模型元数据。",
modelDisclaimer: "显示模型免责声明",
diff --git a/studio/frontend/tests/pasted-text-attachment.test.ts b/studio/frontend/tests/pasted-text-attachment.test.ts
index 0d52f3efd49..70de153ad9f 100644
--- a/studio/frontend/tests/pasted-text-attachment.test.ts
+++ b/studio/frontend/tests/pasted-text-attachment.test.ts
@@ -6,9 +6,10 @@ import test from "node:test";
import { fallbackTitleFromUserText } from "../src/features/chat/utils/chat-title.ts";
import {
- PASTED_TEXT_MIN_CHARS,
- PASTED_TEXT_MIN_LINES,
+ PASTED_TEXT_DEFAULT_MIN_CHARS,
PASTED_TEXT_PREVIEW_MAX_CHARS,
+ PASTED_TEXT_THRESHOLD_CHOICES,
+ PASTED_TEXT_THRESHOLD_OFF,
attachmentContentSample,
attachmentContentText,
attachmentsPastedText,
@@ -66,24 +67,45 @@ test("short pastes stay inline", () => {
assert.equal(shouldAttachPastedText(" \n "), false);
assert.equal(shouldAttachPastedText("what does this function do?"), false);
assert.equal(
- shouldAttachPastedText("a".repeat(PASTED_TEXT_MIN_CHARS - 1)),
- false,
- );
- assert.equal(
- shouldAttachPastedText("line\n".repeat(PASTED_TEXT_MIN_LINES - 2)),
+ shouldAttachPastedText("a".repeat(PASTED_TEXT_DEFAULT_MIN_CHARS - 1)),
false,
);
+ // Line count no longer decides: a tall but short paste stays inline.
+ assert.equal(shouldAttachPastedText("line\n".repeat(200)), false);
});
-test("bulk pastes become attachments by length or by line count", () => {
- assert.equal(shouldAttachPastedText("a".repeat(PASTED_TEXT_MIN_CHARS)), true);
- // Many short lines (a log tail, a stack trace) are just as unusable inline.
+test("bulk pastes become attachments by length", () => {
assert.equal(
- shouldAttachPastedText("x\n".repeat(PASTED_TEXT_MIN_LINES)),
+ shouldAttachPastedText("a".repeat(PASTED_TEXT_DEFAULT_MIN_CHARS)),
true,
);
});
+test("the threshold is configurable", () => {
+ const text = "a".repeat(3000);
+ assert.equal(shouldAttachPastedText(text, 2000), true);
+ assert.equal(shouldAttachPastedText(text, 4000), false);
+ assert.equal(shouldAttachPastedText(text, 16000), false);
+});
+
+test("the off choice keeps every paste inline", () => {
+ const huge = "a".repeat(5 * 1024 * 1024);
+ assert.equal(shouldAttachPastedText(huge, PASTED_TEXT_THRESHOLD_OFF), false);
+ // A negative or nonsense value cannot turn it back on either.
+ assert.equal(shouldAttachPastedText(huge, -1), false);
+});
+
+test("the default is one of the offered choices", () => {
+ assert.ok(
+ PASTED_TEXT_THRESHOLD_CHOICES.includes(PASTED_TEXT_DEFAULT_MIN_CHARS),
+ );
+ assert.equal(PASTED_TEXT_DEFAULT_MIN_CHARS, 4000);
+ assert.deepEqual(
+ [...PASTED_TEXT_THRESHOLD_CHOICES],
+ [0, 2000, 4000, 8000, 16000],
+ );
+});
+
test("the file is named after the opening of the paste", () => {
assert.equal(
pastedTextFileName("Introducing Unsloth"),
@@ -132,9 +154,7 @@ test("the file is named after the opening of the paste", () => {
});
test("pasted text files are recognised by identity", () => {
- const file = createPastedTextFile(
- "Deploy log\n".repeat(PASTED_TEXT_MIN_LINES),
- );
+ const file = createPastedTextFile("Deploy log\n".repeat(400));
assert.equal(file.name, "Deploy log.txt");
assert.equal(file.type, "text/plain");
assert.equal(isPastedTextFile(file), true);
@@ -340,7 +360,7 @@ test("the preview is capped, and says how much it is holding back", () => {
});
test("a long text paste is swallowed and handed over as a file", async () => {
- const text = "a".repeat(PASTED_TEXT_MIN_CHARS);
+ const text = "a".repeat(PASTED_TEXT_DEFAULT_MIN_CHARS);
const added: File[] = [];
const event = pasteEvent(clipboard(text));
@@ -366,7 +386,7 @@ test("normal pastes and file pastes fall through untouched", () => {
// An image on the clipboard belongs to the file-paste path, even when the
// app also offers a long text/plain rendering of it.
const withFile = pasteEvent(
- clipboard("a".repeat(PASTED_TEXT_MIN_CHARS), [
+ clipboard("a".repeat(PASTED_TEXT_DEFAULT_MIN_CHARS), [
new File([new Uint8Array([1, 2, 3])], "shot.png", { type: "image/png" }),
]),
);
@@ -387,10 +407,9 @@ test("a paste too big to hold inline still attaches", () => {
// one case the input cannot survive.
const huge = "a".repeat(20 * 1024 * 1024 + 1);
assert.equal(shouldAttachPastedText(huge), true);
- // Whitespace is no exemption either: it used to skip both thresholds.
- assert.equal(shouldAttachPastedText(" ".repeat(PASTED_TEXT_MIN_CHARS)), true);
+ // Whitespace is no exemption either.
assert.equal(
- shouldAttachPastedText("\n".repeat(PASTED_TEXT_MIN_LINES)),
+ shouldAttachPastedText(" ".repeat(PASTED_TEXT_DEFAULT_MIN_CHARS)),
true,
);
assert.equal(shouldAttachPastedText(" "), false);
@@ -398,7 +417,9 @@ test("a paste too big to hold inline still attaches", () => {
test("an attachment that throws on the spot reports instead of vanishing", () => {
let errors = 0;
- const event = pasteEvent(clipboard("a".repeat(PASTED_TEXT_MIN_CHARS)));
+ const event = pasteEvent(
+ clipboard("a".repeat(PASTED_TEXT_DEFAULT_MIN_CHARS)),
+ );
const handled = pasteLongTextAsFile(
event,
@@ -424,7 +445,7 @@ test("a .txt named like a pasted one keeps the normal tile", () => {
});
test("native image and file payloads stay on the file paste path", () => {
- const text = "a".repeat(PASTED_TEXT_MIN_CHARS);
+ const text = "a".repeat(PASTED_TEXT_DEFAULT_MIN_CHARS);
// Tauri advertises native payloads by type only, with nothing in files.
const svg = pasteEvent(
clipboard(text, [], { types: ["text/plain", "image/svg+xml"] }),