Skip to content

Commit d5a789e

Browse files
authored
Merge branch 'main' into fix/checkpoint-index-metadata
2 parents 8679610 + 4d06156 commit d5a789e

331 files changed

Lines changed: 29322 additions & 1788 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/desktop/src/electron/ElectronShell.test.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,39 @@ describe("ElectronShell", () => {
8888
}).pipe(Effect.provide(ElectronShell.layer)),
8989
);
9090

91+
it.effect("opens Zed's ssh deep link", () =>
92+
Effect.gen(function* () {
93+
openExternalMock.mockResolvedValue(undefined);
94+
95+
const electronShell = yield* ElectronShell.ElectronShell;
96+
const results = yield* Effect.all([
97+
electronShell.openExternal("zed://ssh/example.com/home/user/project"),
98+
electronShell.openExternal("zed://ssh/example.com/"),
99+
]);
100+
101+
assert.deepEqual(results, [true, true]);
102+
assert.deepEqual(openExternalMock.mock.calls, [
103+
["zed://ssh/example.com/home/user/project"],
104+
["zed://ssh/example.com/"],
105+
]);
106+
}).pipe(Effect.provide(ElectronShell.layer)),
107+
);
108+
109+
it.effect("does not open editor URLs that mix up link shapes", () =>
110+
Effect.gen(function* () {
111+
openExternalMock.mockResolvedValue(undefined);
112+
113+
const electronShell = yield* ElectronShell.ElectronShell;
114+
const results = yield* Effect.all([
115+
electronShell.openExternal("zed://extension/attacker"),
116+
electronShell.openExternal("vscode://ssh/example.com/home/user/project"),
117+
]);
118+
119+
assert.deepEqual(results, [false, false]);
120+
assert.equal(openExternalMock.mock.calls.length, 0);
121+
}).pipe(Effect.provide(ElectronShell.layer)),
122+
);
123+
91124
it.effect("does not open remote editor URLs with userinfo", () =>
92125
Effect.gen(function* () {
93126
openExternalMock.mockResolvedValue(undefined);
@@ -100,9 +133,10 @@ describe("ElectronShell", () => {
100133
electronShell.openExternal(
101134
"vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",
102135
),
136+
electronShell.openExternal("zed://ssh/[email protected]/home/user/project"),
103137
]);
104138

105-
assert.deepEqual(results, [false, false]);
139+
assert.deepEqual(results, [false, false, false]);
106140
assert.equal(openExternalMock.mock.calls.length, 0);
107141
}).pipe(Effect.provide(ElectronShell.layer)),
108142
);

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ const SYSTEM_SETTINGS_URLS: Record<SystemSettingsPane, string> = {
2424
"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_AllFiles",
2525
};
2626

27-
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`)
28-
// must reach the OS handler; every other non-web scheme stays blocked.
27+
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`,
28+
// `zed://ssh/<host>/<path>`) must reach the OS handler; every other non-web
29+
// scheme stays blocked.
2930
const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);
3031
const REMOTE_EDITOR_PROTOCOLS = new Set(
3132
REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
@@ -34,13 +35,18 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
3435
}),
3536
);
3637

38+
// Zed's host sits in the first path segment, so it needs its own userinfo ban.
39+
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.*$/;
40+
3741
const isRemoteEditorUrl = (url: URL) =>
3842
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&
3943
url.username.length === 0 &&
4044
url.password.length === 0 &&
41-
url.host === "vscode-remote" &&
42-
url.pathname.startsWith("/ssh-remote+") &&
43-
url.pathname.length > "/ssh-remote+".length;
45+
(url.protocol === "zed:"
46+
? url.host === "ssh" && ZED_SSH_PATHNAME.test(url.pathname)
47+
: url.host === "vscode-remote" &&
48+
url.pathname.startsWith("/ssh-remote+") &&
49+
url.pathname.length > "/ssh-remote+".length);
4450

