1
0
silverbullet/plugs/emoji/emoji.ts

24 lines
615 B
TypeScript
Raw Normal View History

import emojis from "./emoji.json" assert { type: "json" };
2022-10-14 13:11:33 +00:00
import { editor } from "$sb/silverbullet-syscall/mod.ts";
2022-04-01 13:02:35 +00:00
export async function emojiCompleter() {
2022-10-14 13:11:33 +00:00
const prefix = await editor.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",
})),
};
}