Skip to content

Commit 8e31712

Browse files
committed
Merge origin/main into feature/vcs-specific-terminology
2 parents 449c13d + 0d809db commit 8e31712

137 files changed

Lines changed: 4082 additions & 436 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,10 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
286286
onInput(mapOf("data" to "\r"))
287287
},
288288
)
289+
val navigationKeys = TerminalNavigationKeyListener { onInput(mapOf("data" to it)) }
289290
inputView.setOnKeyListener { _, keyCode, event ->
290291
if (readOnly) return@setOnKeyListener true
292+
if (navigationKeys.onKey(inputView, keyCode, event)) return@setOnKeyListener true
291293
if (event.action != KeyEvent.ACTION_DOWN) return@setOnKeyListener false
292294
when {
293295
keyCode == KeyEvent.KEYCODE_DEL -> {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package expo.modules.t3terminal
2+
3+
import android.view.KeyEvent
4+
import android.view.View
5+
6+
internal class TerminalNavigationKeyListener(
7+
private val send: (String) -> Unit
8+
) : View.OnKeyListener {
9+
override fun onKey(view: View?, keyCode: Int, event: KeyEvent): Boolean {
10+
val sequence = sequenceFor(keyCode, event) ?: return false
11+
if (event.action == KeyEvent.ACTION_DOWN) send(sequence)
12+
// Unconsumed arrow and Tab key events move focus off the terminal input.
13+
return true
14+
}
15+
16+
// Matches iOS: these keys only without modifiers, plus Shift+Tab.
17+
private fun sequenceFor(keyCode: Int, event: KeyEvent): String? = when {
18+
keyCode == KeyEvent.KEYCODE_TAB && event.hasModifiers(KeyEvent.META_SHIFT_ON) -> "\u001b[Z"
19+
!event.hasNoModifiers() -> null
20+
keyCode == KeyEvent.KEYCODE_DPAD_UP -> "\u001b[A"
21+
keyCode == KeyEvent.KEYCODE_DPAD_DOWN -> "\u001b[B"
22+
keyCode == KeyEvent.KEYCODE_DPAD_RIGHT -> "\u001b[C"
23+
keyCode == KeyEvent.KEYCODE_DPAD_LEFT -> "\u001b[D"
24+
keyCode == KeyEvent.KEYCODE_TAB -> "\t"
25+
keyCode == KeyEvent.KEYCODE_ESCAPE -> "\u001b"
26+
else -> null
27+
}
28+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package expo.modules.t3terminal
2+
3+
import android.app.Activity
4+
import android.view.KeyEvent
5+
import android.view.View
6+
import android.widget.Button
7+
import android.widget.EditText
8+
import android.widget.LinearLayout
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Assert.assertTrue
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
import org.robolectric.Robolectric
14+
import org.robolectric.RobolectricTestRunner
15+
import org.robolectric.annotation.Config
16+
17+
@RunWith(RobolectricTestRunner::class)
18+
@Config(sdk = [36], manifest = Config.NONE)
19+
class TerminalNavigationKeyListenerTest {
20+
@Test
21+
fun hardwareNavigationKeysReachThePtyAndKeepFocus() {
22+
val activity = Robolectric.buildActivity(Activity::class.java).setup().get()
23+
val sent = StringBuilder()
24+
val input = EditText(activity).apply {
25+
setSingleLine(true)
26+
isFocusableInTouchMode = true
27+
setOnKeyListener(TerminalNavigationKeyListener { sent.append(it) })
28+
}
29+
val nextControl = Button(activity).apply { isFocusableInTouchMode = true }
30+
val root = LinearLayout(activity).apply {
31+
orientation = LinearLayout.VERTICAL
32+
addView(input)
33+
addView(nextControl)
34+
}
35+
activity.setContentView(root)
36+
// Focus search below the input only finds controls that have bounds.
37+
root.measure(
38+
View.MeasureSpec.makeMeasureSpec(1080, View.MeasureSpec.EXACTLY),
39+
View.MeasureSpec.makeMeasureSpec(1920, View.MeasureSpec.EXACTLY),
40+
)
41+
root.layout(0, 0, 1080, 1920)
42+
assertTrue(input.requestFocus())
43+
44+
val shift = KeyEvent.META_SHIFT_ON or KeyEvent.META_SHIFT_LEFT_ON
45+
val keys = listOf(
46+
Triple(KeyEvent.KEYCODE_DPAD_UP, 0, "\u001b[A"),
47+
Triple(KeyEvent.KEYCODE_DPAD_DOWN, 0, "\u001b[B"),
48+
Triple(KeyEvent.KEYCODE_DPAD_RIGHT, 0, "\u001b[C"),
49+
Triple(KeyEvent.KEYCODE_DPAD_LEFT, 0, "\u001b[D"),
50+
Triple(KeyEvent.KEYCODE_TAB, 0, "\t"),
51+
Triple(KeyEvent.KEYCODE_TAB, shift, "\u001b[Z"),
52+
Triple(KeyEvent.KEYCODE_ESCAPE, 0, "\u001b"),
53+
)
54+
for ((keyCode, meta, expected) in keys) {
55+
sent.clear()
56+
input.dispatchKeyEvent(KeyEvent(0, 0, KeyEvent.ACTION_DOWN, keyCode, 0, meta))
57+
input.dispatchKeyEvent(KeyEvent(0, 0, KeyEvent.ACTION_UP, keyCode, 0, meta))
58+
assertEquals("bytes for key $keyCode meta $meta", expected, sent.toString())
59+
assertTrue("focus left the input after key $keyCode meta $meta", input.isFocused)
60+
}
61+
62+
sent.clear()
63+
val ctrl = KeyEvent.META_CTRL_ON or KeyEvent.META_CTRL_LEFT_ON
64+
input.dispatchKeyEvent(KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP, 0, ctrl))
65+
assertEquals("modified arrows are left to the app, as on iOS", "", sent.toString())
66+
}
67+
}

‎apps/mobile/src/Stack.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import {
110110
import {
111111
ScheduledTaskModelPickerRouteScreen,
112112
ScheduledTaskBranchPickerRouteScreen,
113+
ScheduledTaskThreadPickerRouteScreen,
113114
} from "./features/settings/ScheduledTaskPickerScreens";
114115
import { SettingsKeyboardRouteScreen } from "./features/settings/SettingsKeyboardRouteScreen";
115116
import { SettingsLegalRouteScreen } from "./features/settings/SettingsLegalRouteScreen";
@@ -301,6 +302,10 @@ const SETTINGS_SCREENS = {
301302
screen: ScheduledTaskBranchPickerRouteScreen,
302303
options: settingsPage("Base branch"),
303304
}),
305+
SettingsScheduledTaskThread: createNativeStackScreen({
306+
screen: ScheduledTaskThreadPickerRouteScreen,
307+
options: settingsPage("Destination"),
308+
}),
304309
SettingsScheduledTaskModel: createNativeStackScreen({
305310
screen: ScheduledTaskModelPickerRouteScreen,
306311
options: THREAD_SETTINGS_ROUTE,

‎apps/mobile/src/components/FilePreview.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ImageViewing from "react-native-image-viewing";
66
import { useSafeAreaInsets } from "react-native-safe-area-context";
77

88
import { openAttachmentInViewer } from "../lib/attachmentDownload";
9+
import { useMediaActions } from "../state/mediaActions";
910
import type {
1011
ResolvedFilePreviewDocument,
1112
ResolvedFilePreviewSource,
@@ -20,6 +21,8 @@ function PdfDocumentPreview(props: {
2021
readonly onRequestClose: () => void;
2122
}) {
2223
const insets = useSafeAreaInsets();
24+
const media = useMediaActions(props.source.actionsSource);
25+
const save = media.actions.find((action) => action.id === "save");
2326
return (
2427
<Modal
2528
animationType="slide"
@@ -35,6 +38,19 @@ function PdfDocumentPreview(props: {
3538
presentation="inline"
3639
title={props.source.name ?? "PDF"}
3740
onClose={props.onRequestClose}
41+
actions={
42+
save
43+
? [
44+
{
45+
accessibilityLabel: "Save or share",
46+
icon: "square.and.arrow.up",
47+
disabled: save.disabled,
48+
loading: media.sharing,
49+
onPress: () => void save.run(),
50+
},
51+
]
52+
: []
53+
}
3854
/>
3955
<PdfPreview uri={props.source.uri} />
4056
</View>

‎apps/mobile/src/components/FilePreviewModal.tsx‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { refreshAssetUrl } from "../state/assets";
1414
import { filePreviewGallery, filePreviewKey, filePreviewName } from "../lib/filePreviewGallery";
1515
import { FilePreviewGallery } from "./FilePreviewGallery";
1616
import { FilePreview } from "./FilePreview";
17+
import type { MediaActionsSource } from "../lib/mediaActionsSource";
1718
import type { FilePreviewItem, FilePreviewSource } from "./FilePreviewModal.types";
1819

1920
export type {
@@ -67,6 +68,18 @@ async function resolvePreviewUri(
6768
return { uri: url + (item.srcFragment ?? "") };
6869
}
6970

71+
// Shares from the unresolved item so remote URLs refresh and draft files take their own lease.
72+
function pdfActionsSource(item: FilePreviewItem): MediaActionsSource {
73+
const metadata = {
74+
name: filePreviewName(item),
75+
mimeType: item.mimeType ?? "application/pdf",
76+
...(item.sourceIdentifier ? { sourceIdentifier: item.sourceIdentifier } : {}),
77+
};
78+
if ("uri" in item) return { ...metadata, uri: item.uri };
79+
if ("attachment" in item) return { ...metadata, attachment: item.attachment };
80+
return { ...metadata, environmentId: item.environmentId, resource: item.resource };
81+
}
82+
7083
function ResolvedFilePreview(props: {
7184
readonly source: FilePreviewSource;
7285
readonly onRequestClose: () => void;
@@ -166,9 +179,16 @@ function ResolvedFilePreview(props: {
166179
: []),
167180
]);
168181
};
182+
const actionsSource =
183+
selected.kind === "pdf" ? (selected.actionsSource ?? pdfActionsSource(selected)) : undefined;
169184
return (
170185
<FilePreview
171-
source={{ ...selected, kind: selected.kind, uri }}
186+
source={{
187+
...selected,
188+
kind: selected.kind,
189+
uri,
190+
...(actionsSource ? { actionsSource } : {}),
191+
}}
172192
onRequestClose={props.onRequestClose}
173193
onOpenError={onOpenError}
174194
/>

‎apps/mobile/src/components/ui/AppBar.android.tsx‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@ function AppBarView(props: AppBarProps & { readonly searchState?: SearchState })
155155
</Menu>
156156
));
157157
const confirmButton = props.confirm ? (
158-
<Button
159-
label={props.confirm.label}
160-
tone="text"
161-
loading={props.confirm.loading}
162-
disabled={props.confirm.disabled}
163-
onPress={props.confirm.onPress}
164-
/>
158+
<View className="self-center">
159+
<Button
160+
label={props.confirm.label}
161+
tone="text"
162+
loading={props.confirm.loading}
163+
disabled={props.confirm.disabled}
164+
onPress={props.confirm.onPress}
165+
/>
166+
</View>
165167
) : null;
166168
const options =
167169
props.embedded || props.sheet ? null : (

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,16 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
845845
kind: "pdf",
846846
uri: previewUri,
847847
name: basename(relativePath),
848+
...(environmentId !== null && assetPreview.resource !== null
849+
? {
850+
actionsSource: {
851+
name: basename(relativePath),
852+
mimeType: "application/pdf",
853+
environmentId,
854+
resource: assetPreview.resource,
855+
},
856+
}
857+
: {}),
848858
}),
849859
} as const)
850860
: null,

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ export function PullRequestAgentRow(props: {
1919
title={props.title ?? action.title}
2020
icon="sparkles"
2121
accessibilityLabel={props.title ?? action.title}
22-
menu={agent.threads.length > 1}
22+
menu={agent.chooseThread && !action.attributes.disabled}
2323
onPress={
24-
action.attributes.disabled || agent.threads.length > 1
25-
? undefined
26-
: () => agent.start(props.task)
24+
action.attributes.disabled || agent.chooseThread ? undefined : () => agent.start(props.task)
2725
}
2826
/>
2927
);
30-
if (agent.threads.length <= 1 || action.attributes.disabled) return row;
28+
if (!agent.chooseThread || action.attributes.disabled) return row;
3129
return (
3230
<Menu
3331
title={props.title ?? action.title}

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Animated from "react-native-reanimated";
33
import { PR_ROW_LAYOUT } from "./pullRequestAnimations";
44
import { useNavigation } from "@react-navigation/native";
55
import type { PullRequestDetail } from "@t3tools/contracts";
6+
import type { MenuAction } from "@react-native-menu/menu";
67
import type { ReactNode } from "react";
78
import { Platform, Pressable, View } from "react-native";
89
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -126,7 +127,7 @@ export function PullRequestActionToolbar(props: {
126127
const { shortLabel } = useChangeRequestTerms();
127128
const threadLabel = agent.threads.length ? "Continue thread" : `Work on ${shortLabel}`;
128129
const primaryLabel = pendingReview ? `Submit review · ${draft.comments.length}` : threadLabel;
129-
const chooseThread = agent.threads.length > 1;
130+
const chooseThread = agent.chooseThread;
130131
const agentActions = agent.actions.filter((action) => action.task !== "ask");
131132
const open = (mode: "review" | "comment") =>
132133
navigation.navigate("PullRequestReview", { ...props.params, mode });
@@ -191,17 +192,6 @@ export function PullRequestActionToolbar(props: {
191192
</View>
192193
);
193194
}
194-
const nativeThreadItems = threadMenuItems.map((item) => (
195-
<Toolbar.MenuAction
196-
key={item.id}
197-
icon={item.image}
198-
subtitle={"subtitle" in item ? item.subtitle : undefined}
199-
disabled={"attributes" in item && item.attributes.disabled}
200-
onPress={() => agent.select(item.id)}
201-
>
202-
<Toolbar.Label>{item.title}</Toolbar.Label>
203-
</Toolbar.MenuAction>
204-
));
205195
const primaryControl = showPrimary ? (
206196
!pendingReview && chooseThread ? (
207197
<Toolbar.Menu
@@ -220,7 +210,7 @@ export function PullRequestActionToolbar(props: {
220210
disabled={primaryDisabled}
221211
separateBackground
222212
>
223-
{nativeThreadItems}
213+
{renderThreadMenuItems(threadMenuItems, agent.select)}
224214
</Toolbar.Menu>
225215
) : (
226216
<Toolbar.Button
@@ -254,17 +244,7 @@ export function PullRequestActionToolbar(props: {
254244
{agentActions.map((action) =>
255245
chooseThread && !action.disabled ? (
256246
<Toolbar.Menu key={action.task} title={action.title} icon={action.icon}>
257-
{agent.threadActions(action.task).map((item) => (
258-
<Toolbar.MenuAction
259-
key={item.id}
260-
icon={item.image}
261-
subtitle={"subtitle" in item ? item.subtitle : undefined}
262-
disabled={"attributes" in item && item.attributes.disabled}
263-
onPress={() => agent.select(item.id)}
264-
>
265-
<Toolbar.Label>{item.title}</Toolbar.Label>
266-
</Toolbar.MenuAction>
267-
))}
247+
{renderThreadMenuItems(agent.threadActions(action.task), agent.select)}
268248
</Toolbar.Menu>
269249
) : (
270250
<Toolbar.MenuAction
@@ -306,3 +286,23 @@ export function PullRequestActionToolbar(props: {
306286
</Toolbar>
307287
);
308288
}
289+
290+
function renderThreadMenuItems(items: MenuAction[], select: (id: string) => void): ReactNode {
291+
return items.map((item) =>
292+
item.subactions ? (
293+
<Toolbar.Menu key={item.id} title={item.title} icon={item.image}>
294+
{renderThreadMenuItems(item.subactions, select)}
295+
</Toolbar.Menu>
296+
) : (
297+
<Toolbar.MenuAction
298+
key={item.id}
299+
icon={item.image}
300+
subtitle={item.subtitle}
301+
disabled={item.attributes?.disabled}
302+
onPress={() => item.id && select(item.id)}
303+
>
304+
<Toolbar.Label>{item.title}</Toolbar.Label>
305+
</Toolbar.MenuAction>
306+
),
307+
);
308+
}

0 commit comments

Comments
 (0)