Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

feat: add word wrapping setting and in-panel button (#1326)

Raphael Lüthyd4a7e1ac0b03
diff --git a/apps/web/src/appSettings.ts b/apps/web/src/appSettings.ts
index 99a62f663..cb7b5fd9c 100644
--- a/apps/web/src/appSettings.ts
+++ b/apps/web/src/appSettings.ts
@@ -56,6 +56,7 @@ export const AppSettingsSchema = Schema.Struct({
codexHomePath: Schema.String.check(Schema.isMaxLength(4096)).pipe(withDefaults(() => "")),
defaultThreadEnvMode: EnvMode.pipe(withDefaults(() => "local" as const satisfies EnvMode)),
confirmThreadDelete: Schema.Boolean.pipe(withDefaults(() => true)),
+ diffWordWrap: Schema.Boolean.pipe(withDefaults(() => false)),
enableAssistantStreaming: Schema.Boolean.pipe(withDefaults(() => false)),
timestampFormat: TimestampFormat.pipe(withDefaults(() => DEFAULT_TIMESTAMP_FORMAT)),
customCodexModels: Schema.Array(Schema.String).pipe(withDefaults(() => [])),
diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsx
index 34ad78881..96e021987 100644
--- a/apps/web/src/components/DiffPanel.tsx
+++ b/apps/web/src/components/DiffPanel.tsx
@@ -3,7 +3,13 @@ import { FileDiff, type FileDiffMetadata, Virtualizer } from "@pierre/diffs/reac
import { useQuery } from "@tanstack/react-query";
import { useNavigate, useParams, useSearch } from "@tanstack/react-router";
import { ThreadId, type TurnId } from "@t3tools/contracts";
-import { ChevronLeftIcon, ChevronRightIcon, Columns2Icon, Rows3Icon } from "lucide-react";
+import {
+ ChevronLeftIcon,
+ ChevronRightIcon,
+ Columns2Icon,
+ Rows3Icon,
+ TextWrapIcon,
+} from "lucide-react";
import {
type WheelEvent as ReactWheelEvent,
useCallback,
@@ -162,8 +168,10 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
const { resolvedTheme } = useTheme();
const { settings } = useAppSettings();
const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
+ const [diffWordWrap, setDiffWordWrap] = useState(settings.diffWordWrap);
const patchViewportRef = useRef<HTMLDivElement>(null);
const turnStripRef = useRef<HTMLDivElement>(null);
+ const previousDiffOpenRef = useRef(false);
const [canScrollTurnStripLeft, setCanScrollTurnStripLeft] = useState(false);
const [canScrollTurnStripRight, setCanScrollTurnStripRight] = useState(false);
const routeThreadId = useParams({
@@ -171,6 +179,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
select: (params) => (params.threadId ? ThreadId.makeUnsafe(params.threadId) : null),
});
const diffSearch = useSearch({ strict: false, select: (search) => parseDiffRouteSearch(search) });
+ const diffOpen = diffSearch.diff === "1";
const activeThreadId = routeThreadId;
const activeThread = useStore((store) =>
activeThreadId ? store.threads.find((thread) => thread.id === activeThreadId) : undefined,
@@ -293,6 +302,13 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
);
}, [renderablePatch]);
+ useEffect(() => {
+ if (diffOpen && !previousDiffOpenRef.current) {
+ setDiffWordWrap(settings.diffWordWrap);
+ }
+ previousDiffOpenRef.current = diffOpen;
+ }, [diffOpen, settings.diffWordWrap]);
+
useEffect(() => {
if (!selectedFilePath || !patchViewportRef.current) {
return;
@@ -490,25 +506,39 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
))}
</div>
</div>
- <ToggleGroup
- className="shrink-0 [-webkit-app-region:no-drag]"
- variant="outline"
- size="xs"
- value={[diffRenderMode]}
- onValueChange={(value) => {
- const next = value[0];
- if (next === "stacked" || next === "split") {
- setDiffRenderMode(next);
- }
- }}
- >
- <Toggle aria-label="Stacked diff view" value="stacked">
- <Rows3Icon className="size-3" />
- </Toggle>
- <Toggle aria-label="Split diff view" value="split">
- <Columns2Icon className="size-3" />
+ <div className="flex shrink-0 items-center gap-1 [-webkit-app-region:no-drag]">
+ <ToggleGroup
+ className="shrink-0"
+ variant="outline"
+ size="xs"
+ value={[diffRenderMode]}
+ onValueChange={(value) => {
+ const next = value[0];
+ if (next === "stacked" || next === "split") {
+ setDiffRenderMode(next);
+ }
+ }}
+ >
+ <Toggle aria-label="Stacked diff view" value="stacked">
+ <Rows3Icon className="size-3" />
+ </Toggle>
+ <Toggle aria-label="Split diff view" value="split">
+ <Columns2Icon className="size-3" />
+ </Toggle>
+ </ToggleGroup>
+ <Toggle
+ aria-label={diffWordWrap ? "Disable diff line wrapping" : "Enable diff line wrapping"}
+ title={diffWordWrap ? "Disable line wrapping" : "Enable line wrapping"}
+ variant="outline"
+ size="xs"
+ pressed={diffWordWrap}
+ onPressedChange={(pressed) => {
+ setDiffWordWrap(Boolean(pressed));
+ }}
+ >
+ <TextWrapIcon className="size-3" />
</Toggle>
- </ToggleGroup>
+ </div>
</>
);
@@ -582,6 +612,7 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
options={{
diffStyle: diffRenderMode === "split" ? "split" : "unified",
lineDiffType: "none",
+ overflow: diffWordWrap ? "wrap" : "scroll",
theme: resolveDiffThemeName(resolvedTheme),
themeType: resolvedTheme as DiffThemeType,
unsafeCSS: DIFF_PANEL_UNSAFE_CSS,
@@ -595,7 +626,14 @@ export default function DiffPanel({ mode = "inline" }: DiffPanelProps) {
<div className="h-full overflow-auto p-2">
<div className="space-y-2">
<p className="text-[11px] text-muted-foreground/75">{renderablePatch.reason}</p>
- <pre className="max-h-[72vh] overflow-auto rounded-md border border-border/70 bg-background/70 p-3 font-mono text-[11px] leading-relaxed text-muted-foreground/90">
+ <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
+ ? "overflow-auto whitespace-pre-wrap wrap-break-word"
+ : "overflow-auto",
+ )}
+ >
{renderablePatch.text}
</pre>
</div>
diff --git a/apps/web/src/routes/_chat.settings.tsx b/apps/web/src/routes/_chat.settings.tsx
index 0fbff1cda..05fd640d0 100644
--- a/apps/web/src/routes/_chat.settings.tsx
+++ b/apps/web/src/routes/_chat.settings.tsx
@@ -252,6 +252,7 @@ function SettingsRouteView() {
const changedSettingLabels = [
...(theme !== "system" ? ["Theme"] : []),
...(settings.timestampFormat !== defaults.timestampFormat ? ["Time format"] : []),
+ ...(settings.diffWordWrap !== defaults.diffWordWrap ? ["Diff line wrapping"] : []),
...(settings.enableAssistantStreaming !== defaults.enableAssistantStreaming
? ["Assistant output"]
: []),
@@ -500,6 +501,34 @@ function SettingsRouteView() {
}
/>
+ <SettingsRow
+ title="Diff line wrapping"
+ description="Set the default wrap state when the diff panel opens. The in-panel wrap toggle only affects the current diff session."
+ resetAction={
+ settings.diffWordWrap !== defaults.diffWordWrap ? (
+ <SettingResetButton
+ label="diff line wrapping"
+ onClick={() =>
+ updateSettings({
+ diffWordWrap: defaults.diffWordWrap,
+ })
+ }
+ />
+ ) : null
+ }
+ control={
+ <Switch
+ checked={settings.diffWordWrap}
+ onCheckedChange={(checked) =>
+ updateSettings({
+ diffWordWrap: Boolean(checked),
+ })
+ }
+ aria-label="Wrap diff lines by default"
+ />
+ }
+ />
+
<SettingsRow
title="Assistant output"
description="Show token-by-token output while a response is in progress."