Skip to content

Commit 52452b1

Browse files
feat(mobile): expose word wrap in pull request guides and diffs
1 parent 58ac5a0 commit 52452b1

4 files changed

Lines changed: 106 additions & 20 deletions

File tree

‎apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ export function PullRequestFileRouteScreen({
755755
}
756756
}, [filter.hideTestFiles, result.parsed]);
757757
const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
758-
const { themeAppearance } = useAppearancePreferences();
758+
const { themeAppearance, appearance, setCodeWordBreak } = useAppearancePreferences();
759759
const bridge = useNativeReviewDiffBridge({
760760
threadKey: null,
761761
sectionId: `pull-request:${route.params.repository}:${route.params.number}:${commit ?? "all"}`,
@@ -840,6 +840,12 @@ export function PullRequestFileRouteScreen({
840840
trailing={
841841
<ControlPillMenu
842842
actions={[
843+
{
844+
id: "word-wrap",
845+
title: "Word wrap",
846+
image: "text.alignleft",
847+
state: appearance.codeWordBreak ? "on" : "off",
848+
},
843849
{
844850
id: "hide-tests",
845851
title: "Hide test files",
@@ -860,7 +866,8 @@ export function PullRequestFileRouteScreen({
860866
: []),
861867
]}
862868
onPressAction={({ nativeEvent }) => {
863-
if (nativeEvent.event === "hide-tests") toggleTestFiles();
869+
if (nativeEvent.event === "word-wrap") setCodeWordBreak(!appearance.codeWordBreak);
870+
else if (nativeEvent.event === "hide-tests") toggleTestFiles();
864871
else if (
865872
nativeEvent.event === "submit-review" ||
866873
nativeEvent.event === "comment-on-pr"
@@ -906,6 +913,13 @@ export function PullRequestFileRouteScreen({
906913
<NativeHeaderToolbar.Label>Add comment</NativeHeaderToolbar.Label>
907914
</NativeHeaderToolbar.MenuAction>
908915
) : null}
916+
<NativeHeaderToolbar.MenuAction
917+
icon="text.alignleft"
918+
isOn={appearance.codeWordBreak}
919+
onPress={() => setCodeWordBreak(!appearance.codeWordBreak)}
920+
>
921+
<NativeHeaderToolbar.Label>Word wrap</NativeHeaderToolbar.Label>
922+
</NativeHeaderToolbar.MenuAction>
909923
<NativeHeaderToolbar.MenuAction
910924
icon="line.3.horizontal.decrease"
911925
isOn={filter.hideTestFiles}

‎apps/mobile/src/features/pull-requests/guide/GuideOutline.tsx‎

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { SymbolView } from "../../../components/AppSymbol";
66
import { PullRequestMarkdown } from "../PullRequestMarkdown";
77
import { ControlPillMenu } from "../../../components/ControlPillMenu";
88

9+
import { useAppearancePreferences } from "../../settings/appearance/AppearancePreferencesProvider";
10+
911
/** The stops are a reading sequence, with file context kept beside each idea. */
1012
export function GuideOutline({
1113
guide,
@@ -16,6 +18,7 @@ export function GuideOutline({
1618
readonly onOpen: (position: number) => void;
1719
readonly onRewrite?: () => void;
1820
}) {
21+
const { appearance, setCodeWordBreak } = useAppearancePreferences();
1922
const files = new Set(guide.stops.flatMap(stopFilePaths));
2023
return (
2124
<View>
@@ -26,21 +29,33 @@ export function GuideOutline({
2629
through {files.size} {files.size === 1 ? "file" : "files"}
2730
</Text>
2831
</View>
29-
{onRewrite ? (
30-
<ControlPillMenu
31-
title="Guide options"
32-
actions={[{ id: "rewrite", title: "Rewrite guide", image: "arrow.clockwise" }]}
33-
onPressAction={() => onRewrite()}
32+
<ControlPillMenu
33+
title="Guide options"
34+
actions={[
35+
{
36+
id: "word-wrap",
37+
title: "Word wrap",
38+
image: "text.alignleft",
39+
state: appearance.codeWordBreak ? "on" : "off",
40+
},
41+
...(onRewrite
42+
? [{ id: "rewrite", title: "Rewrite guide", image: "arrow.clockwise" }]
43+
: []),
44+
]}
45+
onPressAction={({ nativeEvent }) =>
46+
nativeEvent.event === "word-wrap"
47+
? setCodeWordBreak(!appearance.codeWordBreak)
48+
: onRewrite?.()
49+
}
50+
>
51+
<Pressable
52+
accessibilityRole="button"
53+
accessibilityLabel="Guide options"
54+
className="h-11 w-11 items-center justify-center rounded-full active:bg-grouped-card"
3455
>
35-
<Pressable
36-
accessibilityRole="button"
37-
accessibilityLabel="Guide options"
38-
className="h-11 w-11 items-center justify-center rounded-full active:bg-grouped-card"
39-
>
40-
<SymbolView name="ellipsis" size={20} tintColorClassName="accent-icon-muted" />
41-
</Pressable>
42-
</ControlPillMenu>
43-
) : null}
56+
<SymbolView name="ellipsis" size={20} tintColorClassName="accent-icon-muted" />
57+
</Pressable>
58+
</ControlPillMenu>
4459
</View>
4560
{guide.stops[0]?.summary ? (
4661
<View className="mb-6">

‎apps/mobile/src/features/pull-requests/guide/PullRequestGuideScreen.tsx‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { GuideOutline } from "./GuideOutline";
1515
import { AppText as Text } from "../../../components/AppText";
1616
import { MaterialButton } from "../../../components/MaterialButton";
1717
import { ScreenScrollView } from "../../../components/ScreenScrollView";
18-
import { NativeStackScreenOptions } from "../../../native/StackHeader";
18+
import { ControlPillMenu } from "../../../components/ControlPillMenu";
19+
import { MaterialIconButton } from "../../../components/MaterialIconButton";
20+
import { useAppearancePreferences } from "../../settings/appearance/AppearancePreferencesProvider";
21+
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../../native/StackHeader";
1922
import { PullRequestCardGroup, PullRequestCardRow } from "../PullRequestControls";
2023
import { PullRequestMarkdown, PullRequestMarkdownRepository } from "../PullRequestMarkdown";
2124
import { usePullRequestDiff, type PullRequestParams } from "../usePullRequestDiff";
@@ -188,6 +191,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
188191
guide !== null &&
189192
(guide.headSha !== route.params.guideHeadSha ||
190193
guide.generatedAt !== route.params.guideGeneratedAt);
194+
const { appearance, setCodeWordBreak } = useAppearancePreferences();
191195
const notes = stop ? letterStopNotes(stop).lettered : [];
192196
return (
193197
<View className="flex-1 bg-screen">
@@ -201,8 +205,40 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
201205
<AndroidScreenHeader
202206
title={`Stop ${route.params.position + 1}`}
203207
onBack={() => navigation.goBack()}
208+
trailing={
209+
<ControlPillMenu
210+
actions={[
211+
{
212+
id: "word-wrap",
213+
title: "Word wrap",
214+
image: "text.alignleft",
215+
state: appearance.codeWordBreak ? "on" : "off",
216+
},
217+
]}
218+
onPressAction={() => setCodeWordBreak(!appearance.codeWordBreak)}
219+
>
220+
<View pointerEvents="none">
221+
<MaterialIconButton icon="ellipsis" accessibilityLabel="Guide options" />
222+
</View>
223+
</ControlPillMenu>
224+
}
204225
/>
205226
) : null}
227+
<NativeHeaderToolbar placement="right">
228+
<NativeHeaderToolbar.Menu
229+
title="Guide options"
230+
accessibilityLabel="Guide options"
231+
icon="ellipsis"
232+
>
233+
<NativeHeaderToolbar.MenuAction
234+
icon="text.alignleft"
235+
isOn={appearance.codeWordBreak}
236+
onPress={() => setCodeWordBreak(!appearance.codeWordBreak)}
237+
>
238+
<NativeHeaderToolbar.Label>Word wrap</NativeHeaderToolbar.Label>
239+
</NativeHeaderToolbar.MenuAction>
240+
</NativeHeaderToolbar.Menu>
241+
</NativeHeaderToolbar>
206242
<PullRequestMarkdownRepository
207243
value={`https://${route.params.host ?? "github.com"}/${route.params.repository}`}
208244
>

‎apps/mobile/src/features/pull-requests/guide/ReviewGuideExcerpt.tsx‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function ReviewGuideExcerpt({
2626
readonly loading: boolean;
2727
readonly onOpen: () => void;
2828
}) {
29-
const { nativeReviewDiffStyle } = useAppearanceCodeSurface();
29+
const { nativeReviewDiffStyle, codeWordBreak } = useAppearanceCodeSurface();
3030
const { themeAppearance } = useAppearancePreferences();
3131
const slice = useMemo(() => {
3232
try {
@@ -60,6 +60,10 @@ export function ReviewGuideExcerpt({
6060
selectedRowIds: EMPTY_IDS,
6161
canHighlight: true,
6262
});
63+
const [measuredHeight, setMeasuredHeight] = useState<{ key: string; height: number } | null>(
64+
null,
65+
);
66+
const measurementKey = `${slice}:${codeWordBreak}:${nativeReviewDiffStyle.rowHeight}`;
6367
const [NativeDiff] = useState(() => resolveNativeReviewDiffView());
6468
return (
6569
<View className="gap-3">
@@ -85,7 +89,14 @@ export function ReviewGuideExcerpt({
8589
</Pressable>
8690
{NativeDiff && data.rows.length ? (
8791
<View
88-
style={{ height: Math.min(360, data.rows.length * nativeReviewDiffStyle.rowHeight) }}
92+
style={{
93+
height: Math.min(
94+
360,
95+
measuredHeight?.key === measurementKey
96+
? measuredHeight.height
97+
: data.rows.length * nativeReviewDiffStyle.rowHeight,
98+
),
99+
}}
89100
>
90101
<NativeDiff
91102
appearanceScheme={themeAppearance}
@@ -97,7 +108,17 @@ export function ReviewGuideExcerpt({
97108
styleJson={bridge.styleJson}
98109
tokensPatchJson={bridge.tokensPatchJson}
99110
tokensResetKey={bridge.tokensResetKey}
100-
onDebug={bridge.onDebug}
111+
onDebug={(event) => {
112+
bridge.onDebug(event);
113+
const { message, contentHeight } = event.nativeEvent;
114+
if (message === "metrics" && typeof contentHeight === "number") {
115+
setMeasuredHeight((current) =>
116+
current?.key === measurementKey && current.height === contentHeight
117+
? current
118+
: { key: measurementKey, height: contentHeight },
119+
);
120+
}
121+
}}
101122
onPressLine={onOpen}
102123
/>
103124
</View>

0 commit comments

Comments
 (0)