mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-10 01:03:36 -05:00
feat: require at least two characters to autocomplete emoji (#298)
This commit is contained in:
parent
3ef3f84877
commit
1800aace43
1 changed files with 23 additions and 21 deletions
|
@ -14,19 +14,19 @@ import UserIcon from "./user/UserIcon";
|
|||
export type AutoCompleteState =
|
||||
| { type: "none" }
|
||||
| ({ selected: number; within: boolean } & (
|
||||
| {
|
||||
type: "emoji";
|
||||
matches: string[];
|
||||
}
|
||||
| {
|
||||
type: "user";
|
||||
matches: User[];
|
||||
}
|
||||
| {
|
||||
type: "channel";
|
||||
matches: Channel[];
|
||||
}
|
||||
));
|
||||
| {
|
||||
type: "emoji";
|
||||
matches: string[];
|
||||
}
|
||||
| {
|
||||
type: "user";
|
||||
matches: User[];
|
||||
}
|
||||
| {
|
||||
type: "channel";
|
||||
matches: Channel[];
|
||||
}
|
||||
));
|
||||
|
||||
export type SearchClues = {
|
||||
users?: { type: "channel"; id: string } | { type: "all" };
|
||||
|
@ -79,13 +79,15 @@ export function useAutoComplete(
|
|||
|
||||
if (current === ":" || current === "@" || current === "#") {
|
||||
const search = content.slice(j + 1, content.length);
|
||||
if (search.length > 0) {
|
||||
const minLen = current === ":" ? 2 : 1
|
||||
|
||||
if (search.length >= minLen) {
|
||||
return [
|
||||
current === "#"
|
||||
? "channel"
|
||||
: current === ":"
|
||||
? "emoji"
|
||||
: "user",
|
||||
? "emoji"
|
||||
: "user",
|
||||
search.toLowerCase(),
|
||||
j + 1,
|
||||
];
|
||||
|
@ -165,8 +167,8 @@ export function useAutoComplete(
|
|||
const matches = (
|
||||
search.length > 0
|
||||
? users.filter((user) =>
|
||||
user.username.toLowerCase().match(regex),
|
||||
)
|
||||
user.username.toLowerCase().match(regex),
|
||||
)
|
||||
: users
|
||||
)
|
||||
.splice(0, 5)
|
||||
|
@ -197,8 +199,8 @@ export function useAutoComplete(
|
|||
const matches = (
|
||||
search.length > 0
|
||||
? channels.filter((channel) =>
|
||||
channel.name!.toLowerCase().match(regex),
|
||||
)
|
||||
channel.name!.toLowerCase().match(regex),
|
||||
)
|
||||
: channels
|
||||
)
|
||||
.splice(0, 5)
|
||||
|
@ -415,7 +417,7 @@ export default function AutoComplete({
|
|||
<Emoji
|
||||
emoji={
|
||||
(emojiDictionary as Record<string, string>)[
|
||||
match
|
||||
match
|
||||
]
|
||||
}
|
||||
size={20}
|
||||
|
|
Loading…
Reference in a new issue