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: paste without formatting always fills the message box (#9545)

Michael Han27ca0c9704ca
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 58bce5e1586..9d397f7113e 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -61,6 +61,8 @@ import {
pasteClipboardFiles,
extractYoutubeVideoId,
pasteLongTextAsFile,
+ isPlainPasteChord,
+ plainPasteStillCounts,
isStudioDictationAvailable,
notifyStudioDictationUnavailable,
YoutubeTranscriptPrompt,
@@ -2339,8 +2341,36 @@ const Composer: FC<{
});
// A pasted YouTube link offers a transcript attachment above the composer.
const [youtubeLink, setYoutubeLink] = useState<string | null>(null);
+ // Paste without formatting asks for the clipboard in the field, so the paste
+ // it makes stays inline however long it is. A paste event carries no
+ // modifiers, so the chord is read from the keydown before it, and the flag
+ // lasts only as long as the keys are down: the paste is the keydown's own
+ // default action, while a menu the user might reach for instead cannot be
+ // opened without letting go first.
+ const plainPasteAtRef = useRef(0);
+ const notePlainPasteChord = useCallback(
+ (event: KeyboardEvent<HTMLTextAreaElement>) => {
+ plainPasteAtRef.current = isPlainPasteChord(event)
+ ? performance.now()
+ : 0;
+ },
+ [],
+ );
+ // Any release ends it, whichever key of the chord goes first, as does losing
+ // the field. The time cap behind them is for a release that never lands,
+ // which is what tabbing away mid-chord used to leave behind.
+ const endPlainPasteChord = useCallback(() => {
+ plainPasteAtRef.current = 0;
+ }, []);
const handleFilePaste = useCallback(
(event: ClipboardEvent<HTMLTextAreaElement>) => {
+ // Read once and cleared here, so a paste with no chord before it, from
+ // the menu or a script, is never taken for the plain one.
+ const plainPaste = plainPasteStillCounts(
+ plainPasteAtRef.current,
+ performance.now(),
+ );
+ plainPasteAtRef.current = 0;
const pastedText = event.clipboardData?.getData("text/plain") ?? "";
if (extractYoutubeVideoId(pastedText)) {
setYoutubeLink(pastedText.trim());
@@ -2362,7 +2392,11 @@ const Composer: FC<{
if (composer.getState().text !== value) return;
composer.setText(value.slice(0, selectionStart) + value.slice(selectionEnd));
};
- const attachedPastedText = !overlay && pasteGoesLast && pasteLongTextAsFile(
+ const attachedPastedText =
+ !overlay &&
+ !plainPaste &&
+ pasteGoesLast &&
+ pasteLongTextAsFile(
event,
async (file) => {
await aui.composer().addAttachment(file);
@@ -4556,6 +4590,10 @@ const Composer: FC<{
// no effect on Latin / CJK / Devanagari.
dir="auto"
{...inputProps}
+ // Capture, so inputProps keeps the handlers it already owns.
+ onKeyDownCapture={notePlainPasteChord}
+ onKeyUpCapture={endPlainPasteChord}
+ onBlurCapture={endPlainPasteChord}
addAttachmentOnPaste={false}
onPaste={handleFilePaste}
/>
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index 7c08e5b860c..d36f5551820 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -211,7 +211,9 @@ export {
createPastedTextFile,
isPastedTextContent,
isPastedTextFile,
+ isPlainPasteChord,
pasteLongTextAsFile,
+ plainPasteStillCounts,
pastedTextContentBytes,
pastedTextContentPreview,
pastedTextOf,
diff --git a/studio/frontend/src/features/chat/utils/pasted-text.ts b/studio/frontend/src/features/chat/utils/pasted-text.ts
index 779a0f73059..76be4c9d586 100644
--- a/studio/frontend/src/features/chat/utils/pasted-text.ts
+++ b/studio/frontend/src/features/chat/utils/pasted-text.ts
@@ -40,6 +40,86 @@ type ClipboardTextPasteEvent = {
preventDefault: () => void;
};
+type PlainPasteKeyEvent = {
+ readonly code?: string;
+ readonly key?: string;
+ /** Deprecated, but layout-independent, and every engine still sets it. */
+ readonly keyCode?: number;
+ readonly metaKey: boolean;
+ readonly ctrlKey: boolean;
+ readonly shiftKey: boolean;
+ readonly altKey: boolean;
+};
+
+/** `KeyboardEvent.keyCode` for V, which follows the physical key, not the
+ * character the layout and Option produce. */
+const V_KEY_CODE = 86;
+
+// Resolved once: the chord below is read on every keydown in the composer, and
+// the platform cannot change under a live document.
+let macPlatform: boolean | null = null;
+
+function isMacPlatform(): boolean {
+ if (macPlatform !== null) return macPlatform;
+ if (typeof navigator === "undefined") return false;
+ macPlatform = /mac|iphone|ipad|ipod/i.test(
+ `${navigator.platform ?? ""} ${navigator.userAgent ?? ""}`,
+ );
+ return macPlatform;
+}
+
+/**
+ * The paste-without-formatting chord: ⌥⇧⌘V on macOS, which is what its Edit
+ * menu carries and so the only one that actually pastes there, and Ctrl+Shift+V
+ * elsewhere. It asks for the clipboard in the field, so a paste made with it
+ * stays inline however long it is.
+ */
+export function isPlainPasteChord(
+ event: PlainPasteKeyEvent,
+ mac: boolean = isMacPlatform(),
+): boolean {
+ if (!event.shiftKey) return false;
+ // The other platform's modifier is a different chord, not this one.
+ if (mac ? !event.metaKey || event.ctrlKey : !event.ctrlKey || event.metaKey) {
+ return false;
+ }
+ // Option belongs to the chord on macOS and to nothing off it. ⇧⌘V is taken
+ // on macOS too: web apps bind it, so a host that maps it should reach the
+ // field rather than the attachment path.
+ if (event.altKey && !mac) return false;
+ // The layout decides where paste lives, not the board: Dvorak puts V on the
+ // QWERTY period key and moves the chord with it. So a key that types a
+ // letter answers for itself, and a letter that is not v is not this chord
+ // however it is wired.
+ const typed = (event.key ?? "").toLowerCase();
+ if (!event.altKey && typed.length === 1 && typed >= "a" && typed <= "z") {
+ return typed === "v";
+ }
+ // No letter to read: Option rewrote it, ⌥V being "√" and ⌥⇧V "◊", or the
+ // layout types none at all. The two signals left disagree on a remapped
+ // board -- `code` is the position the key sits at, `keyCode` the letter it
+ // stands for -- and only one of them can be pointing at the chord, so either
+ // saying V is enough. The wrong one costing us nothing is what makes that
+ // safe: this only counts while the keys are still down, and the one paste
+ // that can land by then is the chord's own.
+ return event.code === "KeyV" || event.keyCode === V_KEY_CODE;
+}
+
+/**
+ * How long a plain-paste chord stands for the paste it asks for. The browser
+ * dispatches that paste while it is still handling the keydown, so the window
+ * only has to survive one task. It has to expire, though: on macOS ⇧⌘V is a
+ * web-app convention rather than a menu command, so it can be pressed and
+ * paste nothing, and the Edit-menu paste the user reaches for next arrives
+ * with no keydown of its own to clear the chord.
+ */
+export const PLAIN_PASTE_GESTURE_MS = 1000;
+
+/** True when the paste being handled is the one that chord asked for. */
+export function plainPasteStillCounts(chordAt: number, now: number): boolean {
+ return chordAt > 0 && now - chordAt < PLAIN_PASTE_GESTURE_MS;
+}
+
// Identity separates a pasted blob from a .txt the user attached. A sent
// message keeps no File, so the wrapper below carries it over instead.
const pastedTextFiles = new WeakSet<File>();
diff --git a/studio/frontend/src/features/settings/tabs/chat-tab.tsx b/studio/frontend/src/features/settings/tabs/chat-tab.tsx
index f119ef7d51f..63d7faf8036 100644
--- a/studio/frontend/src/features/settings/tabs/chat-tab.tsx
+++ b/studio/frontend/src/features/settings/tabs/chat-tab.tsx
@@ -17,6 +17,7 @@ import {
useSidebarOrganizationStore,
} from "@/features/chat";
import { PASTED_TEXT_THRESHOLD_CHOICES } from "@/features/chat/utils/pasted-text";
+import { formatBindingLabel, isMacPlatform } from "../lib/keyboard-shortcuts";
import { useUserProfileStore } from "@/features/profile";
import { type TranslationKey, useT } from "@/i18n";
import {
@@ -212,6 +213,14 @@ export function ChatTab() {
const setPastedTextMinChars = useChatPreferencesStore(
(state) => state.setPastedTextMinChars,
);
+ // The platform's own paste-without-formatting chord, which the composer reads
+ // as "put it in the box" whatever this threshold says. macOS carries it on
+ // Option, that being the chord its Edit menu binds.
+ const macPlatform = isMacPlatform();
+ const plainPasteLabel = formatBindingLabel(
+ { code: "KeyV", mod: true, ctrl: false, shift: true, alt: macPlatform },
+ macPlatform,
+ );
useEffect(() => {
void hydratePersistedSettings();
@@ -341,7 +350,9 @@ export function ChatTab() {
</SettingsRow>
<SettingsRow
label={t("settings.chat.pastedTextThreshold")}
- description={t("settings.chat.pastedTextThresholdDescription")}
+ description={t("settings.chat.pastedTextThresholdDescription", {
+ shortcut: plainPasteLabel,
+ })}
>
<Select
value={String(pastedTextMinChars)}
diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.ts
index 30dd86b6e35..59ba7fc9285 100644
--- a/studio/frontend/src/i18n/locales/ar.ts
+++ b/studio/frontend/src/i18n/locales/ar.ts
@@ -1090,7 +1090,7 @@ export const ar = {
exportChat: "تصدير المحادثة",
},
pastedTextThreshold: "ضغط النصوص الملصقة الطويلة",
- pastedTextThresholdDescription: "النص الملصق الأطول من هذا الحد يصبح مرفق \u200e.txt بدلاً من ملء مربع الرسالة.",
+ pastedTextThresholdDescription: "النص الملصق الأطول من هذا الحد يصبح مرفق \u200e.txt بدلاً من ملء مربع الرسالة. اضغط {shortcut} للصق في مربع الرسالة على أي حال.",
pastedTextThresholdOff: "إيقاف",
showResponseModel: "إظهار نموذج الاستجابة",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.ts
index 8d14f946cfe..6a3c471493b 100644
--- a/studio/frontend/src/i18n/locales/de.ts
+++ b/studio/frontend/src/i18n/locales/de.ts
@@ -1126,7 +1126,7 @@ export const de = {
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.",
+ pastedTextThresholdDescription: "Eingefügter Text, der länger ist, wird zu einem .txt-Anhang, statt das Nachrichtenfeld zu füllen. Mit {shortcut} wird trotzdem in das Nachrichtenfeld eingefügt.",
pastedTextThresholdOff: "Aus",
showResponseModel: "Antwortmodell anzeigen",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.ts
index a300afee547..41f60b1eb7f 100644
--- a/studio/frontend/src/i18n/locales/en.ts
+++ b/studio/frontend/src/i18n/locales/en.ts
@@ -1086,7 +1086,7 @@ export const en = {
exportChat: "Export chat",
},
pastedTextThreshold: "Condense long pastes",
- pastedTextThresholdDescription: "Pasted text longer than this becomes a .txt attachment instead of filling the message box.",
+ pastedTextThresholdDescription: "Pasted text longer than this becomes a .txt attachment instead of filling the message box. Press {shortcut} to paste into the message box anyway.",
pastedTextThresholdOff: "Off",
showResponseModel: "Show response model",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.ts
index fd61f9bcbea..a2cb1087e21 100644
--- a/studio/frontend/src/i18n/locales/es.ts
+++ b/studio/frontend/src/i18n/locales/es.ts
@@ -1117,7 +1117,7 @@ export const es = {
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.",
+ pastedTextThresholdDescription: "El texto pegado más largo que esto se convierte en un adjunto .txt en lugar de llenar el cuadro de mensaje. Pulsa {shortcut} para pegar en el cuadro de mensaje de todos modos.",
pastedTextThresholdOff: "Desactivado",
showResponseModel: "Mostrar el modelo de respuesta",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.ts
index 1884e18edf0..4416ee6d502 100644
--- a/studio/frontend/src/i18n/locales/fr.ts
+++ b/studio/frontend/src/i18n/locales/fr.ts
@@ -1123,7 +1123,7 @@ export const fr = {
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.",
+ pastedTextThresholdDescription: "Le texte collé plus long que cette valeur devient une pièce jointe .txt au lieu de remplir le champ de message. Appuyez sur {shortcut} pour coller quand même dans le champ de message.",
pastedTextThresholdOff: "Désactivé",
showResponseModel: "Afficher le modèle de réponse",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.ts
index de281956701..2dd126b0bf0 100644
--- a/studio/frontend/src/i18n/locales/hi.ts
+++ b/studio/frontend/src/i18n/locales/hi.ts
@@ -1097,7 +1097,7 @@ export const hi = {
exportChat: "चैट एक्सपोर्ट करें",
},
pastedTextThreshold: "लंबे पेस्ट को संक्षिप्त करें",
- pastedTextThresholdDescription: "इससे लंबा चिपकाया गया टेक्स्ट संदेश बॉक्स भरने के बजाय .txt अटैचमेंट बन जाता है।",
+ pastedTextThresholdDescription: "इससे लंबा चिपकाया गया टेक्स्ट संदेश बॉक्स भरने के बजाय .txt अटैचमेंट बन जाता है। {shortcut} दबाने पर यह फिर भी संदेश बॉक्स में चिपकेगा।",
pastedTextThresholdOff: "बंद",
showResponseModel: "जवाब देने वाला मॉडल दिखाएँ",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.ts
index 7142215cb18..b6fd4328122 100644
--- a/studio/frontend/src/i18n/locales/it.ts
+++ b/studio/frontend/src/i18n/locales/it.ts
@@ -1091,7 +1091,7 @@ export const it = {
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.",
+ pastedTextThresholdDescription: "Il testo incollato più lungo di questo valore diventa un allegato .txt invece di riempire il campo del messaggio. Premi {shortcut} per incollare comunque nel campo del messaggio.",
pastedTextThresholdOff: "Disattivato",
showResponseModel: "Mostra il modello della risposta",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.ts
index 5b6f8b143f6..545924a504f 100644
--- a/studio/frontend/src/i18n/locales/ja.ts
+++ b/studio/frontend/src/i18n/locales/ja.ts
@@ -1080,7 +1080,7 @@ export const ja = {
exportChat: "チャットをエクスポート",
},
pastedTextThreshold: "長い貼り付けを圧縮",
- pastedTextThresholdDescription: "この長さを超える貼り付けテキストは、入力欄を埋める代わりに .txt 添付ファイルになります。",
+ pastedTextThresholdDescription: "この長さを超える貼り付けテキストは、入力欄を埋める代わりに .txt 添付ファイルになります。 {shortcut} を押すと、それでも入力欄に貼り付けます。",
pastedTextThresholdOff: "オフ",
showResponseModel: "応答モデルを表示",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.ts
index 8fc1ae0c05d..20150523c55 100644
--- a/studio/frontend/src/i18n/locales/ko.ts
+++ b/studio/frontend/src/i18n/locales/ko.ts
@@ -1089,7 +1089,7 @@ export const ko = {
exportChat: "채팅 내보내기",
},
pastedTextThreshold: "긴 붙여넣기 압축",
- pastedTextThresholdDescription: "이 길이를 초과한 붙여넣기 텍스트는 입력창을 채우는 대신 .txt 첨부 파일이 됩니다.",
+ pastedTextThresholdDescription: "이 길이를 초과한 붙여넣기 텍스트는 입력창을 채우는 대신 .txt 첨부 파일이 됩니다. {shortcut} 를 누르면 그래도 입력창에 붙여넣습니다.",
pastedTextThresholdOff: "끄기",
showResponseModel: "응답 모델 표시",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.ts
index b3510b584a9..fcfe8c9691b 100644
--- a/studio/frontend/src/i18n/locales/pt-br.ts
+++ b/studio/frontend/src/i18n/locales/pt-br.ts
@@ -1105,7 +1105,7 @@ export const ptBR = {
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.",
+ pastedTextThresholdDescription: "Texto colado maior que isso vira um anexo .txt em vez de encher a caixa de mensagem. Pressione {shortcut} para colar na caixa de mensagem mesmo assim.",
pastedTextThresholdOff: "Desativado",
showResponseModel: "Mostrar o modelo da resposta",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.ts
index 6abfa20a34d..8e1b6702d4c 100644
--- a/studio/frontend/src/i18n/locales/ru.ts
+++ b/studio/frontend/src/i18n/locales/ru.ts
@@ -1102,7 +1102,7 @@ export const ru = {
exportChat: "Экспортировать чат",
},
pastedTextThreshold: "Сворачивать длинные вставки",
- pastedTextThresholdDescription: "Вставленный текст длиннее этого значения станет вложением .txt вместо заполнения поля сообщения.",
+ pastedTextThresholdDescription: "Вставленный текст длиннее этого значения станет вложением .txt вместо заполнения поля сообщения. Нажмите {shortcut}, чтобы всё равно вставить в поле сообщения.",
pastedTextThresholdOff: "Выкл.",
showResponseModel: "Показывать модель в ответах",
showResponseModelDescription:
diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.ts
index 47c95f0ccae..6bee6e6d127 100644
--- a/studio/frontend/src/i18n/locales/zh-CN.ts
+++ b/studio/frontend/src/i18n/locales/zh-CN.ts
@@ -1067,7 +1067,7 @@ export const zhCN = {
exportChat: "导出聊天",
},
pastedTextThreshold: "压缩长粘贴内容",
- pastedTextThresholdDescription: "超过此长度的粘贴文本将变为 .txt 附件,而不会填满消息输入框。",
+ pastedTextThresholdDescription: "超过此长度的粘贴文本将变为 .txt 附件,而不会填满消息输入框。 按 {shortcut} 仍可粘贴到消息输入框。",
pastedTextThresholdOff: "关闭",
showResponseModel: "显示回复模型",
showResponseModelDescription: "在助手回复中显示模型元数据。",
diff --git a/studio/frontend/tests/pasted-text-attachment.test.ts b/studio/frontend/tests/pasted-text-attachment.test.ts
index ddaca712546..b9327ed037c 100644
Binary files a/studio/frontend/tests/pasted-text-attachment.test.ts and b/studio/frontend/tests/pasted-text-attachment.test.ts differ