Skip to content

Commit 9d7b476

Browse files
danddanddandclaude
andcommitted
feat(composer): choose when large pastes become text attachments
Pastes fold into a text-file attachment only at 32 KiB, so long logs and code blocks still flood the composer. Add a client setting with three presets (1 KB, 5 KB, and 32 KB, the default) on web, desktop, and mobile. The shared paste disposition and the native editors now 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 Opus 5.5 <[email protected]>
1 parent 1eb4071 commit 9d7b476

20 files changed

Lines changed: 475 additions & 15 deletions

‎apps/mobile/src/Stack.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { SettingsAuthRouteScreen } from "./features/settings/SettingsAuthRouteSc
9494
import { SettingsEnvironmentDetailRouteScreen } from "./features/settings/SettingsEnvironmentDetailRouteScreen";
9595
import { SettingsEnvironmentsRouteScreen } from "./features/settings/SettingsEnvironmentsRouteScreen";
9696
import { SettingsFollowUpRouteScreen } from "./features/settings/SettingsFollowUpRouteScreen";
97+
import { SettingsLargePastesRouteScreen } from "./features/settings/SettingsLargePastesRouteScreen";
9798
import {
9899
SettingsEnvironmentAgentBehaviorRouteScreen,
99100
SettingsEnvironmentMaintenanceRouteScreen,
@@ -375,6 +376,14 @@ const SETTINGS_SCREENS = {
375376
title: "Follow-ups",
376377
},
377378
}),
379+
SettingsLargePastes: createNativeStackScreen({
380+
screen: SettingsLargePastesRouteScreen,
381+
linking: "settings/large-pastes",
382+
options: {
383+
...SETTINGS_PAGE_OPTIONS,
384+
title: "Large pastes",
385+
},
386+
}),
378387
SettingsScheduledTasks: createNativeStackScreen({
379388
screen: SettingsScheduledTasksRouteScreen,
380389
linking: "settings/scheduled-tasks",
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2+
import { useAtomSet, useAtomValue } from "@effect/atom-react";
3+
import { useNavigation } from "@react-navigation/native";
4+
import { pastedTextThresholdLabel } from "@t3tools/client-runtime/text-paste";
5+
import {
6+
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD,
7+
type PastedTextAttachmentThreshold,
8+
} from "@t3tools/contracts";
9+
import { AsyncResult } from "effect/reactivity";
10+
import { Platform, View } from "react-native";
11+
import { useSafeAreaInsets } from "react-native-safe-area-context";
12+
13+
import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
14+
import { AppText as Text } from "../../components/ui/AppText";
15+
import { NativeStackScreenOptions } from "../../native/StackHeader";
16+
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
17+
import { SettingsChoiceRow } from "./components/SettingsChoiceRow";
18+
import { SettingsSection } from "./components/SettingsSection";
19+
20+
const THRESHOLD_OPTIONS: ReadonlyArray<{
21+
readonly threshold: PastedTextAttachmentThreshold;
22+
readonly description: string;
23+
}> = [
24+
{ threshold: 1_000, description: "Most logs, stack traces, and code snippets become files." },
25+
{ threshold: 5_000, description: "Long logs and documents become files; snippets stay as text." },
26+
{ threshold: 32_768, description: "Default. Only very large pastes become files." },
27+
];
28+
29+
const PASTE_AS_TEXT_SHORTCUT = Platform.OS === "ios" ? "Command + Shift + V" : "Ctrl + Shift + V";
30+
31+
export function SettingsLargePastesRouteScreen() {
32+
const navigation = useNavigation();
33+
const insets = useSafeAreaInsets();
34+
const preferencesResult = useAtomValue(mobilePreferencesAtom);
35+
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
36+
const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
37+
const selectedThreshold = AsyncResult.isSuccess(preferencesResult)
38+
? (preferencesResult.value.pastedTextAttachmentThreshold ??
39+
DEFAULT_PASTED_TEXT_ATTACHMENT_THRESHOLD)
40+
: null;
41+
42+
return (
43+
<View collapsable={false} className="flex-1 bg-sheet">
44+
{Platform.OS === "android" ? (
45+
<>
46+
<NativeStackScreenOptions options={{ headerShown: false }} />
47+
<AndroidScreenHeader title="Large pastes" onBack={() => navigation.goBack()} />
48+
</>
49+
) : null}
50+
<ScrollView
51+
contentInsetAdjustmentBehavior="automatic"
52+
showsVerticalScrollIndicator={false}
53+
className="flex-1"
54+
contentContainerClassName="gap-3 px-5 pt-4"
55+
contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
56+
>
57+
<SettingsSection title="Attach pastes as files from">
58+
{THRESHOLD_OPTIONS.map(({ threshold, description }, index) => (
59+
<SettingsChoiceRow
60+
key={threshold}
61+
label={pastedTextThresholdLabel(threshold)}
62+
description={description}
63+
selected={selectedThreshold === threshold}
64+
separated={index > 0}
65+
disabled={!preferencesReady}
66+
onPress={() => savePreferences({ pastedTextAttachmentThreshold: threshold })}
67+
/>
68+
))}
69+
</SettingsSection>
70+
<Text className="px-2 text-sm text-foreground-muted">
71+
Sizes count bytes, so non-Latin text and emoji become files with fewer characters. Shorter
72+
pastes go into the message as text. With a hardware keyboard, press{" "}
73+
{PASTE_AS_TEXT_SHORTCUT} to paste a long block as text instead.
74+
</Text>
75+
</ScrollView>
76+
</View>
77+
);
78+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ function useSettingsIndexSections(): SettingsListSection[] {
258258
page("SettingsOrganization", "folder", "Organization"),
259259
page("SettingsThreads", "text.bubble", "Thread behavior"),
260260
page("SettingsFollowUp", "arrow.turn.left.up", "Follow-ups"),
261+
page("SettingsLargePastes", "doc.text", "Large pastes"),
261262
page("SettingsArchive", "archivebox", "Archived Threads"),
262263
],
263264
},

‎apps/mobile/src/features/settings/components/settings-page-targets.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const SETTINGS_PAGE_TARGETS = [
1717
"SettingsKeyboard",
1818
"SettingsMicrophone",
1919
"SettingsFollowUp",
20+
"SettingsLargePastes",
2021
"SettingsScheduledTasks",
2122
"SettingsProjectGrouping",
2223
"SettingsClientStorage",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const SETTINGS_SEARCH_TERMS = {
4343
"working section",
4444
],
4545
SettingsFollowUp: ["queue", "steer", "while the agent is running"],
46+
SettingsLargePastes: ["paste", "attachment", "text file", "threshold"],
4647
SettingsArchive: ["archive", "archived", "restore", "unarchive"],
4748
SettingsProviderAccounts: ["codex", "claude", "cursor", "opencode", "sign in", "login", "auth"],
4849
SettingsEnvironmentNewThreads: [

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import Animated, {
4949
withTiming,
5050
} from "react-native-reanimated";
5151
import { useUniwindTheme } from "../../lib/useUniwindTheme";
52+
import { usePastedTextAttachmentThreshold } from "../../lib/usePastedTextAttachmentThreshold";
5253
import { themeColorWithAlpha } from "../../lib/mobileTheme";
5354
import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/remoteRegistration";
5455
import { scopedThreadKey } from "../../lib/scopedEntities";
@@ -446,6 +447,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
446447
const navigation = useNavigation();
447448
const foregroundColor = useUniwindTheme()["--color-foreground"];
448449
const bodyText = useScaledTextRole("body");
450+
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();
449451
const fallbackInputRef = useRef<ComposerEditorHandle>(null);
450452
const inputRef = props.editorRef ?? fallbackInputRef;
451453
const [isFocused, setIsFocused] = useState(false);
@@ -1122,6 +1124,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
11221124
text: paste.text,
11231125
wouldExceedInputLimit,
11241126
canAttach: true,
1127+
thresholdBytes: pastedTextAttachmentThreshold,
11251128
}) === "attachment"
11261129
) {
11271130
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";
@@ -26,6 +25,7 @@ import { contextChipIconUri } from "../lib/contextChipIconSource";
2625
import { useUniwindTheme } from "../lib/useUniwindTheme";
2726
import { createNativeComposerTheme } from "../lib/nativeComposerTheme";
2827
import { FONT_FAMILIES } from "../lib/fontFamilies";
28+
import { usePastedTextAttachmentThreshold } from "../lib/usePastedTextAttachmentThreshold";
2929
import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole";
3030
import {
3131
acknowledgeComposerNativeEvent,
@@ -143,6 +143,7 @@ export function ComposerEditor({
143143
const bodyText = useScaledTextRole("body");
144144
const theme = useUniwindTheme();
145145
const fontFamily = FONT_FAMILIES.regular;
146+
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();
146147

147148
useImperativeHandle(
148149
ref,
@@ -288,7 +289,7 @@ export function ComposerEditor({
288289
autoFocus={props.autoFocus ?? false}
289290
autoCorrect={props.autoCorrect ?? true}
290291
spellCheck={props.spellCheck ?? true}
291-
textPasteThresholdBytes={onPasteText ? PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES : 0}
292+
textPasteThresholdBytes={onPasteText ? pastedTextAttachmentThreshold : 0}
292293
maxInputChars={PROVIDER_SEND_TURN_MAX_INPUT_CHARS}
293294
style={style as StyleProp<ViewStyle>}
294295
onComposerChange={(event) => {

‎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";
@@ -27,6 +26,7 @@ import { contextChipIconUri } from "../lib/contextChipIconSource";
2726
import { MOBILE_TYPOGRAPHY } from "../lib/typography";
2827
import { useNativePaste } from "../lib/useNativePaste";
2928
import { FONT_FAMILIES } from "../lib/fontFamilies";
29+
import { usePastedTextAttachmentThreshold } from "../lib/usePastedTextAttachmentThreshold";
3030
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
3131
import { useUniwindTheme } from "../lib/useUniwindTheme";
3232
import { createNativeComposerTheme } from "../lib/nativeComposerTheme";
@@ -261,6 +261,7 @@ export function ComposerEditor({
261261
});
262262
const resolvedTextStyle = StyleSheet.flatten(textStyle) ?? {};
263263
const regularFontFamily = FONT_FAMILIES.regular;
264+
const pastedTextAttachmentThreshold = usePastedTextAttachmentThreshold();
264265
return (
265266
<TextInputWrapper onPaste={handlePaste} style={[{ minHeight: 0 }, style]}>
266267
<NativeView
@@ -292,7 +293,7 @@ export function ComposerEditor({
292293
autoFocus={props.autoFocus ?? false}
293294
autoCorrect={props.autoCorrect ?? true}
294295
spellCheck={props.spellCheck ?? true}
295-
textPasteThresholdBytes={onPasteText ? PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES : 0}
296+
textPasteThresholdBytes={onPasteText ? pastedTextAttachmentThreshold : 0}
296297
maxInputChars={PROVIDER_SEND_TURN_MAX_INPUT_CHARS}
297298
style={{ flex: 1, minHeight: 0 }}
298299
onComposerChange={(event) => {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
PullRequestInvolvement,
1111
PullRequestListFilters,
1212
PullRequestListState,
13+
PASTED_TEXT_ATTACHMENT_THRESHOLDS,
14+
type PastedTextAttachmentThreshold,
1315
type ProviderInstanceId,
1416
type PullRequestMergeMethod,
1517
type SidebarProjectGroupingMode,
@@ -102,6 +104,7 @@ export interface Preferences {
102104
/** Hardware Return behavior is iOS-only. */
103105
readonly composerEnterBehavior?: ComposerEnterBehavior;
104106
readonly followUpBehavior?: FollowUpBehavior;
107+
readonly pastedTextAttachmentThreshold?: PastedTextAttachmentThreshold;
105108
readonly microphones?: ReadonlyArray<MicrophoneEntry>;
106109
readonly projectGroupingEnabled?: boolean;
107110
readonly projectGroupingMode?: SidebarProjectGroupingMode;
@@ -178,6 +181,7 @@ function sanitizePreferences(parsed: Preferences): Preferences {
178181
dismissedDatabaseStorageNotices?: readonly string[];
179182
composerEnterBehavior?: ComposerEnterBehavior;
180183
followUpBehavior?: FollowUpBehavior;
184+
pastedTextAttachmentThreshold?: PastedTextAttachmentThreshold;
181185
microphones?: ReadonlyArray<MicrophoneEntry>;
182186
projectGroupingEnabled?: boolean;
183187
projectGroupingMode?: SidebarProjectGroupingMode;
@@ -278,6 +282,14 @@ function sanitizePreferences(parsed: Preferences): Preferences {
278282
if (parsed.followUpBehavior === "queue" || parsed.followUpBehavior === "steer") {
279283
preferences.followUpBehavior = parsed.followUpBehavior;
280284
}
285+
if (
286+
typeof parsed.pastedTextAttachmentThreshold === "number" &&
287+
(PASTED_TEXT_ATTACHMENT_THRESHOLDS as readonly number[]).includes(
288+
parsed.pastedTextAttachmentThreshold,
289+
)
290+
) {
291+
preferences.pastedTextAttachmentThreshold = parsed.pastedTextAttachmentThreshold;
292+
}
281293
if (Array.isArray(parsed.microphones)) {
282294
preferences.microphones = parsed.microphones.flatMap((entry): MicrophoneEntry[] => {
283295
if (typeof entry !== "object" || entry === null || !isMicrophoneKind(entry.kind)) return [];

0 commit comments

Comments
 (0)