1
0
silverbullet/plugs/emoji/emoji.ts

26 lines
611 B
TypeScript
Raw Normal View History

import emojis from "./emoji.json" assert { type: "json" };
2023-08-28 15:12:15 +00:00
import type { CompleteEvent } from "$sb/app_event.ts";
2022-04-01 13:02:35 +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;
}
const [fullMatch, emojiName] = match;
const filteredEmoji = emojis.filter(([_, shortcode]) =>
shortcode.includes(emojiName)
2022-04-01 13:02:35 +00:00
);
return {
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",
})),
};
}