Skip to content

Commit f48434e

Browse files
committed
Place the exact match on top of the autocomplete variants
1 parent 99a3d69 commit f48434e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/components/autocomplete/selector.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from './ranked-names';
2323

2424
export function Selector({ query, events, onSelect, context, localLinks = false }) {
25+
query = query.toLowerCase();
2526
const dispatch = useDispatch();
2627
const [usernames, accountsMap, compare] = useAccountsMap({ context });
2728

@@ -37,7 +38,16 @@ export function Selector({ query, events, onSelect, context, localLinks = false
3738
}, [dispatch, query]);
3839

3940
const matches = useMemo(() => {
40-
const finder = new Finder(query, 5, compare);
41+
const compareWithExact = (a, b) => {
42+
if (a.text === query) {
43+
return -1;
44+
}
45+
if (b.text === query) {
46+
return 1;
47+
}
48+
return compare(a, b);
49+
};
50+
const finder = new Finder(query, 5, compareWithExact);
4151
for (const username of usernames) {
4252
finder.add(username);
4353
}

0 commit comments

Comments
 (0)