Skip to content

Commit d81b8fd

Browse files
dlettIggyclaude
committed
fix(messages): keep the edited marker on a closing list or quote line
Address review on #2020: - A body ending in a list item or blockquote now keeps "(edited)" on that last line, as Slack does, rather than on its own line below. - A plugin card's marker sits inside its bubble, above the reactions, rather than after them. - Cover table-only, emoji-only, list, quote, plugin-card and expanded agent rows, and check in a real engine that a copied caption leaves the marker out. - Keep the edited rules together in Messages.module.css. Co-authored-by: Iggy <42e0a2efa374023f3b716c1a8ee341e1063b06afdd3840d29cdcbc145c5f822b@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Daniel Lett <[email protected]>
1 parent 9227a10 commit d81b8fd

5 files changed

Lines changed: 115 additions & 24 deletions

File tree

‎src/features/messages/MessageMarkdown.tsx‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,26 @@ type HtmlNode = {
309309
properties?: Record<string, unknown>;
310310
children?: HtmlNode[];
311311
};
312+
/** Lists and quotes the slot descends into, so their last line keeps it. */
313+
const editedSlotContainers = new Set(["ul", "ol", "li", "blockquote"]);
312314
/** Leave a slot after the body's last rendered line for the edited marker:
313-
* inside a closing paragraph, else after the last block, including generated
314-
* footnotes. Parses are cached by content alone, so every body has the slot
315-
* and rendering decides whether to fill it. */
315+
* inside a closing paragraph, list item or quote line, else after the last
316+
* block, including generated footnotes. Parses are cached by content alone, so
317+
* every body has the slot and rendering decides whether to fill it. */
316318
function rehypeEditedSlot() {
317319
return (tree: HtmlNode) => {
318-
const last = tree.children
319-
?.filter((child) => child.type === "element")
320-
.at(-1);
321-
const parent = last?.tagName === "p" ? last : tree;
320+
let parent = tree;
321+
for (;;) {
322+
const last = parent.children
323+
?.filter((child) => child.type === "element")
324+
.at(-1);
325+
if (last?.tagName === "p") parent = last;
326+
else if (last && editedSlotContainers.has(last.tagName ?? "")) {
327+
parent = last;
328+
continue;
329+
}
330+
break;
331+
}
322332
parent.children = [
323333
...(parent.children ?? []),
324334
{
@@ -489,7 +499,7 @@ export function MessageMarkdown({
489499
participantProfiles?: ReadonlyMap<string, Profile> | undefined;
490500
largeEmoji?: boolean | undefined;
491501
interactive?: boolean;
492-
/** Mark the body as replaced by its author's edit, after its last line. */
502+
/** Mark the body as replaced by an edit, after its last line. */
493503
edited?: boolean | undefined;
494504
}) {
495505
const resolveName = useChannelIdentityNames(session, row.channelId);

‎src/features/messages/MessageRow.test.tsx‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3858,6 +3858,32 @@ it("marks an edited body after its last line, and leaves an unedited one unmarke
38583858
expect(screen.getByText("(edited)").parentElement?.tagName).toBe("P");
38593859
cleanup();
38603860

3861+
render("- one\n- two", true);
3862+
const item = screen.getByText("(edited)").parentElement;
3863+
expect(item?.tagName).toBe("LI");
3864+
expect(item).toHaveTextContent("two (edited)");
3865+
cleanup();
3866+
3867+
render("> quoted line", true);
3868+
const quoted = screen.getByText("(edited)").parentElement;
3869+
expect(quoted?.tagName).toBe("P");
3870+
expect(quoted?.parentElement?.tagName).toBe("BLOCKQUOTE");
3871+
cleanup();
3872+
3873+
// The unboxed table styling selects `table:first-child + .edited:last-child`.
3874+
render("| Day | Room |\n| --- | --- |\n| Thu | 4B |", true);
3875+
const afterTable = screen.getByText("(edited)");
3876+
expect(afterTable.previousElementSibling?.tagName).toBe("TABLE");
3877+
expect(afterTable.parentElement?.firstElementChild?.tagName).toBe("TABLE");
3878+
expect(afterTable.nextElementSibling).toBeNull();
3879+
cleanup();
3880+
3881+
render("🎉", true);
3882+
expect(screen.getByText("(edited)").parentElement).toHaveAttribute(
3883+
"data-single-emoji",
3884+
);
3885+
cleanup();
3886+
38613887
renderDom(
38623888
<MessageRow
38633889
row={{
@@ -3912,6 +3938,42 @@ it("marks an edited body after its last line, and leaves an unedited one unmarke
39123938
name: "Morgarita: Done (edited)",
39133939
});
39143940
expect(within(line).getByText("(edited)")).toBeInTheDocument();
3941+
fireEvent.click(line);
3942+
expect(screen.getAllByText("(edited)")).toHaveLength(1);
3943+
expect(line).not.toContainElement(screen.getByText("(edited)"));
3944+
cleanup();
3945+
3946+
const none: never[] = [];
3947+
const cards = [
3948+
{
3949+
id: "card",
3950+
title: "Card",
3951+
key: "fixture.card:card",
3952+
pluginId: "fixture.card",
3953+
revision: "one",
3954+
matches: () => true,
3955+
component: () => <p>Plugin card</p>,
3956+
},
3957+
];
3958+
renderDom(
3959+
<MessageRow
3960+
row={{ ...row, content: "Card body", edited: true }}
3961+
profile={undefined}
3962+
media={() => undefined}
3963+
onOpenLink={() => false}
3964+
day={false}
3965+
retry={undefined}
3966+
extensions={{
3967+
tools: { snapshot: () => none, subscribe: () => () => {} },
3968+
inline: { snapshot: () => none, subscribe: () => () => {} },
3969+
messages: { snapshot: () => cards, subscribe: () => () => {} },
3970+
}}
3971+
/>,
3972+
);
3973+
// Inside the card's bubble, so above any reactions it holds.
3974+
expect(screen.getByText("(edited)").parentElement).toBe(
3975+
screen.getByText("Plugin card").closest("[data-message-action-anchor]"),
3976+
);
39153977
cleanup();
39163978

39173979
render("Hi how are ya.", false);

‎src/features/messages/MessageRow.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,9 @@ function MessageRowContent({
450450
bodyShown && messageRenderer !== failedRenderer
451451
? messageRenderer?.ownsAttachment
452452
: undefined;
453-
// The host's Markdown marks an edit after the caption's last line. Diffs,
454-
// plugin cards and captionless rows are marked after the payload instead.
453+
// The host's Markdown marks an edit after the caption's last line. Plugin
454+
// cards are marked inside their bubble; diffs and captionless rows after the
455+
// payload.
455456
const editedInBody =
456457
bodyShown &&
457458
!row.diff &&
@@ -823,6 +824,8 @@ function MessageRowContent({
823824
!shownRow &&
824825
!emojiOnly &&
825826
!row.diff;
827+
// A plugin card keeps reactions in its bubble, so its mark goes above them.
828+
const editedInBubble = !editedInBody && reactionsInBubble;
826829
const reactionContent =
827830
session && scope && extensions ? (
828831
<MessageReactions
@@ -1078,6 +1081,7 @@ function MessageRowContent({
10781081
) : (
10791082
body
10801083
)}
1084+
{editedInBubble && shown.edited && <EditedMarker />}
10811085
{reactionsInBubble && reactionContent}
10821086
</div>
10831087
)}
@@ -1273,7 +1277,9 @@ function MessageRowContent({
12731277
})}
12741278
</div>
12751279
)}
1276-
{!editedInBody && shown.edited && <EditedMarker />}
1280+
{!editedInBody && !editedInBubble && shown.edited && (
1281+
<EditedMarker />
1282+
)}
12771283
</MessageTimestampHint>
12781284
</div>
12791285
{!reactionsInBubble && reactionContent}

‎src/features/messages/Messages.module.css‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,15 +1765,17 @@ html[data-keyboard-navigation] .text pre code:focus-visible {
17651765
font-style: italic;
17661766
}
17671767

1768-
/* Metadata after the body's last line; on its own line after a closing block,
1769-
or after cards and attachments when no body is drawn. A large-emoji
1768+
/* Metadata after the body's last line; on its own line after a closing block
1769+
or plugin card, or after attachments when no body is drawn. A large-emoji
17701770
paragraph is itself `.text` and keeps its marker inline. */
17711771
.edited {
17721772
color: var(--message-metadata, var(--text-metadata));
17731773
font-size: var(--text-caption);
17741774
letter-spacing: var(--text-caption--letter-spacing);
17751775
}
1776-
.messagePayload > .edited {
1776+
/* A plugin card's marker sits in its bubble, above the reactions. */
1777+
.messagePayload > .edited,
1778+
.messageBubble > .edited {
17771779
display: block;
17781780
margin-top: var(--space-1);
17791781
}
@@ -1787,6 +1789,13 @@ html[data-keyboard-navigation] .text pre code:focus-visible {
17871789
.text:not(p) > :has(+ .edited:last-child) {
17881790
margin-bottom: var(--space-1);
17891791
}
1792+
.message[data-viewer-message] .messagePayload > .edited {
1793+
text-align: end;
1794+
}
1795+
/* The edit marker follows a short preview and stays visible beside a long one. */
1796+
.audiencePreview:has(+ .edited) {
1797+
flex: 0 1 auto;
1798+
}
17901799

17911800
.mention {
17921801
display: inline;
@@ -3434,13 +3443,6 @@ html[data-keyboard-navigation] .audienceLine:focus-visible {
34343443
text-overflow: ellipsis;
34353444
white-space: nowrap;
34363445
}
3437-
/* The edit marker follows a short preview and stays visible beside a long one. */
3438-
.audiencePreview:has(+ .edited) {
3439-
flex: 0 1 auto;
3440-
}
3441-
.message[data-viewer-message] .messagePayload > .edited {
3442-
text-align: end;
3443-
}
34443446

34453447
/* Retain the expanded columns during exit, so wrapping and the preview do
34463448
not replace the closing details before their space has folded away. */

‎tests/browser/message-edit.spec.mjs‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,20 @@ test("Up and Cmd+Up edit in the existing composer and restore native focus, draf
108108
await expect(input).toBeFocused();
109109
await expect(input).toHaveJSProperty("value", "");
110110
// The applied edit replaces the caption and marks it as edited.
111-
await expect(
112-
page.getByText("Revised caption reject (edited)", { exact: true }),
113-
).toBeVisible();
111+
const revised = page.getByText("Revised caption reject (edited)", {
112+
exact: true,
113+
});
114+
await expect(revised).toBeVisible();
115+
// The marker is metadata, so a selection of the caption leaves it out.
116+
expect(
117+
await revised.evaluate((caption) => {
118+
const selection = getSelection();
119+
selection?.selectAllChildren(caption);
120+
const text = selection?.toString() ?? "";
121+
selection?.removeAllRanges();
122+
return text.trim();
123+
}),
124+
).toBe("Revised caption reject");
114125
await expect(
115126
page.getByRole("link", { name: "Download report.txt", exact: true }),
116127
).toBeVisible();

0 commit comments

Comments
 (0)