Skip to content

Commit f122ca6

Browse files
Merge branch 'main' into andrew/windows-taskbar-unread-badge
2 parents c5bd2fa + 0eaa18c commit f122ca6

320 files changed

Lines changed: 25271 additions & 4203 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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,16 @@ describe("ElectronShell", () => {
9393
openExternalMock.mockResolvedValue(undefined);
9494

9595
const electronShell = yield* ElectronShell.ElectronShell;
96-
const result = yield* electronShell.openExternal("zed://ssh/example.com/home/user/project");
96+
const results = yield* Effect.all([
97+
electronShell.openExternal("zed://ssh/example.com/home/user/project"),
98+
electronShell.openExternal("zed://ssh/example.com/"),
99+
]);
97100

98-
assert.equal(result, true);
99-
assert.deepEqual(openExternalMock.mock.calls, [["zed://ssh/example.com/home/user/project"]]);
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+
]);
100106
}).pipe(Effect.provide(ElectronShell.layer)),
101107
);
102108

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(
3636
);
3737

3838
// Zed's host sits in the first path segment, so it needs its own userinfo ban.
39-
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.+$/;
39+
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.*$/;
4040

4141
const isRemoteEditorUrl = (url: URL) =>
4242
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&

‎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: 67 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import { createContext, useContext, useEffect, useState } from "react";
1+
import { createContext, memo, useContext, useMemo } from "react";
22
import { Image, Platform, ScrollView, Text, useColorScheme, View } from "react-native";
33
import type { MarkdownNode } from "react-native-nitro-markdown/headless";
44

55
import { CopyTextButton } from "./CopyTextButton";
66
import { MarkdownTextPrimitive } from "./MarkdownTextPrimitive";
7-
import { nativeMarkdownDocumentRuns, nativeMarkdownListItemBlocks } from "./nativeMarkdownText";
8-
import { NativeMarkdownSelectableText } from "./NativeMarkdownSelectableText.ios";
7+
import {
8+
nativeMarkdownDocumentRuns,
9+
nativeMarkdownListItemBlocks,
10+
nativeMarkdownNodePosition,
11+
} from "./nativeMarkdownText";
12+
import { NativeMarkdownSelectableText } from "./NativeMarkdownSelectableText";
913
import type {
1014
MarkdownCodeHighlighter,
1115
MarkdownHighlightedToken,
1216
MarkdownImageRenderer,
1317
NativeMarkdownTextStyle,
1418
SelectableMarkdownSkill,
1519
} from "./SelectableMarkdownText.types";
20+
import { useHighlightedCode, type HighlightedCode } from "./useHighlightedCode";
1621

1722
/** Set by SelectableMarkdownText so images anywhere in the block tree can use it. */
1823
export const MarkdownImageRendererContext = createContext<MarkdownImageRenderer | null>(null);
1924

20-
type HighlightedCode = ReadonlyArray<ReadonlyArray<MarkdownHighlightedToken>>;
21-
22-
const highlightedCodeCache = new Map<string, HighlightedCode>();
23-
const highlightedCodePromiseCache = new Map<string, Promise<HighlightedCode>>();
24-
const HIGHLIGHTED_CODE_CACHE_LIMIT = 64;
2525
const MONO_FONT_FAMILY = Platform.select({
2626
ios: "ui-monospace",
2727
android: "monospace",
2828
default: "monospace",
2929
});
3030

3131
function nodeKey(node: MarkdownNode, index: number): string {
32-
return `${node.type}:${node.beg ?? index}:${node.end ?? index}`;
32+
return `${node.type}:${nativeMarkdownNodePosition(node, index)}`;
3333
}
3434

3535
/** Code inside markdown scales with the base text size (12pt at the default 15pt body). */
@@ -67,174 +67,74 @@ function SelectableNode(props: {
6767
);
6868
}
6969

