1
0
silverbullet/plugs/emoji/emoji.ts

24 lines
616 B
TypeScript
Raw Normal View History

import emojis from "./emoji.json" assert { type: "json" };
import { matchBefore } from "$sb/silverbullet-syscall/editor.ts";
2022-04-01 13:02:35 +00:00
export async function emojiCompleter() {
const prefix = await matchBefore(":[\\w]+");
2022-04-01 13:02:35 +00:00
if (!prefix) {
return null;
}
const textPrefix = prefix.text.substring(1); // Cut off the initial :
const filteredEmoji = emojis.filter(([_, shortcode]) =>
2022-04-01 13:02:35 +00:00
shortcode.includes(textPrefix)
);
return {
from: prefix.from,
filter: false,
options: filteredEmoji.map(([emoji, shortcode]) => ({
detail: shortcode,
label: emoji,
type: "emoji",
})),
};
}