Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop/src/settings/DesktopClientSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const clientSettings: ClientSettings = {
confirmThreadDelete: false,
dismissedProviderUpdateNotificationKeys: [],
diffIgnoreWhitespace: true,
diffWordWrap: true,
favorites: [],
providerModelPreferences: {},
sidebarProjectGroupingMode: "repository_path",
Expand All @@ -29,6 +28,7 @@ const clientSettings: ClientSettings = {
sidebarThreadSortOrder: "created_at",
sidebarThreadPreviewCount: 6,
timestampFormat: "24-hour",
wordWrap: true,
};

const decodeClientSettingsJson = Schema.decodeEffect(Schema.fromJsonString(ClientSettingsSchema));
Expand Down
21 changes: 21 additions & 0 deletions apps/web/src/clientPersistenceStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,25 @@ describe("clientPersistenceStorage", () => {
}),
);
});

it("defaults word wrap on and discards obsolete wrapping preferences", async () => {
const testWindow = getTestWindow();
testWindow.localStorage.setItem(
"t3code:client-settings:v1",
JSON.stringify({
chatWordWrap: false,
diffWordWrap: false,
}),
);
const { readBrowserClientSettings } = await import("./clientPersistenceStorage");
const settings = readBrowserClientSettings();

expect(settings).toEqual(
expect.objectContaining({
wordWrap: true,
}),
);
expect(settings).not.toHaveProperty("chatWordWrap");
expect(settings).not.toHaveProperty("diffWordWrap");
});
});
6 changes: 4 additions & 2 deletions apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering";
import { fnv1a32 } from "../lib/diffRendering";
import { LRUCache } from "../lib/lruCache";
import { useTheme } from "../hooks/useTheme";
import { useClientSettings } from "../hooks/useSettings";
import {
chatMarkdownClipboardPayload,
serializeTableElementToCsv,
Expand Down Expand Up @@ -295,7 +296,7 @@ function getHighlighterPromise(language: string): Promise<DiffsHighlighter> {
function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
const containerRef = useRef<HTMLDivElement | null>(null);
const tableRef = useRef<HTMLTableElement | null>(null);
const [expanded, setExpanded] = useState(false);
const [expanded, setExpanded] = useState(useClientSettings((settings) => settings.wordWrap));
const [copied, setCopied] = useState(false);
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const expandLabel = expanded ? "Collapse table cells" : "Expand table cells";
Expand Down Expand Up @@ -525,10 +526,11 @@ function MarkdownCodeBlock({
children: ReactNode;
}) {
const [copied, setCopied] = useState(false);
const [wrapped, setWrapped] = useState(false);
const [wrapped, setWrapped] = useState(useClientSettings((settings) => settings.wordWrap));
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const wrapLabel = wrapped ? "Disable line wrap" : "Wrap lines";
const copyLabel = copied ? "Copied" : "Copy code";

const handleCopy = useCallback(() => {
if (typeof navigator === "undefined" || navigator.clipboard == null) {
return;
Expand Down
17 changes: 8 additions & 9 deletions apps/web/src/components/DiffPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,15 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff
const { resolvedTheme } = useTheme();
const settings = useClientSettings();
const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
const [diffWordWrap, setDiffWordWrap] = useState(settings.diffWordWrap);
const [wordWrap, setWordWrap] = useState(settings.wordWrap);
const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
const [baseRefQuery, setBaseRefQuery] = useState("");
const [collapsedDiffFiles, setCollapsedDiffFiles] = useState<CollapsedDiffFilesState>(() => ({
scopeKey: null,
fileKeys: EMPTY_COLLAPSED_DIFF_FILE_KEYS,
}));
const codeViewRef = useRef<AnnotatableCodeViewHandle>(null);

const routeThreadRef = useParams({
strict: false,
select: (params) => resolveThreadRouteRef(params),
Expand Down Expand Up @@ -695,22 +696,20 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff
<TooltipTrigger
render={
<Toggle
aria-label={
diffWordWrap ? "Disable diff line wrapping" : "Enable diff line wrapping"
}
aria-label={wordWrap ? "Disable diff line wrapping" : "Enable diff line wrapping"}
variant="outline"
size="xs"
pressed={diffWordWrap}
pressed={wordWrap}
onPressedChange={(pressed) => {
setDiffWordWrap(Boolean(pressed));
setWordWrap(Boolean(pressed));
}}
/>
}
>
<TextWrapIcon className="size-3" />
</TooltipTrigger>
<TooltipPopup side="top">
{diffWordWrap ? "Disable line wrapping" : "Enable line wrapping"}
{wordWrap ? "Disable line wrapping" : "Enable line wrapping"}
</TooltipPopup>
</Tooltip>
<Tooltip>
Expand Down Expand Up @@ -844,7 +843,7 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff
options={{
diffStyle: diffRenderMode === "split" ? "split" : "unified",
lineDiffType: "none",
overflow: diffWordWrap ? "wrap" : "scroll",
overflow: wordWrap ? "wrap" : "scroll",
theme: resolveDiffThemeName(resolvedTheme),
themeType: resolvedTheme as DiffThemeType,
unsafeCSS: DIFF_PANEL_UNSAFE_CSS,
Expand All @@ -860,7 +859,7 @@ export default function DiffPanel({ mode = "inline", composerDraftTarget }: Diff
<pre
className={cn(
"max-h-[72vh] rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90",
diffWordWrap
wordWrap
? "overflow-auto whitespace-pre-wrap wrap-break-word"
: "overflow-auto",
)}
Expand Down
16 changes: 13 additions & 3 deletions apps/web/src/components/files/FilePreviewPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { isBrowserPreviewFile, openFileInPreview } from "~/browser/openFileInPreview";
import ChatMarkdown from "~/components/ChatMarkdown";
import { OpenInPicker } from "~/components/chat/OpenInPicker";
import { useClientSettings } from "~/hooks/useSettings";
import { useTheme } from "~/hooks/useTheme";
import { getLocalStorageItem, setLocalStorageItem } from "~/hooks/useLocalStorage";
import { resolveDiffThemeName } from "~/lib/diffRendering";
Expand Down Expand Up @@ -248,6 +249,7 @@ interface EditableFileSurfaceProps {
contents: string;
resolvedTheme: "light" | "dark";
revealRequestId: number;
wordWrap: boolean;
onPostRender: FilePostRender;
onPendingChange: (relativePath: string, pending: boolean) => void;
}
Expand Down Expand Up @@ -296,6 +298,7 @@ function EditableFileSurface({
contents,
resolvedTheme,
revealRequestId,
wordWrap,
onPostRender,
onPendingChange,
}: EditableFileSurfaceProps) {
Expand Down Expand Up @@ -516,7 +519,7 @@ function EditableFileSurface({
onGutterUtilityClick: setSelectedRange,
onLineSelectionChange: setSelectedRange,
onLineSelectionEnd: handleLineSelectionEnd,
overflow: "scroll",
overflow: wordWrap ? "wrap" : "scroll",
theme: resolveDiffThemeName(resolvedTheme),
themeType: resolvedTheme,
unsafeCSS: FILE_LINK_REVEAL_UNSAFE_CSS,
Expand Down Expand Up @@ -557,7 +560,12 @@ function RenderedMarkdownSurface({
onPendingChange,
}: Omit<
EditableFileSurfaceProps,
"resolvedTheme" | "composerDraftTarget" | "revealLine" | "revealRequestId" | "onPostRender"
| "resolvedTheme"
| "composerDraftTarget"
| "revealLine"
| "revealRequestId"
| "wordWrap"
| "onPostRender"
> & {
threadRef: ScopedThreadRef;
}) {
Expand Down Expand Up @@ -613,6 +621,7 @@ export default function FilePreviewPanel({
onPendingChange,
}: FilePreviewPanelProps) {
const { resolvedTheme } = useTheme();
const wordWrap = useClientSettings((settings) => settings.wordWrap);
const primaryEnvironmentId = usePrimaryEnvironmentId();
const environmentHttpBaseUrl = useEnvironmentHttpBaseUrl(environmentId);
const createAssetUrl = useAtomQueryRunner(assetEnvironment.createUrl, {
Expand Down Expand Up @@ -844,7 +853,7 @@ export default function FilePreviewPanel({
}}
options={{
disableFileHeader: true,
overflow: "scroll",
overflow: wordWrap ? "wrap" : "scroll",
theme: resolveDiffThemeName(resolvedTheme),
themeType: resolvedTheme,
unsafeCSS: FILE_LINK_REVEAL_UNSAFE_CSS,
Expand All @@ -863,6 +872,7 @@ export default function FilePreviewPanel({
contents={file.data.contents}
resolvedTheme={resolvedTheme}
revealRequestId={revealRequestId}
wordWrap={wordWrap}
onPostRender={onFilePostRender}
onPendingChange={onPendingChange}
/>
Expand Down
24 changes: 11 additions & 13 deletions apps/web/src/components/settings/SettingsPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,7 @@ export function useSettingsRestore(onRestored?: () => void) {
...(settings.sidebarThreadPreviewCount !== DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount
? ["Visible threads"]
: []),
...(settings.diffWordWrap !== DEFAULT_UNIFIED_SETTINGS.diffWordWrap
? ["Diff line wrapping"]
: []),
...(settings.wordWrap !== DEFAULT_UNIFIED_SETTINGS.wordWrap ? ["Word wrap"] : []),
...(settings.diffIgnoreWhitespace !== DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace
? ["Diff whitespace changes"]
: []),
Expand Down Expand Up @@ -434,11 +432,11 @@ export function useSettingsRestore(onRestored?: () => void) {
settings.defaultThreadEnvMode,
settings.newWorktreesStartFromOrigin,
settings.diffIgnoreWhitespace,
settings.diffWordWrap,
settings.automaticGitFetchInterval,
settings.enableAssistantStreaming,
settings.sidebarThreadPreviewCount,
settings.timestampFormat,
settings.wordWrap,
theme,
],
);
Expand All @@ -456,7 +454,7 @@ export function useSettingsRestore(onRestored?: () => void) {
setTheme("system");
updateSettings({
timestampFormat: DEFAULT_UNIFIED_SETTINGS.timestampFormat,
diffWordWrap: DEFAULT_UNIFIED_SETTINGS.diffWordWrap,
wordWrap: DEFAULT_UNIFIED_SETTINGS.wordWrap,
diffIgnoreWhitespace: DEFAULT_UNIFIED_SETTINGS.diffIgnoreWhitespace,
sidebarThreadPreviewCount: DEFAULT_UNIFIED_SETTINGS.sidebarThreadPreviewCount,
autoOpenPlanSidebar: DEFAULT_UNIFIED_SETTINGS.autoOpenPlanSidebar,
Expand Down Expand Up @@ -594,25 +592,25 @@ export function GeneralSettingsPanel() {
/>

<SettingsRow
title="Diff line wrapping"
description="Set the default wrap state when the diff panel opens."
title="Word wrap"
description="Wrap long lines in code blocks, tables, diffs, and file previews by default."
resetAction={
settings.diffWordWrap !== DEFAULT_UNIFIED_SETTINGS.diffWordWrap ? (
settings.wordWrap !== DEFAULT_UNIFIED_SETTINGS.wordWrap ? (
<SettingResetButton
label="diff line wrapping"
label="word wrapping"
onClick={() =>
updateSettings({
diffWordWrap: DEFAULT_UNIFIED_SETTINGS.diffWordWrap,
wordWrap: DEFAULT_UNIFIED_SETTINGS.wordWrap,
})
}
/>
) : null
}
control={
<Switch
checked={settings.diffWordWrap}
onCheckedChange={(checked) => updateSettings({ diffWordWrap: Boolean(checked) })}
aria-label="Wrap diff lines by default"
checked={settings.wordWrap}
onCheckedChange={(checked) => updateSettings({ wordWrap: Boolean(checked) })}
aria-label="Wrap code, tables, diffs, and file previews by default"
/>
}
/>
Expand Down
27 changes: 25 additions & 2 deletions packages/contracts/src/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,35 @@ import { describe, expect, it } from "vite-plus/test";
import * as Schema from "effect/Schema";

import { ProviderInstanceId } from "./providerInstance.ts";
import { DEFAULT_SERVER_SETTINGS, ServerSettings, ServerSettingsPatch } from "./settings.ts";

import {
ClientSettingsSchema,
DEFAULT_SERVER_SETTINGS,
ServerSettings,
ServerSettingsPatch,
} from "./settings.ts";

const decodeClientSettings = Schema.decodeUnknownSync(ClientSettingsSchema);
const decodeServerSettings = Schema.decodeUnknownSync(ServerSettings);
const decodeServerSettingsPatch = Schema.decodeUnknownSync(ServerSettingsPatch);
const encodeServerSettings = Schema.encodeSync(ServerSettings);

describe("ClientSettings word wrap", () => {
it("defaults word wrap on", () => {
expect(decodeClientSettings({}).wordWrap).toBe(true);
});

it("ignores obsolete wrapping preferences", () => {
const decoded = decodeClientSettings({
chatWordWrap: false,
diffWordWrap: false,
});

expect(decoded.wordWrap).toBe(true);
expect(decoded).not.toHaveProperty("chatWordWrap");
expect(decoded).not.toHaveProperty("diffWordWrap");
});
});

describe("ServerSettings.providerInstances (slice-2 invariant)", () => {
it("defaults to an empty record so legacy configs without the key still decode", () => {
expect(DEFAULT_SERVER_SETTINGS.providerInstances).toEqual({});
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const ClientSettingsSchema = Schema.Struct({
Schema.withDecodingDefault(Effect.succeed([])),
),
diffIgnoreWhitespace: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
diffWordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
// Model favorites. Historically keyed by provider kind, now
// widened to `ProviderInstanceId` so users can favorite a specific model
// on a custom provider instance (e.g. "Codex Personal · gpt-5") without
Expand Down Expand Up @@ -92,6 +91,7 @@ export const ClientSettingsSchema = Schema.Struct({
timestampFormat: TimestampFormat.pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
),
wordWrap: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
});
export type ClientSettings = typeof ClientSettingsSchema.Type;

Expand Down Expand Up @@ -538,7 +538,6 @@ export const ClientSettingsPatch = Schema.Struct({
confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
diffIgnoreWhitespace: Schema.optionalKey(Schema.Boolean),
diffWordWrap: Schema.optionalKey(Schema.Boolean),
favorites: Schema.optionalKey(
Schema.Array(
Schema.Struct({
Expand Down Expand Up @@ -568,5 +567,6 @@ export const ClientSettingsPatch = Schema.Struct({
sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
sidebarThreadPreviewCount: Schema.optionalKey(SidebarThreadPreviewCount),
timestampFormat: Schema.optionalKey(TimestampFormat),
wordWrap: Schema.optionalKey(Schema.Boolean),
});
export type ClientSettingsPatch = typeof ClientSettingsPatch.Type;
Loading