Skip to content

Commit a22f040

Browse files
danddanddandclaude
andcommitted
feat(composer): choose when large pastes become text attachments
Pasted text only folds into a text-file attachment at 32 KiB, so everyday logs, stack traces, and code blocks land in the composer as text. On a phone that text fills the whole composer and the prompt around it is hard to reach or edit. Add a client setting with three presets (1 KB, 5 KB, and 32 KB, the default and today's behavior) on web, desktop, and mobile. The shared paste disposition and the native editors read the chosen threshold instead of a constant. Presets are labelled by size because the comparison counts UTF-8 bytes, and a stored value that is no longer a preset decodes to the default instead of failing the settings decode. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent f419698 commit a22f040

16 files changed

Lines changed: 234 additions & 17 deletions

File tree

‎apps/mobile/src/features/settings/SettingsFollowUpRouteScreen.tsx‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
22
import { useAtomSet, useAtomValue } from "@effect/atom-react";
3+
import {
4+
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
5+
type PastedTextAttachmentThreshold,
6+
} from "@t3tools/contracts";
7+
import { pastedTextThresholdLabel } from "@t3tools/client-runtime/text-paste";
38
import { AsyncResult } from "effect/reactivity";
49
import { Platform } from "react-native";
510
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -28,6 +33,17 @@ const FOLLOW_UP_OPTIONS: ReadonlyArray<{
2833
},
2934
];
3035

