diff --git a/src/app/(protected)/workorders/_components/view/work-order-activity-panel.tsx b/src/app/(protected)/workorders/_components/view/work-order-activity-panel.tsx index 61d3d060..ca276156 100644 --- a/src/app/(protected)/workorders/_components/view/work-order-activity-panel.tsx +++ b/src/app/(protected)/workorders/_components/view/work-order-activity-panel.tsx @@ -75,9 +75,14 @@ export function WorkOrderActivityPanel({ if (!trimmed) { return; } - void Promise.resolve(onSubmitComment(trimmed)).then(() => { - setCommentText(""); - }); + void (async () => { + try { + await onSubmitComment(trimmed); + setCommentText(""); + } catch { + // Mutation toast handles failure; keep the draft for retry. + } + })(); }} className="mt-4 flex flex-col gap-2" > diff --git a/src/domain/work-orders/utils/comment-mentions.ts b/src/domain/work-orders/utils/comment-mentions.ts index 21302f1a..b3542bcd 100644 --- a/src/domain/work-orders/utils/comment-mentions.ts +++ b/src/domain/work-orders/utils/comment-mentions.ts @@ -80,7 +80,8 @@ function appendPlainMentionMatches( const sortedNames = [...mentionNames].sort((a, b) => b.length - a.length); const namePattern = sortedNames.map((name) => escapeRegExp(name)).join("|"); - const mentionRegex = new RegExp(`@(${namePattern})`, "g"); + // Require a non-word boundary after the name so "@Ann" does not match inside "@Annual". + const mentionRegex = new RegExp(`@(${namePattern})(?![\\w])`, "g"); let cursor = 0; for (const match of plainText.matchAll(mentionRegex)) { diff --git a/src/test/domain/work-orders/utils/comment-mentions.test.ts b/src/test/domain/work-orders/utils/comment-mentions.test.ts index c1f9dd3d..95e03ebc 100644 --- a/src/test/domain/work-orders/utils/comment-mentions.test.ts +++ b/src/test/domain/work-orders/utils/comment-mentions.test.ts @@ -70,6 +70,17 @@ describe("comment-mentions", () => { ]); }); + it("does not highlight shorter mention names as prefixes of longer @words", () => { + const text = "Check @Annual maintenance with @Ann"; + + expect(buildCommentBodySegments(text, ["user-ann"], [{ id: "user-ann", name: "Ann" }])).toEqual( + [ + { type: "text", value: "Check @Annual maintenance with " }, + { type: "mention", userId: "Ann", label: "Ann" }, + ], + ); + }); + it("finds active mention query at cursor", () => { const text = "Hello @ja"; const query = findActiveMentionQuery(text, text.length);