Skip to content

Commit 003dab5

Browse files
committed
fix(mobile): limit math file actions to file links
1 parent 167de81 commit 003dab5

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const NativeMathText = memo(function NativeMathText(props: {
8181
return renderer.nativeMathRunHtml(
8282
run,
8383
style,
84-
run.href ? fileContextMenu?.(run.href) : undefined,
84+
run.fileIcon && run.href ? fileContextMenu?.(run.href) : undefined,
8585
icons[nativeMathIconKey(run) ?? ""],
8686
showExternalIcon,
8787
);
@@ -170,7 +170,7 @@ export const NativeMathText = memo(function NativeMathText(props: {
170170
const href = message.href;
171171
const actionId = message.action;
172172
if (
173-
props.runs.some((run) => run.href === href) &&
173+
props.runs.some((run) => run.fileIcon && run.href === href) &&
174174
props
175175
.fileContextMenu?.(href)
176176
?.actions.some((action) => action.id === actionId && !action.disabled)

‎apps/mobile/modules/t3-markdown-text/src/nativeMathHtml.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ export function nativeMathRunHtml(
9999
}
100100
if (run.href) {
101101
const href = escapeHtml(run.href);
102-
const actions = menu
103-
? `<button class="file-actions" aria-label="File actions" data-menu="${escapeHtml(JSON.stringify(menu))}" data-href="${href}">⋯</button>`
104-
: "";
102+
const actions =
103+
run.fileIcon && menu
104+
? `<button class="file-actions" aria-label="File actions" data-menu="${escapeHtml(JSON.stringify(menu))}" data-href="${href}">⋯</button>`
105+
: "";
105106
return `<a style="${escapeHtml(css)}" href="${href}">${content}</a>${actions}`;
106107
}
107108
return `<span style="${escapeHtml(css)}">${content}</span>`;

‎apps/mobile/src/lib/nativeMarkdownMath.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ it("keeps heading size, skill labels, file icons and links in math text", () =>
100100
icon,
101101
),
102102
nativeMathRunHtml({ text: "Email", href: "mailto:[email protected]" }, textStyle),
103+
nativeMathRunHtml({ text: "Docs", href: "https://example.com" }, textStyle, {
104+
title: "File",
105+
actions: [{ id: "open", title: "Open" }],
106+
}),
103107
].join("");
104108
const dom = new JSDOM(html);
105109
try {
@@ -112,7 +116,9 @@ it("keeps heading size, skill labels, file icons and links in math text", () =>
112116
);
113117
expect(document.querySelector("[data-copy-source]")?.textContent).toBe("Deploy");
114118
expect(document.querySelector("img")?.getAttribute("src")).toBe(icon);
115-
expect(document.querySelector("[data-menu]")).not.toBeNull();
119+
expect(document.querySelectorAll("[data-menu]")).toHaveLength(1);
120+
expect(document.querySelector("[data-menu]")?.getAttribute("data-href")).toBe("file:///app.ts");
121+
expect(document.querySelector('a[href="https://example.com"]')?.textContent).toBe("Docs");
116122
expect(document.querySelector('a[href="mailto:[email protected]"]')?.textContent).toBe("Email");
117123
} finally {
118124
dom.window.close();

0 commit comments

Comments
 (0)