Skip to content

Commit fb0a4d5

Browse files
wesbillmanBrain
andauthored
fix(desktop): close mention popup after an exact name + trailing space (#2030)
Signed-off-by: Wes <[email protected]> Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co>
1 parent fd2eaac commit fb0a4d5

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎desktop/src/shared/lib/detectPrefixQuery.test.mjs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,30 @@ test("multi-word: glued-to-word prefix still rejected", () => {
9696
assert.equal(at("#", "x#buzz de", CHANNELS), null);
9797
});
9898

99+
// ── Completed mention: exact name + trailing space closes the query ───────────
100+
101+
test("exact name followed by space does not stay open for a longer name", () => {
102+
// "pinky" is complete; "pinky and the brain" sharing the prefix must not
103+
// keep the popup open and steal Enter/Tab.
104+
const names = ["pinky", "brain", "pinky and the brain"];
105+
assert.equal(at("@", "@pinky ", names), null);
106+
});
107+
108+
test("typing past the space toward the longer name re-opens the query", () => {
109+
const names = ["pinky", "brain", "pinky and the brain"];
110+
assert.deepEqual(at("@", "@pinky a", names), {
111+
query: "pinky a",
112+
startIndex: 0,
113+
});
114+
});
115+
116+
test("multi-word name still completes word by word when no shorter exact match", () => {
117+
assert.deepEqual(at("@", "@bob ", PEOPLE), {
118+
query: "bob ",
119+
startIndex: 0,
120+
});
121+
});
122+
99123
// ── Empty / no-match guards unchanged ─────────────────────────────────────────
100124

101125
test("bare prefix after ( yields empty single-word query, not multi-word", () => {

‎desktop/src/shared/lib/detectPrefixQuery.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ export function detectPrefixQuery(
5454
break;
5555
}
5656
const lowerCandidate = candidate.toLowerCase();
57+
// A trailing space after an exact known name means the mention is
58+
// complete — don't keep the query open just because a longer name
59+
// (e.g. a team) shares the prefix.
60+
if (
61+
lowerCandidate.endsWith(" ") &&
62+
knownNamesLower.includes(lowerCandidate.trimEnd())
63+
) {
64+
break;
65+
}
5766
const isPrefix = knownNamesLower.some((name) =>
5867
name.startsWith(lowerCandidate),
5968
);

0 commit comments

Comments
 (0)