mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
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:
@@ -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),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user