2022-10-10 12:50:21 +00:00
|
|
|
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 :
|
2022-10-10 12:50:21 +00:00
|
|
|
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",
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
}
|