fix(desktop): close mention popup after an exact name + trailing space (#2030)

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
Wes
2026-07-17 09:22:40 -07:00
committed by GitHub
co-authored by Brain
parent fd2eaac73b
commit fb0a4d5e74
2 changed files with 33 additions and 0 deletions
@@ -96,6 +96,30 @@ test("multi-word: glued-to-word prefix still rejected", () => {
assert.equal(at("#", "x#buzz de", CHANNELS), null);
});
// ── Completed mention: exact name + trailing space closes the query ───────────
test("exact name followed by space does not stay open for a longer name", () => {
// "pinky" is complete; "pinky and the brain" sharing the prefix must not
// keep the popup open and steal Enter/Tab.
const names = ["pinky", "brain", "pinky and the brain"];
assert.equal(at("@", "@pinky ", names), null);
});
test("typing past the space toward the longer name re-opens the query", () => {
const names = ["pinky", "brain", "pinky and the brain"];
assert.deepEqual(at("@", "@pinky a", names), {
query: "pinky a",
startIndex: 0,
});
});
test("multi-word name still completes word by word when no shorter exact match", () => {
assert.deepEqual(at("@", "@bob ", PEOPLE), {
query: "bob ",
startIndex: 0,
});
});
// ── Empty / no-match guards unchanged ─────────────────────────────────────────
test("bare prefix after ( yields empty single-word query, not multi-word", () => {
@@ -54,6 +54,15 @@ export function detectPrefixQuery(
break;
}
const lowerCandidate = candidate.toLowerCase();
// A trailing space after an exact known name means the mention is
// complete — don't keep the query open just because a longer name
// (e.g. a team) shares the prefix.
if (
lowerCandidate.endsWith(" ") &&
knownNamesLower.includes(lowerCandidate.trimEnd())
) {
break;
}
const isPrefix = knownNamesLower.some((name) =>
name.startsWith(lowerCandidate),
);