70-
function codeHighlightCacheKey(
71-
code: string,
72-
language: string | undefined,
73-
theme: "light" | "dark",
74-
): string {
75-
return `${theme}:${language ?? "text"}:${code}`;
76-
}
77-
78-
function cacheHighlightedCode(key: string, tokens: HighlightedCode): void {
79-
highlightedCodeCache.delete(key);
80-
highlightedCodeCache.set(key, tokens);
81-
82-
while (highlightedCodeCache.size > HIGHLIGHTED_CODE_CACHE_LIMIT) {
83-
const oldestKey = highlightedCodeCache.keys().next().value;
84-
if (oldestKey === undefined) {
85-
break;
86-
}
87-
highlightedCodeCache.delete(oldestKey);
88-
}
89-
}
90-
91-
function loadHighlightedCode(
92-
code: string,
93-
language: string | undefined,
94-
theme: "light" | "dark",
95-
highlightCode: MarkdownCodeHighlighter,
96-
): Promise<HighlightedCode> {
97-
const key = codeHighlightCacheKey(code, language, theme);
98-
const cached = highlightedCodeCache.get(key);
99-
if (cached) {
100-
return Promise.resolve(cached);
101-
}
102-
103-
const pending = highlightedCodePromiseCache.get(key);
104-
if (pending) {
105-
return pending;
106-
}
107-
108-
const promise = highlightCode({ code, language, theme })
109-
.then((tokens) => {
110-
cacheHighlightedCode(key, tokens);
111-
highlightedCodePromiseCache.delete(key);
112-
return tokens;
113-
})
114-
.catch((error) => {
115-
highlightedCodePromiseCache.delete(key);
116-
throw error;
117-
});
118-
highlightedCodePromiseCache.set(key, promise);
119-
return promise;
120-
}
121-
122-
function useHighlightedCode(
123-
code: string,
124-
language: string | undefined,
125-
theme: "light" | "dark",
126-
highlightCode: MarkdownCodeHighlighter,
127-
): HighlightedCode | null {
128-
const key = codeHighlightCacheKey(code, language, theme);
129-
const [highlighted, setHighlighted] = useState<{
130-
readonly key: string;
131-
readonly tokens: HighlightedCode | null;
132-
}>(() => ({
133-
key,
134-
tokens: highlightedCodeCache.get(key) ?? null,
135-
}));
136-
137-
useEffect(() => {
138-
let active = true;
139-
const cached = highlightedCodeCache.get(key);
140-
if (cached) {
141-
cacheHighlightedCode(key, cached);
142-
setHighlighted({ key, tokens: cached });
143-
return () => {
144-
active = false;
145-
};
146-
}
147-
148-
void loadHighlightedCode(code, language, theme, highlightCode)
149-
.then((tokens) => {
150-
if (active) {
151-
setHighlighted({ key, tokens });
152-
}
153-
})
154-
.catch(() => {
155-
if (active) {
156-
setHighlighted({ key, tokens: null });
157-
}
158-
});
159-
return () => {
160-
active = false;
161-
};
162-
}, [code, highlightCode, key, language, theme]);
163-
164-
return highlighted.key === key ? highlighted.tokens : null;
165-
}
166-
167-
function HighlightedCodeText(props: {
168-
readonly content: string;
169-
readonly highlighted: HighlightedCode | null;
170-
readonly textStyle: NativeMarkdownTextStyle;
70+
const HighlightedCodeLine = memo(function HighlightedCodeLine(props: {
71+
readonly tokens: ReadonlyArray<MarkdownHighlightedToken>;
72+
readonly color: string;
73+
readonly newline: boolean;
17174
}) {
172-
if (!props.highlighted) {
173-
return (
75+
let offset = 0;
76+
const children = [];
77+
for (const token of props.tokens) {
78+
if (!token.content) continue;
79+
children.push(
17480
<MarkdownTextPrimitive
175-
uiTextView
176-
selectable
81+
key={offset}
17782
style={{
178-
color: props.textStyle.codeColor,
83+
color: token.color ?? props.color,
17984
fontFamily: MONO_FONT_FAMILY,
180-
fontSize: codeBlockFontSize(props.textStyle),
181-
lineHeight: codeBlockLineHeight(props.textStyle),
85+
fontStyle: token.fontStyle !== null && (token.fontStyle & 1) === 1 ? "italic" : "normal",
86+
fontWeight: token.fontStyle !== null && (token.fontStyle & 2) === 2 ? "700" : "400",
18287
}}
18388
>
184-
{props.content}
185-
</MarkdownTextPrimitive>
89+
{token.content}
90+
</MarkdownTextPrimitive>,
18691
);
92+
offset += token.content.length;
18793
}
188-
const highlighted = props.highlighted;
189-
let sourceOffset = 0;
190-
const keyOccurrences = new Map<string, number>();
191-
const keyedLines = highlighted.map((line) => {
192-
const lineStart = sourceOffset;
193-
const tokens = line.map((token) => {
194-
const start = sourceOffset;
195-
sourceOffset += token.content.length;
196-
const signature = `${start}:${token.content}:${token.color ?? ""}:${token.fontStyle ?? ""}`;
197-
const occurrence = keyOccurrences.get(signature) ?? 0;
198-
keyOccurrences.set(signature, occurrence + 1);
199-
return { key: `${signature}:${occurrence}`, token };
200-
});
201-
sourceOffset += 1;
202-
return {
203-
key: `line:${lineStart}:${line.map((token) => token.content).join("")}`,
204-
tokens,
205-
};
206-
});
94+
return (
95+
<MarkdownTextPrimitive>
96+
{children}
97+
{props.newline ? "\n" : ""}
98+
</MarkdownTextPrimitive>
99+
);
100+
});
207101

102+
function HighlightedCodeText(props: {
103+
readonly content: string;
104+
readonly highlighted: HighlightedCode | null;
105+
readonly textStyle: NativeMarkdownTextStyle;
106+
}) {
107+
// The text root provides inherited styles through context. A new style object
108+
// would rerender every token even when its completed line is unchanged.
109+
const fontSize = codeBlockFontSize(props.textStyle);
110+
const lineHeight = codeBlockLineHeight(props.textStyle);
111+
const style = useMemo(
112+
() => ({
113+
color: props.textStyle.codeColor,
114+
fontFamily: MONO_FONT_FAMILY,
115+
fontSize,
116+
lineHeight,
117+
}),
118+
[props.textStyle.codeColor, fontSize, lineHeight],
119+
);
120+
let offset = 0;
121+
const lines = [];
122+
if (props.highlighted) {
123+
for (const tokens of props.highlighted) {
124+
lines.push(
125+
<HighlightedCodeLine
126+
key={offset}
127+
tokens={tokens}
128+
color={props.textStyle.codeColor}
129+
newline={lines.length + 1 < props.highlighted.length}
130+
/>,
131+
);
132+
offset += tokens.reduce((length, token) => length + token.content.length, 0) + 1;
133+
}
134+
}
208135
return (
209-
<MarkdownTextPrimitive
210-
uiTextView
211-
selectable
212-
style={{
213-
color: props.textStyle.codeColor,
214-
fontFamily: MONO_FONT_FAMILY,
215-
fontSize: codeBlockFontSize(props.textStyle),
216-
lineHeight: codeBlockLineHeight(props.textStyle),
217-
}}
218-
>
219-
{keyedLines.map((line, lineIndex) => (
220-
<MarkdownTextPrimitive key={line.key}>
221-
{line.tokens.map(({ key, token }) => (
222-
<MarkdownTextPrimitive
223-
key={key}
224-
style={{
225-
color: token.color ?? props.textStyle.codeColor,
226-
fontFamily: MONO_FONT_FAMILY,
227-
fontStyle:
228-
token.fontStyle !== null && (token.fontStyle & 1) === 1 ? "italic" : "normal",
229-
fontWeight: token.fontStyle !== null && (token.fontStyle & 2) === 2 ? "700" : "400",
230-
}}
231-
>
232-
{token.content}
233-
</MarkdownTextPrimitive>
234-
))}
235-
{lineIndex + 1 < keyedLines.length ? "\n" : ""}
236-
</MarkdownTextPrimitive>
237-
))}
136+
<MarkdownTextPrimitive uiTextView selectable style={style}>
137+
{props.highlighted ? lines : props.content}
238138
</MarkdownTextPrimitive>
239139
);
240140
}

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.

0 commit comments

Comments
 (0)