1
0
silverbullet/plugs/emoji/emoji.ts

26 lines
622 B
TypeScript
Raw Normal View History

import emojis from "./emoji.json" assert { type: "json" };
import type { CompleteEvent } from "../../plug-api/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",
})),
};
}