36+
const THRESHOLD_OPTIONS: ReadonlyArray<{
37+
readonly threshold: PastedTextAttachmentThreshold;
38+
readonly description: string;
39+
}> = [
40+
{ threshold: 1_000, description: "Most logs, stack traces, and code snippets become files." },
41+
{ threshold: 5_000, description: "Long logs and documents become files; snippets stay as text." },
42+
{ threshold: 32_768, description: "Default. Only very large pastes become files." },
43+
];
44+
45+
const PASTE_AS_TEXT_SHORTCUT = Platform.OS === "ios" ? "Command + Shift + V" : "Ctrl + Shift + V";
46+
3147
export function SettingsFollowUpRouteScreen() {
3248
const insets = useSafeAreaInsets();
3349
const preferencesResult = useAtomValue(mobilePreferencesAtom);
@@ -36,6 +52,10 @@ export function SettingsFollowUpRouteScreen() {
3652
const selectedBehavior = AsyncResult.isSuccess(preferencesResult)
3753
? (preferencesResult.value.followUpBehavior ?? DEFAULT_FOLLOW_UP_BEHAVIOR)
3854
: null;
55+
const selectedThreshold = AsyncResult.isSuccess(preferencesResult)
56+
? (preferencesResult.value.pastedTextAttachmentThreshold ??
57+
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)
58+
: null;
3959

4060
const content = (
4161
<ScrollView
@@ -62,6 +82,24 @@ export function SettingsFollowUpRouteScreen() {
6282
Long-press the send button to use the other option for a single message. With a hardware
6383
keyboard, hold {Platform.OS === "android" ? "Ctrl" : "Command"} while sending.
6484
</Text>
85+
<SettingsSection title="Attach pastes as files from">
86+
{THRESHOLD_OPTIONS.map(({ threshold, description }, index) => (
87+
<SettingsChoiceRow
88+
key={threshold}
89+
label={pastedTextThresholdLabel(threshold)}
90+
description={description}
91+
selected={selectedThreshold === threshold}
92+
separated={index > 0}
93+
disabled={!preferencesReady}
94+
onPress={() => savePreferences({ pastedTextAttachmentThreshold: threshold })}
95+
/>
96+
))}
97+
</SettingsSection>
98+
<Text className="px-2 text-sm text-foreground-muted">
99+
Shorter pastes go into the message as text. Non-Latin text and emoji use more bytes per
100+
character, so they reach the limit sooner. With a hardware keyboard, press{" "}
101+
{PASTE_AS_TEXT_SHORTCUT} to paste a long block as text instead.
102+
</Text>
65103
</ScrollView>
66104
);
67105

‎apps/mobile/src/features/settings/settings-search.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,15 @@ const SETTINGS_SEARCH_TERMS = {
7676
"auto-resume",
7777
"thread behavior",
7878
],
79-
SettingsFollowUp: ["follow-ups", "queue", "steer", "while the agent is running"],
79+
SettingsFollowUp: [
80+
"follow-ups",
81+
"queue",
82+
"steer",
83+
"while the agent is running",
84+
"large pastes",
85+
"attachment",
86+
"text file",
87+
],
8088
SettingsArchive: ["archive", "archived", "restore", "unarchive"],
8189
SettingsProviderAccounts: [
8290
"provider accounts",

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Animated, {
5252
withTiming,
5353
} from "react-native-reanimated";
5454
import { useUniwindTheme } from "../../lib/useUniwindTheme";
55+
import { usePastedTextAttachmentThreshold } from "../../lib/usePastedTextAttachmentThreshold";
5556
import { themeColorWithAlpha } from "../../lib/mobileTheme";
5657
import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/remoteRegistration";
5758
import { scopedThreadKey } from "../../lib/scopedEntities";
@@ -422,6 +423,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
422423
const navigation = useNavigation();
423424
const foregroundColor = useUniwindTheme()["--color-foreground"];
424425
const bodyText = useScaledTextRole("body");
426+
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();
425427
const fallbackInputRef = useRef<ComposerEditorHandle>(null);
426428
const inputRef = props.editorRef ?? fallbackInputRef;
427429
const [isFocused, setIsFocused] = useState(false);
@@ -1013,6 +1015,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
10131015
text: paste.text,
10141016
wouldExceedInputLimit,
10151017
canAttach: true,
1018+
thresholdBytes: pastedTextAttachmentThreshold,
10161019
}) === "attachment"
10171020
) {
10181021
if (canAttach) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useAtomValue } from "@effect/atom-react";
2+
import { DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD } from "@t3tools/contracts";
3+
import { AsyncResult } from "effect/reactivity";
4+
5+
import { mobilePreferencesAtom } from "../state/preferences";
6+
7+
/**
8+
* Paste size at which the composer folds clipboard text into a text-file
9+
* attachment. Selects only the threshold so unrelated preference writes do not
10+
* re-render the composer editors.
11+
*/
12+
export function usePastedTextAttachmentThreshold() {
13+
return useAtomValue(mobilePreferencesAtom, (preferences) =>
14+
AsyncResult.isSuccess(preferences)
15+
? (preferences.value.pastedTextAttachmentThreshold ??
16+
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)
17+
: DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
18+
);
19+
}

‎apps/mobile/src/native/T3ComposerEditor.ios.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES } from "@t3tools/client-runtime/text-paste";
21
import { PROVIDER_SEND_TURN_MAX_INPUT_CHARS } from "@t3tools/contracts";
32
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
43
import { composerContextEditorTokens, composerSkillLabels } from "../lib/composerContext";
@@ -27,6 +26,7 @@ import { contextChipIconUri, modelChipIcon, modelChipIconUri } from "../lib/cont
2726
import { useUniwindTheme } from "../lib/useUniwindTheme";
2827
import { createNativeComposerTheme } from "../lib/nativeComposerTheme";
2928
import { FONT_FAMILIES } from "../lib/fontFamilies";
29+
import { usePastedTextAttachmentThreshold } from "../lib/usePastedTextAttachmentThreshold";
3030
import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
3131
import {
3232
acknowledgeComposerNativeEvent,
@@ -179,6 +179,7 @@ export function ComposerEditor({
179179
const bodyText = useScaledTextRole("body");
180180
const theme = useUniwindTheme();
181181
const fontFamily = FONT_FAMILIES.regular;
182+
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();
182183

183184
const skillLabels = useMemo(() => composerSkillLabels(skills), [skills]);
184185
const { modelsBySource, modelTokens } = useComposerModelTokens(props.value, models);
@@ -372,7 +373,7 @@ export function ComposerEditor({
372373
autoFocus={props.autoFocus ?? false}
373374
autoCorrect={props.autoCorrect ?? true}
374375
spellCheck={props.spellCheck ?? true}
375-
textPasteThresholdBytes={onPasteText ? PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES : 0}
376+
textPasteThresholdBytes={onPasteText ? pastedTextAttachmentThreshold : 0}
376377
maxInputChars={PROVIDER_SEND_TURN_MAX_INPUT_CHARS}
377378
style={style as StyleProp<ViewStyle>}
378379
onComposerChange={(event) => applyNativeChange(event.nativeEvent)}

‎apps/mobile/src/native/T3ComposerEditor.native.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES } from "@t3tools/client-runtime/text-paste";
21
import { PROVIDER_SEND_TURN_MAX_INPUT_CHARS } from "@t3tools/contracts";
32
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
43
import { composerContextEditorTokens, composerSkillLabels } from "../lib/composerContext";
@@ -29,6 +28,7 @@ import { contextChipIconUri, modelChipIcon, modelChipIconUri } from "../lib/cont
2928
import { MOBILE_TYPOGRAPHY } from "../lib/typography";
3029
import { useNativePaste } from "../lib/useNativePaste";
3130
import { FONT_FAMILIES } from "../lib/fontFamilies";
31+
import { usePastedTextAttachmentThreshold } from "../lib/usePastedTextAttachmentThreshold";
3232
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
3333
import { useUniwindTheme } from "../lib/useUniwindTheme";
3434
import { createNativeComposerTheme } from "../lib/nativeComposerTheme";
@@ -313,6 +313,7 @@ export function ComposerEditor({
313313
});
314314
const resolvedTextStyle = StyleSheet.flatten(textStyle) ?? {};
315315
const regularFontFamily = FONT_FAMILIES.regular;
316+
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();
316317
return (
317318
<TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}>
318319
<NativeView
@@ -346,7 +347,7 @@ export function ComposerEditor({
346347
spellCheck={props.spellCheck ?? true}
347348
enterBehavior={props.enterBehavior ?? DEFAULT_COMPOSER_ENTER_BEHAVIOR}
348349
submitEnabled={onSubmit !== undefined}
349-
textPasteThresholdBytes={onPasteText ? PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES : 0}
350+
textPasteThresholdBytes={onPasteText ? pastedTextAttachmentThreshold : 0}
350351
maxInputChars={PROVIDER_SEND_TURN_MAX_INPUT_CHARS}
351352
style={{ flex: 1, minHeight: 0 }}
352353
onComposerChange={(event) => {

‎apps/mobile/src/persistence/mobile-preferences.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
PullRequestInvolvement,
1111
PullRequestListFilters,
1212
PullRequestListState,
13+
PastedTextAttachmentThreshold,
1314
type ProviderInstanceId,
1415
type PullRequestMergeMethod,
1516
type SidebarProjectGroupingMode,
@@ -27,6 +28,7 @@ import { MobileStorageDecodeError, MobileStorageEncodeError } from "./mobile-sto
2728
const PREFERENCES_KEY = "t3code.preferences";
2829
const PREFERENCES_FALLBACK_KEY = "t3code.preferences.fallback";
2930
const encodeJson = Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
31+
const isPastedTextAttachmentThreshold = Schema.is(PastedTextAttachmentThreshold);
3032

3133
export const PullRequestListControls = Schema.Struct({
3234
state: PullRequestListState,
@@ -113,6 +115,7 @@ export interface Preferences {
113115
/** Hardware-keyboard Return behavior in the composer. */
114116
readonly composerEnterBehavior?: ComposerEnterBehavior;
115117
readonly followUpBehavior?: FollowUpBehavior;
118+
readonly pastedTextAttachmentThreshold?: PastedTextAttachmentThreshold;
116119
/** The client `language` setting: a locale code or "system". Unset means English. */
117120
readonly language?: string;
118121
readonly microphones?: ReadonlyArray<MicrophoneEntry>;
@@ -199,6 +202,7 @@ function sanitizePreferences(parsed: Preferences): Preferences {
199202
dismissedDatabaseStorageNotices?: readonly string[];
200203
composerEnterBehavior?: ComposerEnterBehavior;
201204
followUpBehavior?: FollowUpBehavior;
205+
pastedTextAttachmentThreshold?: PastedTextAttachmentThreshold;
202206
language?: string;
203207
microphones?: ReadonlyArray<MicrophoneEntry>;
204208
projectGroupingEnabled?: boolean;
@@ -308,6 +312,9 @@ function sanitizePreferences(parsed: Preferences): Preferences {
308312
if (parsed.followUpBehavior === "queue" || parsed.followUpBehavior === "steer") {
309313
preferences.followUpBehavior = parsed.followUpBehavior;
310314
}
315+
if (isPastedTextAttachmentThreshold(parsed.pastedTextAttachmentThreshold)) {
316+
preferences.pastedTextAttachmentThreshold = parsed.pastedTextAttachmentThreshold;
317+
}
311318
if (typeof parsed.language === "string") preferences.language = parsed.language;
312319
if (Array.isArray(parsed.microphones)) {
313320
preferences.microphones = parsed.microphones.flatMap((entry): MicrophoneEntry[] => {

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
26122612
questionAttachmentTarget,
26132613
attachmentTargetKey,
26142614
fileStagingLimit,
2615+
pastedTextAttachmentThreshold: settings.pastedTextAttachmentThreshold,
26152616
promptRef,
26162617
composerImagesRef,
26172618
composerFilesRef,

‎apps/web/src/components/chat/useComposerAttachmentIntake.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function useComposerAttachmentIntake(input: {
6767
readonly questionAttachmentTarget: DraftId | null;
6868
readonly attachmentTargetKey: string;
6969
readonly fileStagingLimit: number | null;
70+
readonly pastedTextAttachmentThreshold: number;
7071
readonly promptRef: ChatComposerProps["promptRef"];
7172
readonly composerImagesRef: ChatComposerProps["composerImagesRef"];
7273
readonly composerFilesRef: ChatComposerProps["composerFilesRef"];
@@ -94,6 +95,7 @@ export function useComposerAttachmentIntake(input: {
9495
questionAttachmentTarget,
9596
attachmentTargetKey,
9697
fileStagingLimit,
98+
pastedTextAttachmentThreshold,
9799
promptRef,
98100
composerImagesRef,
99101
composerFilesRef,
@@ -381,6 +383,7 @@ export function useComposerAttachmentIntake(input: {
381383
bypassAutoAttachment,
382384
wouldExceedInputLimit,
383385
canAttach: true,
386+
thresholdBytes: pastedTextAttachmentThreshold,
384387
}) === "attachment";
385388
if (!shouldFold) {
386389
return false;

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import {
1515
type ProviderInstanceId,
1616
type SidebarProjectGroupingMode,
1717
} from "@t3tools/contracts";
18+
import { pastedTextThresholdLabel } from "@t3tools/client-runtime/text-paste";
1819
import {
1920
DEFAULT_UNIFIED_SETTINGS,
2021
type DiffLayout,
2122
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
2223
MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
24+
PASTED_TEXT_ATTACHMENT_THRESHOLDS,
2325
type ResponseStreamingMode,
2426
type QuitConfirmationMode,
2527
SidebarProjectSortOrder,
@@ -532,6 +534,10 @@ export function useSettingsRestore(onRestored?: () => void) {
532534
? ["Rich text composer"]
533535
: []),
534536
...(settings.sendShortcut !== DEFAULT_UNIFIED_SETTINGS.sendShortcut ? ["Send shortcut"] : []),
537+
...(settings.pastedTextAttachmentThreshold !==
538+
DEFAULT_UNIFIED_SETTINGS.pastedTextAttachmentThreshold
539+
? ["Large paste threshold"]
540+
: []),
535541
...(settings.followUpBehavior !== DEFAULT_UNIFIED_SETTINGS.followUpBehavior
536542
? ["Follow-up behavior"]
537543
: []),
@@ -655,6 +661,7 @@ export function useSettingsRestore(onRestored?: () => void) {
655661
showSkillsInSlashMenu: DEFAULT_UNIFIED_SETTINGS.showSkillsInSlashMenu,
656662
composerRichTextEnabled: DEFAULT_UNIFIED_SETTINGS.composerRichTextEnabled,
657663
sendShortcut: DEFAULT_UNIFIED_SETTINGS.sendShortcut,
664+
pastedTextAttachmentThreshold: DEFAULT_UNIFIED_SETTINGS.pastedTextAttachmentThreshold,
658665
followUpBehavior: DEFAULT_UNIFIED_SETTINGS.followUpBehavior,
659666
toolCallVisibility: DEFAULT_UNIFIED_SETTINGS.toolCallVisibility,
660667
screenReaderAnnouncements: DEFAULT_UNIFIED_SETTINGS.screenReaderAnnouncements,
@@ -1214,6 +1221,57 @@ export function ChatSettingsPanel() {
12141221
</Select>
12151222
}
12161223
/>
1224+
<SettingsRow
1225+
{...searchableSetting("large-paste-threshold")}
1226+
description={`Pastes this size or larger become a text file attachment. Non-Latin text and emoji use more bytes per character, so they reach it sooner. Press ${modifierLabel} + Shift + V to paste inline instead.`}
1227+
resetAction={
1228+
settings.pastedTextAttachmentThreshold !==
1229+
DEFAULT_UNIFIED_SETTINGS.pastedTextAttachmentThreshold ? (
1230+
<SettingResetButton
1231+
label="large paste threshold"
1232+
onClick={() =>
1233+
updateSettings({
1234+
pastedTextAttachmentThreshold:
1235+
DEFAULT_UNIFIED_SETTINGS.pastedTextAttachmentThreshold,
1236+
})
1237+
}
1238+
/>
1239+
) : null
1240+
}
1241+
control={
1242+
<Select
1243+
value={String(settings.pastedTextAttachmentThreshold)}
1244+
onValueChange={(value) => {
1245+
const next = PASTED_TEXT_ATTACHMENT_THRESHOLDS.find(
1246+
(threshold) => String(threshold) === value,
1247+
);
1248+
if (next !== undefined) updateSettings({ pastedTextAttachmentThreshold: next });
1249+
}}
1250+
>
1251+
<SelectTrigger
1252+
size="sm"
1253+
className="w-auto min-w-0 max-w-full"
1254+
aria-label="Large paste threshold"
1255+
>
1256+
<SelectValue>
1257+
{pastedTextThresholdLabel(settings.pastedTextAttachmentThreshold)}
1258+
</SelectValue>
1259+
</SelectTrigger>
1260+
<SelectPopup align="end" alignItemWithTrigger={false}>
1261+
{PASTED_TEXT_ATTACHMENT_THRESHOLDS.map((threshold) => (
1262+
<SelectItem key={threshold} value={String(threshold)}>
1263+
<span className="flex items-center justify-between gap-4">
1264+
{pastedTextThresholdLabel(threshold)}
1265+
{settings.pastedTextAttachmentThreshold === threshold && (
1266+
<CheckIcon aria-hidden="true" />
1267+
)}
1268+
</span>
1269+
</SelectItem>
1270+
))}
1271+
</SelectPopup>
1272+
</Select>
1273+
}
1274+
/>
12171275
<AdvancedSettings targetIds={[searchableSetting("skills-in-slash-menu").id]}>
12181276
<SettingsRow
12191277
{...searchableSetting("skills-in-slash-menu")}

0 commit comments

Comments
 (0)