2022-10-10 12:50:21 +00:00
|
|
|
import emojis from "./emoji.json" assert { type: "json" };
|
2022-12-21 13:55:24 +00:00
|
|
|
import type { CompleteEvent } from "../../plug-api/app_event.ts";
|
2022-04-01 13:02:35 +00:00
|
|
|
|
2022-12-21 13:55:24 +00:00
|
|
|
export function emojiCompleter({ linePrefix, pos }: CompleteEvent) {
|
|
|
|
const match = /:([\w]+)$/.exec(linePrefix);
|
|
|
|
if (!match) {
|
2022-04-01 13:02:35 +00:00
|
|
|
return null;
|
|
|
|
}
|
2022-12-21 13:55:24 +00:00
|
|
|
|
|
|
|
const [fullMatch, emojiName] = match;
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
const filteredEmoji = emojis.filter(([_, shortcode]) =>
|
2022-12-21 13:55:24 +00:00
|
|
|
shortcode.includes(emojiName)
|
2022-04-01 13:02:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
2022-12-21 13:55:24 +00:00
|
|
|
from: pos - fullMatch.length,
|
2022-04-01 13:02:35 +00:00
|
|
|
filter: false,
|
|
|
|
options: filteredEmoji.map(([emoji, shortcode]) => ({
|
|
|
|
detail: shortcode,
|
|
|
|
label: emoji,
|
|
|
|
type: "emoji",
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|