mirror of
https://github.com/revoltchat/revite.git
synced 2025-02-20 15:23:00 -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 =
|
export type AutoCompleteState =
|
||||||
| { type: "none" }
|
| { type: "none" }
|
||||||
| ({ selected: number; within: boolean } & (
|
| ({ selected: number; within: boolean } & (
|
||||||
| {
|
| {
|
||||||
type: "emoji";
|
type: "emoji";
|
||||||
matches: string[];
|
matches: string[];
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: "user";
|
type: "user";
|
||||||
matches: User[];
|
matches: User[];
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
type: "channel";
|
type: "channel";
|
||||||
matches: Channel[];
|
matches: Channel[];
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
export type SearchClues = {
|
export type SearchClues = {
|
||||||
users?: { type: "channel"; id: string } | { type: "all" };
|
users?: { type: "channel"; id: string } | { type: "all" };
|
||||||
|
@ -79,13 +79,15 @@ export function useAutoComplete(
|
||||||
|
|
||||||
if (current === ":" || current === "@" || current === "#") {
|
if (current === ":" || current === "@" || current === "#") {
|
||||||
const search = content.slice(j + 1, content.length);
|
const search = content.slice(j + 1, content.length);
|
||||||
if (search.length > 0) {
|
const minLen = current === ":" ? 2 : 1
|
||||||
|
|
||||||
|
if (search.length >= minLen) {
|
||||||
return [
|
return [
|
||||||
current === "#"
|
current === "#"
|
||||||
? "channel"
|
? "channel"
|
||||||
: current === ":"
|
: current === ":"
|
||||||
? "emoji"
|
? "emoji"
|
||||||
: "user",
|
: "user",
|
||||||
search.toLowerCase(),
|
search.toLowerCase(),
|
||||||
j + 1,
|
j + 1,
|
||||||
];
|
];
|
||||||
|
@ -165,8 +167,8 @@ export function useAutoComplete(
|
||||||
const matches = (
|
const matches = (
|
||||||
search.length > 0
|
search.length > 0
|
||||||
? users.filter((user) =>
|
? users.filter((user) =>
|
||||||
user.username.toLowerCase().match(regex),
|
user.username.toLowerCase().match(regex),
|
||||||
)
|
)
|
||||||
: users
|
: users
|
||||||
)
|
)
|
||||||
.splice(0, 5)
|
.splice(0, 5)
|
||||||
|
@ -197,8 +199,8 @@ export function useAutoComplete(
|
||||||
const matches = (
|
const matches = (
|
||||||
search.length > 0
|
search.length > 0
|
||||||
? channels.filter((channel) =>
|
? channels.filter((channel) =>
|
||||||
channel.name!.toLowerCase().match(regex),
|
channel.name!.toLowerCase().match(regex),
|
||||||
)
|
)
|
||||||
: channels
|
: channels
|
||||||
)
|
)
|
||||||
.splice(0, 5)
|
.splice(0, 5)
|
||||||
|
@ -415,7 +417,7 @@ export default function AutoComplete({
|
||||||
<Emoji
|
<Emoji
|
||||||
emoji={
|
emoji={
|
||||||
(emojiDictionary as Record<string, string>)[
|
(emojiDictionary as Record<string, string>)[
|
||||||
match
|
match
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
size={20}
|
size={20}
|
||||||
|
|
Loading…
Add table
Reference in a new issue