Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ Sources: [translation endpoint](app/Http/Controllers/CommitTranslationController

Commit and reply text supports inline code in backticks and fenced code blocks with syntax highlighting, a **Wrap lines** toggle, and a copy control. A title after the language, as in ```` ```php title="app/Models/User.php" ````, labels the block in place of the language. Text outside code supports emoji shortcodes, clickable URLs, `@username` mentions, and `#hashtags`, which open commit search for signed-in members and stay plain text for guests. This is developer-oriented text formatting, not a full rich-text editor.

In commits, replies, quotes, poll options and remotes, `/shrug` and `/tableflip` typed at the start of the text or after a space become `¯\_(ツ)_/¯` and `(╯°□°)╯︵ ┻━┻` once a space or a new line follows. Typing `/` suggests them; in a fresh commit draft they are listed after `/bug` and `/feature`. Code keeps them as typed, and so does a field whose length limit has no room left for the face; it is expanded as soon as there is. They are expanded in the browser: text sent through the API stays as written.

The smiley button in the commit, reply and quote composers opens the same searchable emoji picker as reactions in remotes. Picking an emoji inserts it where the caret was, or over the selected text, and puts the caret right after it.

In commits, replies, and remotes, start a line with `>` to render a quote block. Consecutive quoted lines stay together; an unquoted line ends the block. Quotes keep inline code, links, mentions, and emoji formatting. A `>` inside code or in the middle of a line stays literal.
Expand All @@ -273,7 +275,7 @@ Typing **#123** in a composer looks up that exact issue or pull request in the /

Write `color(#ff8a4c)` or `color(#fff)` outside code to show the hex value with a small color swatch. The `color(...)` markup stays in the draft and is hidden in the rendered commit. It accepts 3, 4, 6 or 8 hex digits. A bare `#` followed by a letter is a hashtag. On the web, if the text of a commit, reply, quote, or Remotes message contains a hashtag that could be a color, the composer shows the swatch syntax and offers to apply it. Colors that start with a digit can still show a swatch without the markup: `#000`, `#000000` and `#333333` are colors, while `#123` and `#333` stay plain text. The full-width `#` also works for automatic swatches, as in `#fff`. A swatch written with `color(...)` does not add the commit to a guild.

Sources: [body renderer](resources/js/components/commit-body.tsx), [emoji picker button](resources/js/components/emoji-picker.tsx), [colors](resources/js/lib/colors.ts), [code blocks](resources/js/components/code-block.tsx), [mention suggestions](app/Http/Controllers/MentionSuggestionController.php), [mention parsing](app/Services/Mentions.php).
Sources: [body renderer](resources/js/components/commit-body.tsx), [emoji picker button](resources/js/components/emoji-picker.tsx), [colors](resources/js/lib/colors.ts), [text expansions](resources/js/lib/text-expansions.ts), [code blocks](resources/js/components/code-block.tsx), [mention suggestions](app/Http/Controllers/MentionSuggestionController.php), [mention parsing](app/Services/Mentions.php).

### Draft previews

Expand Down
5 changes: 3 additions & 2 deletions resources/js/components/commit-composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ function CommitComposerBody({
rows={1}
value={body}
onValueChange={issue.change}
suggestsExpansions={!issue.ownsExpansions}
onPaste={
poll === null ? attachments.onPaste : undefined
}
Expand Down Expand Up @@ -390,8 +391,8 @@ function CommitComposerBody({
<IssueCommandSuggestions
suggestions={issue.suggestions}
selected={issue.selected}
onPick={(kind) => {
issue.start(kind, '');
onPick={(command) => {
issue.pick(command);
focusBody(id);
}}
/>
Expand Down
41 changes: 30 additions & 11 deletions resources/js/components/issue-command.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useHttp, usePage } from '@inertiajs/react';
import { Bug, Lightbulb, X } from 'lucide-react';
import { Bug, Lightbulb, Smile, X } from 'lucide-react';
import type { KeyboardEvent } from 'react';
import { useState } from 'react';
import { toast } from 'sonner';
Expand All @@ -16,8 +16,12 @@ import {
typedCommand,
} from '@/lib/issue-commands';
import { hasModKey } from '@/lib/keyboard';
import type { TextExpansion } from '@/lib/text-expansions';
import { suggestedExpansions } from '@/lib/text-expansions';
import { cn } from '@/lib/utils';

export type ComposerCommand = IssueCommand | TextExpansion;

const hintDismissedKey = 'issue-command-hint-dismissed';

function isHintDismissed(): boolean {
Expand Down Expand Up @@ -57,10 +61,13 @@ export function useIssueCommand({
>({ command: '', body: '' });
const command =
issueCommands.find((candidate) => candidate.kind === kind) ?? null;
// While the draft is a lone command, this menu lists the text expansions too, so the field doesn't open its own.
const ownsExpansions =
enabled && kind === null && suggestedExpansions(body).length > 0;
// A draft restored from the stash can be a lone slash: the menu only opens while the user is typing in it.
const suggestions =
const suggestions: ComposerCommand[] =
enabled && kind === null && !dismissed && focused
? suggestedCommands(body)
? [...suggestedCommands(body), ...suggestedExpansions(body)]
: [];
const hint =
enabled && kind === null && !hintDismissed ? hintedCommand(body) : null;
Expand All @@ -71,6 +78,14 @@ export function useIssueCommand({
updateBody(rest);
};

const pick = (picked: ComposerCommand) => {
if ('kind' in picked) {
start(picked.kind, '');
} else {
updateBody(`${picked.text} `);
}
};

const change = (value: string) => {
setDismissed(false);
const typed = enabled && kind === null ? typedCommand(value) : null;
Expand Down Expand Up @@ -164,7 +179,7 @@ export function useIssueCommand({
!hasModKey(event)
) {
event.preventDefault();
start(suggestions[selected % suggestions.length].kind, '');
pick(suggestions[selected % suggestions.length]);
return true;
}

Expand Down Expand Up @@ -202,6 +217,7 @@ export function useIssueCommand({
return {
command,
suggestions,
ownsExpansions,
hint,
dismissHint: () => {
setHintDismissed(true);
Expand All @@ -217,6 +233,7 @@ export function useIssueCommand({
focus: () => setFocused(true),
blur: () => setFocused(false),
start,
pick,
exit: () => setKind(null),
submit,
handleKeyDown,
Expand Down Expand Up @@ -264,9 +281,9 @@ export function IssueCommandSuggestions({
selected,
onPick,
}: {
suggestions: IssueCommand[];
suggestions: ComposerCommand[];
selected: number;
onPick: (kind: IssueKind) => void;
onPick: (command: ComposerCommand) => void;
}) {
return (
<div
Expand All @@ -276,17 +293,17 @@ export function IssueCommandSuggestions({
className="mt-1 w-full max-w-sm rounded-md border bg-popover p-1 text-popover-foreground shadow-md"
>
{suggestions.map((command, index) => {
const Icon = icons[command.kind];
const Icon = 'kind' in command ? icons[command.kind] : Smile;

return (
<button
key={command.kind}
key={command.name}
type="button"
role="option"
aria-selected={selected === index}
tabIndex={-1}
onMouseDown={(event) => event.preventDefault()}
onClick={() => onPick(command.kind)}
onClick={() => onPick(command)}
className={cn(
'flex w-full items-center gap-3 rounded-sm px-2 py-1.5 text-left text-sm',
selected === index && 'bg-accent',
Expand All @@ -296,11 +313,13 @@ export function IssueCommandSuggestions({
className="size-4 shrink-0 text-muted-foreground"
aria-hidden="true"
/>
<span className="w-20 shrink-0 font-mono">
<span className="w-24 shrink-0 font-mono">
{command.name}
</span>
<span className="min-w-0 truncate text-muted-foreground">
{command.description}
{'kind' in command
? command.description
: command.text}
</span>
</button>
);
Expand Down
107 changes: 94 additions & 13 deletions resources/js/components/mention-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ import type { EmojiSuggestion } from '@/lib/emoji';
import { emojifyInput, searchEmoji } from '@/lib/emoji';
import { issueReferenceBeforeCaret } from '@/lib/issue-reference';
import { suggestionPosition } from '@/lib/suggestion-position';
import {
expandTextCommands,
expansionCommandBeforeCaret,
expansionsStartingWith,
} from '@/lib/text-expansions';
import { toastWhenThrottled } from '@/lib/throttle';
import { characterCount, cn, laneColor, limitCharacters } from '@/lib/utils';
import type { Organization, OrgMember, User } from '@/types';

type Trigger = {
kind: 'mention' | 'emoji' | 'issue' | 'guild';
kind: 'mention' | 'emoji' | 'expansion' | 'issue' | 'guild';
start: number;
query: string;
};
Expand Down Expand Up @@ -86,6 +91,7 @@ function triggerAt(
suggestsMentions: boolean,
suggestsIssues: boolean,
suggestsGuilds: boolean,
suggestsExpansions: boolean,
): Trigger | null {
if (textarea.selectionStart !== textarea.selectionEnd) {
return null;
Expand Down Expand Up @@ -117,6 +123,14 @@ function triggerAt(
};
}

const expansion = suggestsExpansions
? expansionCommandBeforeCaret(before)
: null;

if (expansion) {
return { kind: 'expansion', ...expansion };
}

if (isTypingExplicitColor(before)) {
return null;
}
Expand Down Expand Up @@ -263,8 +277,8 @@ function Highlighted({ text, query }: { text: string; query: string }) {

/**
* A textarea that suggests developers to mention as soon as "@" is typed, right under the "@", unless it doesn't
* suggest mentions, suggests emoji for the ":shortcode" being typed, and turns emoji shortcodes into emoji as they
* are typed. Within an org, it only suggests the org's members.
* suggest mentions, suggests emoji for the ":shortcode" being typed and text expansions for the "/command" being typed, and
* turns both into what they stand for as they are typed. Within an org, it only suggests the org's members.
*/
export function MentionTextarea({
ref,
Expand All @@ -276,6 +290,7 @@ export function MentionTextarea({
maxLength,
suggestsMentions = true,
suggestsIssues = suggestsMentions,
suggestsExpansions = true,
org,
members,
reply,
Expand All @@ -287,6 +302,7 @@ export function MentionTextarea({
onValueChange: (value: string) => void;
suggestsMentions?: boolean;
suggestsIssues?: boolean;
suggestsExpansions?: boolean;
org?: string;
members?: OrgMember[];
reply?: string;
Expand Down Expand Up @@ -336,6 +352,7 @@ export function MentionTextarea({
suggestsMentions,
suggestsIssues,
suggestsIssues && !!guilds?.length,
suggestsExpansions,
);

if (
Expand Down Expand Up @@ -508,6 +525,11 @@ export function MentionTextarea({
const emojiQuery =
trigger?.kind === 'emoji' ? trigger.query.toLowerCase() : '';
const emojis = emojiQuery === '' ? [] : searchEmoji(emojiQuery);
// The prop can turn off between a keystroke and the next render, so it is read here too, not only when tracking.
const expansions =
suggestsExpansions && trigger?.kind === 'expansion'
? expansionsStartingWith(`/${trigger.query}`)
: [];
const guildQuery =
trigger?.kind === 'guild' ? trigger.query.toLowerCase() : '';
const matchingGuilds =
Expand All @@ -534,7 +556,9 @@ export function MentionTextarea({
: 0
: trigger?.kind === 'emoji'
? emojis.length
: suggestions.length + organizations.length;
: trigger?.kind === 'expansion'
? expansions.length
: suggestions.length + organizations.length;
const selectedIndex = Math.min(activeIndex, Math.max(0, optionCount - 1));
const isOpen =
trigger !== null &&
Expand All @@ -545,8 +569,10 @@ export function MentionTextarea({
? issue !== null
: trigger.kind === 'emoji'
? emojis.length > 0
: suggestions.length + organizations.length > 0 ||
query !== '');
: trigger.kind === 'expansion'
? expansions.length > 0
: suggestions.length + organizations.length > 0 ||
query !== '');

const insert = (text: string, separator: string) => {
const textarea = textareaRef.current;
Expand All @@ -569,9 +595,12 @@ export function MentionTextarea({
const after = value.slice(caret);
const spacing = /^\s/u.test(after) ? '' : separator;
let next = `${value.slice(0, trigger.start)}${text}${spacing}${after}`;
// The caret skips the separator only when the text keeps one: added here, or already there.
let skipped = separator.length;

if (maxLength !== undefined && characterCount(next) > maxLength) {
next = `${value.slice(0, trigger.start)}${text}${after}`;
skipped = spacing === '' ? skipped : 0;
}

if (maxLength !== undefined && characterCount(next) > maxLength) {
Expand All @@ -583,7 +612,7 @@ export function MentionTextarea({
const nextCaret =
trigger.kind === 'issue'
? textarea.selectionStart + next.length - value.length
: trigger.start + text.length + separator.length;
: trigger.start + text.length + skipped;

onValueChange(next);
close();
Expand Down Expand Up @@ -633,6 +662,8 @@ export function MentionTextarea({
insert(`#${matchingGuilds[selectedIndex].handle}`, ' ');
} else if (trigger?.kind === 'emoji') {
selectEmoji(emojis[selectedIndex]);
} else if (trigger?.kind === 'expansion') {
insert(expansions[selectedIndex].text, ' ');
Comment thread
jubianchi marked this conversation as resolved.
Resolved
} else {
select(
selectedIndex < suggestions.length
Expand Down Expand Up @@ -670,10 +701,12 @@ export function MentionTextarea({
: trigger?.kind === 'emoji'
? emojis[selectedIndex] &&
`${id}-emoji-${emojis[selectedIndex].name}`
: selectedIndex < suggestions.length
? `${id}-mention-${suggestions[selectedIndex].id}`
: organizations[selectedIndex - suggestions.length] &&
`${id}-mention-${organizations[selectedIndex - suggestions.length].handle}`;
: trigger?.kind === 'expansion'
? `${id}-expansion-${expansions[selectedIndex].name.slice(1)}`
: selectedIndex < suggestions.length
? `${id}-mention-${suggestions[selectedIndex].id}`
: organizations[selectedIndex - suggestions.length] &&
`${id}-mention-${organizations[selectedIndex - suggestions.length].handle}`;

const isSearching = current?.key !== key;
const listId =
Expand All @@ -683,7 +716,9 @@ export function MentionTextarea({
? `${id}-issues`
: trigger?.kind === 'emoji'
? `${id}-emojis`
: `${id}-mentions`;
: trigger?.kind === 'expansion'
? `${id}-expansions`
: `${id}-mentions`;

return (
<>
Expand All @@ -693,10 +728,19 @@ export function MentionTextarea({
value={value}
onChange={(event) => {
const target = event.currentTarget;
const { text, caret } = emojifyInput(
const emojified = emojifyInput(
target.value,
target.selectionStart ?? target.value.length,
);
const expanded = expandTextCommands(
emojified.text,
emojified.caret,
);
const { text, caret } =
maxLength !== undefined &&
characterCount(expanded.text) > maxLength
? emojified
: expanded;

const limited =
maxLength === undefined
Expand Down Expand Up @@ -831,6 +875,43 @@ export function MentionTextarea({
</span>
</li>
</ul>
) : trigger?.kind === 'expansion' ? (
<ul
ref={listRef}
id={listId}
role="listbox"
aria-label="Insert a text"
className="min-h-0 overflow-y-auto overscroll-contain p-1.5"
>
{expansions.map((expansion, index) => (
<li
key={expansion.name}
id={`${id}-expansion-${expansion.name.slice(1)}`}
role="option"
aria-selected={index === selectedIndex}
onMouseMove={() =>
setActiveIndex(index)
}
onClick={() =>
insert(expansion.text, ' ')
}
className={cn(
'flex cursor-pointer items-center gap-3 rounded-sm px-2.5 py-1.5',
{
'bg-accent':
index === selectedIndex,
},
)}
>
<span className="w-24 shrink-0 font-mono text-[13px] text-muted-foreground">
{expansion.name}
</span>
<span className="max-w-64 min-w-0 truncate whitespace-nowrap">
{expansion.text}
</span>
</li>
))}
</ul>
) : trigger?.kind === 'emoji' ? (
<ul
ref={listRef}
Expand Down
Loading