Skip to content

Commit 6ef99e5

Browse files
shivamhwpclaude
andcommitted
fix(mobile): Android file viewer can select text across lines
Each numbered source row on Android is its own text view, so a selection could not extend past one line. The File actions menu now has a "Select text" action for loaded source files that swaps in the existing continuous selectable renderer, and "Done selecting text" returns to the numbered viewer and re-runs the jump to the linked line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3470164 commit 6ef99e5

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎apps/mobile/src/features/files/SourceFileSurface.tsx‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,18 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
248248
<RefreshControl refreshing={isPullRefreshing} onRefresh={() => void handlePullToRefresh()} />
249249
) : undefined;
250250

251+
const usesLineList = !props.selectable;
252+
251253
// Layout effect so a pending jump is cancelled in the commit that swaps the file.
252254
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- scrolls the FlatList to the target line and cancels a pending jump when the file changes
253255
useLayoutEffect(() => {
254-
if (targetIndex === null) {
256+
if (targetIndex === null || !usesLineList) {
255257
return;
256258
}
257259
lineScroll.scrollToLine(listRef.current, targetIndex);
258260
return lineScroll.cancel;
259-
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Opening another file at the same line index scrolls the new file to it.
260-
}, [lineScroll, props.path, targetIndex]);
261+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- Opening another file at the same line index, or leaving selection mode, scrolls the remounted list to it.
262+
}, [lineScroll, props.path, targetIndex, usesLineList]);
261263

262264
const renderLine = ({ item, index }: { item: string; index: number }) => (
263265
<HighlightedSourceLine
@@ -353,7 +355,6 @@ function JavaScriptSourceFileSurface(props: SourceFileSurfaceProps) {
353355
/>
354356
);
355357

356-
const usesLineList = !props.selectable;
357358
const padded = (
358359
<ScrollView
359360
refreshControl={refreshControl}

‎apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ function FileContent(props: {
227227
readonly threadId: ThreadId | null;
228228
readonly initialLine: number | null;
229229
readonly truncated: boolean;
230+
readonly selectable: boolean;
230231
readonly onRefresh?: () => Promise<void> | void;
231232
}) {
232233
// Reopening a mutable host file must not reuse a poster from an earlier visit.
@@ -329,6 +330,7 @@ function FileContent(props: {
329330
path={props.relativePath}
330331
initialLine={props.initialLine}
331332
headerInsetTop={props.truncated ? 0 : undefined}
333+
selectable={props.selectable}
332334
onRefresh={props.onRefresh}
333335
/>
334336
)}
@@ -719,6 +721,13 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
719721
: null,
720722
);
721723
const fileData = fileQuery.data as ProjectReadFileResult | null;
724+
// Android numbered rows are separate text views, so selection spanning lines needs the
725+
// continuous renderer. It stays opt-in because it lays out the whole file at once.
726+
const selectionScope = JSON.stringify([environmentId, cwd, relativePath]);
727+
const [textSelectionScope, setTextSelectionScope] = useState<string | null>(null);
728+
const canSelectText =
729+
Platform.OS === "android" && resolvedActiveMode === "source" && fileData?.contents != null;
730+
const selectingText = canSelectText && textSelectionScope === selectionScope;
722731

723732
const handleSelectFile = (path: string) => {
724733
const targetPath =
@@ -807,6 +816,15 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
807816
onPress: () => setCodeWordBreak(!appearance.codeWordBreak),
808817
} as const)
809818
: null,
819+
canSelectText
820+
? ({
821+
id: "select-text",
822+
title: selectingText ? "Done selecting text" : "Select text",
823+
icon: selectingText ? "checkmark" : "doc.text",
824+
inline: false,
825+
onPress: () => setTextSelectionScope(selectingText ? null : selectionScope),
826+
} as const)
827+
: null,
810828
...(mediaSource
811829
? mediaActions.actions
812830
.filter(({ id }) => id !== "open-file")
@@ -1003,6 +1021,7 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
10031021
relativePath={relativePath}
10041022
threadId={threadId}
10051023
truncated={fileData?.truncated ?? false}
1024+
selectable={selectingText}
10061025
onRefresh={() => fileQuery.refresh()}
10071026
/>
10081027
</ScreenContent>

0 commit comments

Comments
 (0)