4551
export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
4652
if (typeof rawUrl !== "string") {

‎apps/marketing/src/lib/site.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export const ANDROID_PLAY_STORE_URL =
77
"https://play.google.com/store/apps/details?id=com.t3tools.t3code";
88

99
export const MARKETING_STATS = {
10-
githubStars: "21k+",
11-
users: "200,000",
10+
githubStars: "22k+",
11+
users: "300,000",
1212
} as const;

‎apps/marketing/vercel.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ export const config: VercelConfig = {
77
installCommand: "npm install -g vite-plus && vp install --filter '@t3tools/marketing...'",
88
buildCommand: "vp run --filter @t3tools/marketing build",
99
outputDirectory: "dist",
10+
redirects: [
11+
{
12+
source: "/app",
13+
destination: "https://app.t3.codes",
14+
permanent: true,
15+
},
16+
],
1017
};

‎apps/mobile/modules/t3-markdown-text/android/src/main/java/expo/modules/t3markdowntext/T3MarkdownTextSelectionModule.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package expo.modules.t3markdowntext
33
import android.content.ClipData
44
import android.content.ClipboardManager
55
import android.content.Context
6+
import android.text.Spannable
7+
import android.text.SpannableStringBuilder
68
import android.text.Spanned
79
import android.text.style.ReplacementSpan
810
import android.view.ActionMode
@@ -18,6 +20,14 @@ import kotlin.math.min
1820

1921
private const val OBJECT_REPLACEMENT_CHARACTER = "\uFFFC"
2022

23+
// Match React Native's measurement buffer. Android orders tied line-height
24+
// spans differently in SpannableString, shifting inline images once RN's
25+
// span priorities are exhausted.
26+
private object MarkdownSpannableFactory : Spannable.Factory() {
27+
override fun newSpannable(source: CharSequence): Spannable =
28+
SpannableStringBuilder(source)
29+
}
30+
2131
private fun copyTextWithoutInlineImages(
2232
text: CharSequence,
2333
start: Int,
@@ -85,6 +95,7 @@ class T3MarkdownTextSelectionModule : Module() {
8595
if (currentCallback is SanitizingSelectionActionModeCallback) {
8696
return@runOnUiQueueThread
8797
}
98+
textView.setSpannableFactory(MarkdownSpannableFactory)
8899
textView.customSelectionActionModeCallback =
89100
SanitizingSelectionActionModeCallback(textView, currentCallback)
90101
}

‎apps/mobile/modules/t3-markdown-text/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"./links": "./src/markdownLinks.ts",
2626
"./markdown": "./src/nativeMarkdownText.ts",
2727
"./primitive": "./src/MarkdownTextPrimitive.tsx",
28-
"./renderer": "./src/SelectableMarkdownText.ios.tsx",
28+
"./renderer": "./src/SelectableMarkdownText.tsx",
2929
"./types": "./src/SelectableMarkdownText.types.ts"
3030
},
3131
"peerDependencies": {

apps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.ios.tsx renamed to apps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { MarkdownNode } from "react-native-nitro-markdown/headless";
55
import { CopyTextButton } from "./CopyTextButton";
66
import { MarkdownTextPrimitive } from "./MarkdownTextPrimitive";
77
import { nativeMarkdownDocumentRuns, nativeMarkdownListItemBlocks } from "./nativeMarkdownText";
8-
import { NativeMarkdownSelectableText } from "./NativeMarkdownSelectableText.ios";
8+
import { NativeMarkdownSelectableText } from "./NativeMarkdownSelectableText";
99
import type {
1010
MarkdownCodeHighlighter,
1111
MarkdownHighlightedToken,

apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.ios.tsx renamed to apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.tsx

File renamed without changes.

‎apps/mobile/modules/t3-markdown-text/src/SelectableMarkdownText.ios.tsx‎

Lines changed: 0 additions & 117 deletions
This file was deleted.

‎apps/mobile/modules/t3-markdown-text/src/SelectableMarkdownText.tsx‎

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
import type { SelectableMarkdownTextProps } from "./SelectableMarkdownText.types";
1+
import { useMemo } from "react";
2+
import { View } from "react-native";
3+
import { parseMarkdownWithOptions } from "react-native-nitro-markdown/headless";
4+
5+
import {
6+
nativeMarkdownChunkSpacing,
7+
nativeMarkdownDocumentChunks,
8+
nativeMarkdownDocumentRuns,
9+
nativeMarkdownWithPreservedSoftBreaks,
10+
} from "./nativeMarkdownText";
11+
import { MarkdownImageRendererContext, NativeMarkdownBlock } from "./NativeMarkdownBlock";
12+
import {
13+
MarkdownFileContextMenuContext,
14+
NativeMarkdownSelectableText,
15+
type MarkdownFileContextMenuHandlers,
16+
} from "./NativeMarkdownSelectableText";
17+
import type {
18+
SelectableMarkdownSkill,
19+
SelectableMarkdownTextProps,
20+
} from "./SelectableMarkdownText.types";
21+
22+
const EMPTY_SKILLS: ReadonlyArray<SelectableMarkdownSkill> = [];
223

324
export type {
425
MarkdownCodeHighlighter,
@@ -10,6 +31,87 @@ export type {
1031
SelectableMarkdownTextProps,
1132
} from "./SelectableMarkdownText.types";
1233

13-
export function SelectableMarkdownText(_props: SelectableMarkdownTextProps) {
14-
return null;
34+
export function hasNativeSelectableMarkdownText(): boolean {
35+
return true;
36+
}
37+
38+
export function SelectableMarkdownText({
39+
markdown,
40+
skills = EMPTY_SKILLS,
41+
textStyle,
42+
highlightCode,
43+
preserveSoftBreaks = false,
44+
onLinkPress,
45+
fileContextMenu,
46+
onFileContextMenuAction,
47+
renderImage,
48+
marginTop = 0,
49+
marginBottom = 0,
50+
}: SelectableMarkdownTextProps) {
51+
const chunks = useMemo(() => {
52+
const parsedDocument = parseMarkdownWithOptions(markdown, {
53+
gfm: true,
54+
html: true,
55+
math: false,
56+
});
57+
const document = preserveSoftBreaks
58+
? nativeMarkdownWithPreservedSoftBreaks(parsedDocument)
59+
: parsedDocument;
60+
return nativeMarkdownDocumentChunks(document).map((chunk) =>
61+
chunk.kind === "selectable"
62+
? {
63+
...chunk,
64+
runs: nativeMarkdownDocumentRuns(chunk.node, skills),
65+
}
66+
: chunk,
67+
);
68+
}, [markdown, preserveSoftBreaks, skills]);
69+
70+
const fileContextMenuHandlers = useMemo<MarkdownFileContextMenuHandlers | null>(
71+
() =>
72+
fileContextMenu && onFileContextMenuAction
73+
? { fileContextMenu, onFileContextMenuAction }
74+
: null,
75+
[fileContextMenu, onFileContextMenuAction],
76+
);
77+
78+
return (
79+
<MarkdownImageRendererContext.Provider value={renderImage ?? null}>
80+
<MarkdownFileContextMenuContext.Provider value={fileContextMenuHandlers}>
81+
{/* A percentage width here creates a cyclic intrinsic measurement inside
82+
shrink-to-fit containers such as user-message bubbles. Yoga then gives
83+
the native text node an unbounded second pass and the parent only clips
84+
the resulting single-line width instead of reflowing it. */}
85+
<View style={{ flexShrink: 1, minWidth: 0, marginTop, marginBottom }}>
86+
{chunks.map((chunk, index) => {
87+
const content =
88+
chunk.kind === "rich" ? (
89+
<NativeMarkdownBlock
90+
node={chunk.node}
91+
skills={skills}
92+
textStyle={textStyle}
93+
highlightCode={highlightCode}
94+
onLinkPress={onLinkPress}
95+
/>
96+
) : (
97+
<NativeMarkdownSelectableText
98+
runs={chunk.runs}
99+
textStyle={textStyle}
100+
onLinkPress={onLinkPress}
101+
/>
102+
);
103+
104+
return (
105+
<View
106+
key={chunk.key}
107+
style={{ paddingTop: nativeMarkdownChunkSpacing(chunks[index - 1], chunk) }}
108+
>
109+
{content}
110+
</View>
111+
);
112+
})}
113+
</View>
114+
</MarkdownFileContextMenuContext.Provider>
115+
</MarkdownImageRendererContext.Provider>
116+
);
15117
}

0 commit comments

Comments
 (0)