Skip to content

Commit 18502c7

Browse files
authored
fix(code): style slash commands, fix font (#1511)
## Problem - slash commands don't get highlighted in the submitted prompt the same way they do in the prompt inbox box - chips flip from sans-serif to monospace font after submitting <!-- Who is this for and what problem does it solve? --> <!-- Closes #ISSUE_ID --> ## Changes added slash command highlight, made the font consistent w/ the input box ![Screenshot 2026-04-06 at 2.26.54 PM.png](https://app.graphite.com/user-attachments/assets/d6e86076-7221-45dc-9785-5eb455c6472e.png) <!-- What did you change and why? --> <!-- If there are frontend changes, include screenshots. --> ## How did you test this? manually <!-- Describe what you tested -- manual steps, automated tests, or both. --> <!-- If you're an agent, only list tests you actually ran. -->
1 parent 40123ba commit 18502c7

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

apps/code/src/renderer/features/sessions/components/session-update/parseFileMentions.tsx

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
defaultRemarkPlugins,
44
} from "@features/editor/components/MarkdownRenderer";
55
import { File, GithubLogo, Warning } from "@phosphor-icons/react";
6-
import { Code, Text } from "@radix-ui/themes";
6+
import { Text } from "@radix-ui/themes";
77
import type { ReactNode } from "react";
88
import { memo } from "react";
99
import type { Components } from "react-markdown";
@@ -13,6 +13,7 @@ const MENTION_TAG_REGEX =
1313
/<file\s+path="([^"]+)"\s*\/>|<github_issue\s+number="([^"]+)"(?:\s+title="([^"]*)")?(?:\s+url="([^"]*)")?\s*\/>|<error_context\s+label="([^"]*)">[\s\S]*?<\/error_context>/g;
1414
const MENTION_TAG_TEST =
1515
/<(?:file\s+path|github_issue\s+number|error_context\s+label)="[^"]+"/;
16+
const SLASH_COMMAND_START = /^\/([a-zA-Z][\w-]*)(?=\s|$)/;
1617

1718
const inlineComponents: Components = {
1819
...baseComponents,
@@ -39,11 +40,14 @@ export const InlineMarkdown = memo(function InlineMarkdown({
3940
});
4041

4142
export function hasMentionTags(content: string): boolean {
42-
return MENTION_TAG_TEST.test(content);
43+
return MENTION_TAG_TEST.test(content) || SLASH_COMMAND_START.test(content);
4344
}
4445

4546
export const hasFileMentions = hasMentionTags;
4647

48+
const chipClass =
49+
"inline-flex items-center gap-1 rounded-[var(--radius-1)] bg-[var(--accent-a3)] px-1 py-px align-middle font-medium text-[var(--accent-11)]";
50+
4751
function MentionChip({
4852
icon,
4953
label,
@@ -53,32 +57,48 @@ function MentionChip({
5357
label: string;
5458
onClick?: () => void;
5559
}) {
60+
const style = {
61+
fontSize: "var(--font-size-1)",
62+
margin: "0 2px",
63+
};
64+
65+
if (onClick) {
66+
return (
67+
<button
68+
type="button"
69+
className={`${chipClass} cursor-pointer border-none`}
70+
onClick={onClick}
71+
style={style}
72+
>
73+
{icon}
74+
{label}
75+
</button>
76+
);
77+
}
78+
5679
return (
57-
<Code
58-
size="1"
59-
variant="soft"
60-
onClick={onClick}
61-
style={{
62-
display: "inline-flex",
63-
alignItems: "center",
64-
gap: "4px",
65-
verticalAlign: "middle",
66-
margin: "0 2px",
67-
cursor: onClick ? "pointer" : undefined,
68-
}}
69-
>
80+
<span className={chipClass} style={style}>
7081
{icon}
7182
{label}
72-
</Code>
83+
</span>
7384
);
7485
}
7586

7687
export function parseMentionTags(content: string): ReactNode[] {
7788
const parts: ReactNode[] = [];
7889
let lastIndex = 0;
7990

91+
const slashMatch = content.match(SLASH_COMMAND_START);
92+
if (slashMatch) {
93+
parts.push(
94+
<MentionChip key="slash-cmd" icon={null} label={`/${slashMatch[1]}`} />,
95+
);
96+
lastIndex = slashMatch[0].length;
97+
}
98+
8099
for (const match of content.matchAll(MENTION_TAG_REGEX)) {
81100
const matchIndex = match.index ?? 0;
101+
if (matchIndex < lastIndex) continue;
82102

83103
if (matchIndex > lastIndex) {
84104
parts.push(

0 commit comments

Comments
 (0)